1 #ifndef __SOCKET_UDP_INCOMING_H__ 2 #define __SOCKET_UDP_INCOMING_H__ 14 inline bool OpenForInput(
unsigned short port);
17 inline bool GetPacket(
char *data,
int *max_len,
Socket_Address &address);
18 inline bool SendTo(
const char *data,
int len,
const Socket_Address &address);
19 inline bool InitNoAddress();
20 inline bool SetToBroadCast();
26 static void init_type() {
27 Socket_IP::init_type();
29 Socket_IP::get_class_type());
32 return get_class_type();
34 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
47 if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST, (
char *)&optval,
sizeof(optval)) != 0) {
62 _socket = DO_NEWUDP(AF_INET6);
65 _socket = DO_NEWUDP(AF_INET);
68 return (_socket != BAD_SOCKET);
82 _socket = DO_NEWUDP(AF_INET6);
86 _socket = DO_NEWUDP(AF_INET);
89 if (_socket == BAD_SOCKET) {
93 if (DO_BIND(_socket, &address.GetAddressInfo()) != 0) {
107 if (_socket == BAD_SOCKET) {
111 if (DO_BIND(_socket, &address.GetAddressInfo()) != 0) {
125 if (_socket == BAD_SOCKET) {
130 if (DO_BIND(_socket, &wa1.GetAddressInfo()) != 0) {
136 const sockaddr *addr = &address.GetAddressInfo();
137 if (addr->sa_family == AF_INET) {
138 struct ip_mreq imreq;
139 memset(&imreq, 0,
sizeof(imreq));
140 imreq.imr_multiaddr.s_addr = ((sockaddr_in*)addr)->sin_addr.s_addr;
141 imreq.imr_interface.s_addr = INADDR_ANY;
143 status = setsockopt(
GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP,
144 (
const char *)&imreq,
sizeof(imreq));
146 }
else if (addr->sa_family == AF_INET6) {
147 struct ipv6_mreq imreq;
148 memcpy(&imreq.ipv6mr_multiaddr,
149 &(((
struct sockaddr_in6 *)addr)->sin6_addr),
150 sizeof(
struct in6_addr));
151 imreq.ipv6mr_interface = 0;
153 status = setsockopt(
GetSocket(), IPPROTO_IPV6, IPV6_JOIN_GROUP,
154 (
const char *)&imreq,
sizeof(imreq));
157 return (status == 0);
167 int val = DO_RECV_FROM(_socket, data, *max_len, &address.GetAddressInfo());
186 return (DO_SOCKET_WRITE_TO(_socket, data, len, &address.GetAddressInfo()) == len);
189 #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 set_any_IP(unsigned short port)
Set to any address and a specified port.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool SetV6Only(bool flag)
Sets a flag indicating whether this IPv6 socket should operate in dual-stack mode or not.
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.
bool OpenForInput(unsigned short port)
Starts a UDP socket listening on a port.
bool set_any_IPv6(unsigned short port)
Set to any IPv6 address and a specified port.
sa_family_t get_family() const
Returns AF_INET if this is an IPv4 address, or AF_INET6 if this is an IPv6 address.
A simple place to store and manipulate 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.
SOCKET GetSocket()
Gets the base socket type.
bool InitNoAddress()
Set this socket to work without a bound external address.
bool SetToBroadCast()
Flips the OS bits that allow for brodcast packets to come in on this port.