1 #ifndef __SOCKET_UDP_INCOMING_H__ 2 #define __SOCKET_UDP_INCOMING_H__ 21 inline bool GetPacket(
char * data,
int *max_len,
Socket_Address & address);
22 inline bool SendTo(
const char * data,
int len,
const Socket_Address & address);
23 inline bool InitNoAddress();
24 inline bool SetToBroadCast();
30 static void init_type() {
31 Socket_IP::init_type();
32 register_type(_type_handle,
"Socket_UDP_Incoming",
33 Socket_IP::get_class_type());
36 return get_class_type();
38 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
56 if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST, (
char *)&optval,
sizeof(optval)) != 0)
69 _socket = DO_NEWUDP();
70 if (_socket == BAD_SOCKET)
86 _socket = DO_NEWUDP();
87 if (_socket == BAD_SOCKET)
90 if (DO_BIND(_socket, &address.GetAddressInfo()) != 0)
106 _socket = DO_NEWUDP();
107 if (_socket == BAD_SOCKET)
111 if (DO_BIND(_socket, &wa1.GetAddressInfo()) != 0)
114 struct ip_mreq imreq;
115 memset(&imreq,0,
sizeof(imreq));
116 imreq.imr_multiaddr.s_addr = address.GetAddressInfo().sin_addr.s_addr;
117 imreq.imr_interface.s_addr = INADDR_ANY;
119 int status = setsockopt(
GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP,
120 (
const char *)&imreq,
sizeof(
struct ip_mreq));
139 int val = DO_RECV_FROM(_socket, data, *max_len, &address.GetAddressInfo());
163 return (DO_SOCKET_WRITE_TO(_socket, data, len, &address.GetAddressInfo()) == len);
169 #endif //__SOCKET_UDP_INCOMING_H__ bool OpenForInputMCast(const Socket_Address &address)
Starts a UDP socket listening on a port.
Base functionality for a INET domain Socket this call should be the starting point for all other unix...
bool GetPacket(char *data, int *max_len, Socket_Address &address)
Grabs a dataset off the listening UDP socket and fills in the source address information.
bool SendTo(const char *data, int len, const Socket_Address &address)
Send data to specified address.
unsigned short get_port() const
Get the port portion as an integer.
Base functionality for a UDP Reader.
A simple place to store and munipulate tcp and port address for communication layer.
static int GetLastError()
gets the last errcode from a socket operation
void Close()
closes a socket if it is open (allocated)
TypeHandle is the identifier used to differentiate C++ class types.
bool OpenForInput(const Socket_Address &address)
Starts a UDP socket listening on a port.
SOCKET GetSocket()
Gets the base socket type.
bool InitNoAddress()
Set this socket to work with out a bound external address.
bool SetToBroadCast()
Flips the OS bits that allow for brodcast packets to com in on this port.