ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

udp.cpp
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3 // Copyright (C) 2015 Cherokees of Idaho.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27 //
28 // This exception applies only to the code released under the name GNU
29 // Common C++. If you copy code from other releases into a copy of GNU
30 // Common C++, as the General Public License permits, the exception does
31 // not apply to the code that you add in this way. To avoid misleading
32 // anyone as to the status of such modified files, you must delete
33 // this exception notice from them.
34 //
35 // If you write modifications of your own for GNU Common C++, it is your choice
36 // whether to permit this exception to apply to your modifications.
37 // If you do not wish that, delete this exception notice.
38 //
39 
40 #include <ucommon-config.h>
41 #include <commoncpp/config.h>
42 #include <commoncpp/export.h>
43 #include <commoncpp/string.h>
44 #include <commoncpp/socket.h>
45 #include <commoncpp/udp.h>
46 
47 #ifdef _MSWINDOWS_
48 #include <io.h>
49 #define _IOLEN64 (unsigned)
50 #define _IORET64 (int)
51 typedef int socklen_t;
52 
53 #define socket_errno WSAGetLastError()
54 #else
55 #include <sys/ioctl.h>
56 #include <netinet/tcp.h>
57 #ifdef HAVE_NET_IP6_H
58 #include <netinet/ip6.h>
59 #endif
60 #define socket_errno errno
61 # ifndef O_NONBLOCK
62 # define O_NONBLOCK O_NDELAY
63 # endif
64 # ifdef IPPROTO_IP
65 # ifndef SOL_IP
66 # define SOL_IP IPPROTO_IP
67 # endif // !SOL_IP
68 # endif // IPPROTO_IP
69 #endif // !WIN32
70 
71 #ifndef INADDR_LOOPBACK
72 #define INADDR_LOOPBACK (unsigned long)0x7f000001
73 #endif
74 
75 #ifdef HAVE_NETINET_IN_H
76 #include <netinet/in.h>
77 #endif
78 
79 #if defined(__hpux)
80 #define _XOPEN_SOURCE_EXTENDED
81 #endif
82 
83 #ifdef HAVE_NET_IF_H
84 #include <net/if.h>
85 #endif
86 
87 #ifndef _IOLEN64
88 #define _IOLEN64
89 #endif
90 
91 #ifndef _IORET64
92 #define _IORET64
93 #endif
94 
95 namespace ost {
96 
97 #ifdef HAVE_GETADDRINFO
98 
99 UDPSocket::UDPSocket(const char *name, Family fam) :
100 Socket(fam, SOCK_DGRAM, IPPROTO_UDP)
101 {
102  char namebuf[128], *cp;
103  struct addrinfo hint, *list = NULL, *first;
104 
105  family = fam;
106  peer.setAny(fam);
107 
108  snprintf(namebuf, sizeof(namebuf), "%s", name);
109  cp = strrchr(namebuf, '/');
110  if(!cp && family == IPV4)
111  cp = strrchr(namebuf, ':');
112 
113  if(!cp) {
114  cp = namebuf;
115  name = NULL;
116  }
117  else {
118  name = namebuf;
119  *(cp++) = 0;
120  if(!strcmp(name, "*"))
121  name = NULL;
122  }
123 
124  memset(&hint, 0, sizeof(hint));
125 
126  hint.ai_family = family;
127  hint.ai_socktype = SOCK_DGRAM;
128  hint.ai_protocol = IPPROTO_UDP;
129  hint.ai_flags = AI_PASSIVE;
130 
131  if(getaddrinfo(name, cp, &hint, &list) || !list) {
132  error(errBindingFailed, (char *)"Could not find service", errno);
133  endSocket();
134  return;
135  }
136 
137 #if defined(SO_REUSEADDR)
138  int opt = 1;
139  setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt,
140  (socklen_t)sizeof(opt));
141 #endif
142 
143  first = list;
144 
145  while(list) {
146  if(!bind(so, list->ai_addr, (socklen_t)list->ai_addrlen)) {
147  state = BOUND;
148  break;
149  }
150  list = list->ai_next;
151  }
152  freeaddrinfo(first);
153 
154  if(state != BOUND) {
155  endSocket();
156  error(errBindingFailed, (char *)"Count not bind socket", errno);
157  return;
158  }
159 }
160 
161 #else
162 
163 UDPSocket::UDPSocket(const char *name, Family fam) :
164 Socket(fam, SOCK_DGRAM, IPPROTO_UDP)
165 {
166  char namebuf[128], *cp;
167  family = fam;
168  peer.setAny(fam);
169 
170  snprintf(namebuf, sizeof(namebuf), "%s", name);
171  cp = strrchr(namebuf, '/');
172  if(!cp && family == IPV4)
173  cp = strrchr(namebuf, ':');
174 
175  if(!cp) {
176  cp = namebuf;
177  name = "*";
178  }
179  else {
180  name = namebuf;
181  *(cp++) = 0;
182  }
183 
184  Socket::address addr(namebuf, cp, SOCK_DGRAM);
185 
186 #if defined(SO_REUSEADDR)
187  int opt = 1;
188  setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt,
189  (socklen_t)sizeof(opt));
190 #endif
191 
192  if(addr.isValid() && !bind(so, addr, addr.getLength()))
193  state = BOUND;
194 
195  if(state != BOUND) {
196  endSocket();
197  error(errBindingFailed, (char *)"Count not bind socket", errno);
198  return;
199  }
200 }
201 
202 #endif
203 
204 UDPSocket::UDPSocket(Family fam) :
205 Socket(fam, SOCK_DGRAM, IPPROTO_UDP)
206 {
207  family = fam;
208  peer.setAny(fam);
209 }
210 
212 Socket(ia.family(), SOCK_DGRAM, IPPROTO_UDP)
213 {
214  family = ia.family() == AF_INET6 ? IPV6 : IPV4;
215  peer = ia;
216 #if defined(SO_REUSEADDR)
217  int opt = 1;
218  setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
219 #endif
220  if(bind(so, peer, (socklen_t)peer.getLength())) {
221  endSocket();
222  error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
223  return;
224  }
225  state = BOUND;
226 }
227 
228 UDPSocket::UDPSocket(const IPV4Address &ia, in_port_t port) :
229 Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP), peer(ia.getAddress(), port), family(IPV4)
230 {
231 #if defined(SO_REUSEADDR)
232  int opt = 1;
233  setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
234 #endif
235  if(bind(so, peer, sizeof(sockaddr_in))) {
236  endSocket();
237  error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
238  return;
239  }
240  state = BOUND;
241 }
242 
243 #ifdef CCXX_IPV6
244 UDPSocket::UDPSocket(const IPV6Address &ia, in_port_t port) :
245 Socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP), peer(ia.getAddress(), port), family(IPV6)
246 {
247 #if defined(SO_REUSEADDR)
248  int opt = 1;
249  setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
250 #endif
251  if(bind(so, peer, sizeof(sockaddr_in6))) {
252  endSocket();
253  error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
254  return;
255  }
256  state = BOUND;
257 }
258 #endif
259 
261 {
262  endSocket();
263 }
264 
265 ssize_t UDPSocket::send(const void *buf, size_t len)
266 {
267  const struct sockaddr *addr = peer;
268  socklen_t alen = (socklen_t)peer.getLength();
269  if(isConnected()) {
270  addr = NULL;
271  alen = 0;
272  }
273 
274  return _IORET64 ::sendto(so, (const char *)buf, _IOLEN64 len, MSG_NOSIGNAL, addr, alen);
275 }
276 
277 ssize_t UDPSocket::receive(void *buf, size_t len, bool reply)
278 {
279  struct sockaddr *addr = peer;
280  socklen_t alen = (socklen_t)peer.getLength();
281  struct sockaddr_in6 senderAddress; // DMC 2/7/05 ADD for use below.
282 
283  if(isConnected() || !reply) {
284  // DMC 2/7/05 MOD to use senderAddress instead of NULL, to prevent 10014 error
285  // from recvfrom.
286  //addr = NULL;
287  //alen = 0;
288  addr = (struct sockaddr*)(&senderAddress);
289  alen = sizeof(struct sockaddr_in6);
290  }
291 
292  int bytes = ::recvfrom(so, (char *)buf, _IOLEN64 len, 0, addr, &alen);
293 
294 #ifdef _MSWINDOWS_
295 
296  if (bytes == SOCKET_ERROR) {
297  WSAGetLastError();
298  }
299 #endif
300 
301  return _IORET64 bytes;
302 }
303 
304 Socket::Error UDPSocket::join(const IPV4Multicast &ia,int InterfaceIndex)
305 {
306  return join(Socket::address(getaddress(ia)), InterfaceIndex);
307 }
308 
309 
310 
312 {
313  return Socket::join(ia, InterfaceIndex);
314 }
315 
316 
317 Socket::Error UDPSocket::getInterfaceIndex(const char *DeviceName,int& InterfaceIndex)
318 {
319 #ifndef _MSWINDOWS_
320 #if defined(IP_ADD_MEMBERSHIP) && defined(SIOCGIFINDEX) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(_OSF_SOURCE) && !defined(__hpux) && !defined(__GNU__) && !defined(__NetBSD__)
321 
322  struct ip_mreqn mreqn;
323  struct ifreq m_ifreq;
324  int i;
325  sockaddr_in* in4 = (sockaddr_in*)peer.get(AF_INET);
326  InterfaceIndex = -1;
327 
328  memset(&mreqn, 0, sizeof(mreqn));
329  memcpy(&mreqn.imr_multiaddr.s_addr, &in4->sin_addr, sizeof(mreqn.imr_multiaddr.s_addr));
330 
331  for (i = 0; i < IFNAMSIZ && DeviceName[i]; ++i)
332  m_ifreq.ifr_name[i] = DeviceName[i];
333  for (; i < IFNAMSIZ; ++i)
334  m_ifreq.ifr_name[i] = 0;
335 
336  if (ioctl (so, SIOCGIFINDEX, &m_ifreq))
338 
339 #if defined(__FreeBSD__) || defined(__GNU__)
340  InterfaceIndex = m_ifreq.ifr_ifru.ifru_index;
341 #else
342  InterfaceIndex = m_ifreq.ifr_ifindex;
343 #endif
344  return errSuccess;
345 #else
347 #endif
348 #else
350 #endif // WIN32
351 }
352 
353 #ifdef AF_UNSPEC
355 {
356  struct sockaddr_in addr;
357  int len = sizeof(addr);
358 
359  if(so == INVALID_SOCKET)
360  return errSuccess;
361 
363 
364  memset(&addr, 0, len);
365 #ifndef _MSWINDOWS_
366  addr.sin_family = AF_UNSPEC;
367 #else
368  addr.sin_family = AF_INET;
369  memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
370 #endif
371  if(::connect(so, (sockaddr *)&addr, len))
372  return connectError();
373  return errSuccess;
374 }
375 #else
377 {
378  if(so == INVALID_SOCKET)
379  return errSuccess;
380 
382  return connect(getLocal());
383 }
384 #endif
385 
387 {
388  peer = host;
389 }
390 
392 {
393  peer = host;
394  if(so == INVALID_SOCKET)
395  return;
396 
397  if(!::connect(so, host.get(), (socklen_t)host.getLength()))
399 }
400 
401 void UDPSocket::setPeer(const IPV4Host &ia, in_port_t port)
402 {
404 }
405 
406 void UDPSocket::connect(const IPV4Host &ia, in_port_t port)
407 {
408  setPeer(ia, port);
409  if(so == INVALID_SOCKET)
410  return;
411 
412  if(!::connect(so, (struct sockaddr *)peer.get(AF_INET), sizeof(struct sockaddr_in)))
414 }
415 
416 #ifdef CCXX_IPV6
417 void UDPSocket::setPeer(const IPV6Host &ia, in_port_t port)
418 {
420 }
421 
422 void UDPSocket::connect(const IPV6Host &ia, in_port_t port)
423 {
424  setPeer(ia, port);
425 
426  if(so == INVALID_SOCKET)
427  return;
428 
429  if(!::connect(so, (struct sockaddr *)peer.get(AF_INET6), sizeof(struct sockaddr_in6)))
431 
432 }
433 
434 #endif
435 
436 void UDPSocket::setPeer(const char *name)
437 {
438  struct addrinfo *list = ucommon::Socket::query(name, NULL, SOCK_DGRAM, IPPROTO_UDP);
440  freeaddrinfo(list);
441 }
442 
443 void UDPSocket::connect(const char *service)
444 {
445  int rtn = -1;
446 
447  setPeer(service);
448 
449  if(so == INVALID_SOCKET)
450  return;
451 
452  rtn = ::connect(so, peer, (socklen_t)peer.getLength());
453  if(!rtn)
455 }
456 
458 {
460  setPeer(addr);
461  return addr;
462 }
463 
465 {
467  if (addr.is_valid()) {
468  if(port)
469  *port = peer.getPort();
470  } else {
471  peer.setAny();
472  if(port)
473  *port = 0;
474  }
475 
476  return IPV4Host(ucommon::Socket::address::ipv4(addr)->sin_addr);
477 }
478 
479 #ifdef CCXX_IPV6
480 IPV6Host UDPSocket::getIPV6Peer(in_port_t *port)
481 {
483  if (addr.is_valid()) {
484  if(port)
485  *port = peer.getPort();
486  } else {
487  peer.setAny();
488  if(port)
489  *port = 0;
490  }
491 
492  return IPV6Host(ucommon::Socket::address::ipv6(addr)->sin6_addr);
493 }
494 #endif
495 
497 UDPSocket(ia, port)
498 {
499  if(so != INVALID_SOCKET)
500  setBroadcast(true);
501 }
502 
503 void UDPBroadcast::setPeer(const IPV4Broadcast &ia, in_port_t port)
504 {
506 }
507 
509 UDPSocket(ia)
510 {
511  disconnect(); // assure not started live
512  ::shutdown(so, 0);
513  receiveBuffer(0);
514 }
515 
517 UDPSocket(ia, port)
518 {
519  disconnect(); // assure not started live
520  ::shutdown(so, 0);
521  receiveBuffer(0);
522 }
523 
524 #ifdef CCXX_IPV6
525 UDPTransmit::UDPTransmit(const IPV6Address &ia, in_port_t port) :
526 UDPSocket(ia, port)
527 {
528  disconnect(); // assure not started live
529  ::shutdown(so, 0);
530  receiveBuffer(0);
531 }
532 #endif
533 
535 {
536  disconnect();
537  ::shutdown(so, 0);
538  receiveBuffer(0);
539 }
540 
542 {
543  peer = host;
544  if(peer.isAny())
545  peer.setLoopback();
546  if(::connect(so, peer, (socklen_t)peer.getLength()))
547  return connectError();
548  return errSuccess;
549 }
550 
552 {
554 }
555 
556 #ifdef CCXX_IPV6
557 
558 Socket::Error UDPTransmit::connect(const IPV6Address &ia, in_port_t port)
559 {
560  return connect(ucommon::Socket::address(ia.getAddress(), port));
561 }
562 #endif
563 
565 {
566  if(isBroadcast())
567  setBroadcast(false);
568 
569  return cConnect((IPV4Address)ia,port);
570 }
571 
573 {
574  if(!isBroadcast())
575  setBroadcast(true);
576 
577  return cConnect((IPV4Address)subnet,port);
578 }
579 
581 {
582  Error err;
583  if(!( err = UDPSocket::setMulticast(true) ))
584  return err;
585 
586  return cConnect((IPV4Address)group,port);
587 }
588 
589 #ifdef CCXX_IPV6
590 Socket::Error UDPTransmit::connect(const IPV6Multicast &group, in_port_t port)
591 {
592  Error error;
593  if(!( error = UDPSocket::setMulticast(true) ))
594  return error;
595 
596  return connect((IPV6Address)group,port);
597 }
598 #endif
599 
601 UDPSocket(ia)
602 {
603  ::shutdown(so, 1);
604  sendBuffer(0);
605 }
606 
607 UDPReceive::UDPReceive(const IPV4Address &ia, in_port_t port) :
608 UDPSocket(ia, port)
609 {
610  ::shutdown(so, 1);
611  sendBuffer(0);
612 }
613 
614 #ifdef CCXX_IPV6
615 UDPReceive::UDPReceive(const IPV6Address &ia, in_port_t port) :
616 UDPSocket(ia, port)
617 {
618  ::shutdown(so, 1);
619  sendBuffer(0);
620 }
621 #endif
622 
624 {
625  ucommon::Socket::address host = ia;
626  setPeer(host);
627 
628  // Win32 will crash if you try to connect to INADDR_ANY.
629  if(host.isAny())
630  host.setLoopback();
631 
632  if(::connect(so, host, (socklen_t)host.getLength()))
633  return connectError();
634  return errSuccess;
635 }
636 
638 {
640 }
641 
642 #ifdef CCXX_IPV6
643 Socket::Error UDPReceive::connect(const IPV6Host &ia, in_port_t port)
644 {
645  return connect(ucommon::Socket::address(ia.getAddress(), port));
646 }
647 #endif
648 
650 UDPTransmit(bind.withPort(bind.getPort() + 1)), UDPReceive(bind)
651 {}
652 
653 UDPDuplex::UDPDuplex(const IPV4Address &bind, in_port_t port) :
654 UDPTransmit(bind, port + 1), UDPReceive(bind, port)
655 {}
656 
657 #ifdef CCXX_IPV6
658 UDPDuplex::UDPDuplex(const IPV6Address &bind, in_port_t port) :
659 UDPTransmit(bind, port + 1), UDPReceive(bind, port)
660 {}
661 #endif
662 
664 {
665  Error rtn = UDPTransmit::connect(host);
666  if(rtn) {
669  return rtn;
670  }
671  return UDPReceive::connect(host.withPort(host.getPort() + 1));
672 }
673 
675 {
676  Error rtn = UDPTransmit::connect(host, port);
677  if(rtn) {
680  return rtn;
681  }
682  return UDPReceive::connect(host, port + 1);
683 }
684 
685 #ifdef CCXX_IPV6
686 Socket::Error UDPDuplex::connect(const IPV6Host &host, in_port_t port)
687 {
688  Error rtn = UDPTransmit::connect(host, port);
689  if(rtn) {
692  return rtn;
693  }
694  return UDPReceive::connect(host, port + 1);
695 }
696 #endif
697 
699 {
701  Error rtn2 = UDPReceive::disconnect();
702  if (rtn) return rtn;
703  return rtn2;
704 }
705 
706 } // namespace ost
ost::UDPSocket
Unreliable Datagram Protocol sockets.
Definition: udp.h:99
ucommon::Socket::address::getLength
size_t getLength(void) const
Definition: socket.h:531
ost::IPV4Address
Internet Address binary data type.
Definition: address.h:362
ost::UDPSocket::getIPV4Peer
IPV4Host getIPV4Peer(tpport_t *port=NULL)
Definition: udp.cpp:464
ost::Socket::IPV4
Definition: socket.h:109
ucommon::Socket::error
static int error(void)
Definition: socket.cpp:1849
ost::IPV4Multicast
A multicast network address.
Definition: address.h:651
ucommon::freeaddrinfo
static void freeaddrinfo(struct addrinfo *aip)
Definition: socket.cpp:129
ost::Socket::getLocal
ucommon::Socket::address getLocal() const
Definition: socket.cpp:902
ost::UDPSocket::~UDPSocket
virtual ~UDPSocket()
Definition: udp.cpp:260
ost::UDPReceive
Unreliable Datagram Peer Associations.
Definition: udp.h:452
ost::Socket::CONNECTED
Definition: socket.h:99
ucommon::Socket::err
int err(void) const
Definition: socket.h:919
ost::IPV4Address::getAddress
struct in_addr getAddress(void) const
Definition: address.cpp:142
ost::UDPSocket::getPeer
ucommon::Socket::address getPeer()
Definition: udp.cpp:457
export.h
ost::IPV4Host
Address of a specific Internet host machine.
Definition: address.h:578
addrinfo::ai_addrlen
size_t ai_addrlen
Definition: socket.cpp:88
ost::UDPSocket::setMulticast
Error setMulticast(bool enable)
Definition: udp.h:152
ost::UDPSocket::UDPSocket
UDPSocket(Family family=IPV4)
Definition: udp.cpp:204
ost::Socket::BOUND
Definition: socket.h:98
MSG_NOSIGNAL
#define MSG_NOSIGNAL
Definition: socket.cpp:62
_IORET64
#define _IORET64
Definition: udp.cpp:92
string.h
Common C++ generic string class.
ucommon::Socket::recvfrom
static ssize_t recvfrom(socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=NULL)
Definition: socket.cpp:1890
ost::error
__EXPORT AppLog & error(AppLog &sl)
Definition: applog.h:536
ost::Socket::isBroadcast
bool isBroadcast(void) const
Definition: socket.h:632
ost::UDPReceive::UDPReceive
UDPReceive(const ucommon::Socket::address &bind)
Definition: udp.cpp:600
ost::UDPSocket::join
Socket::Error join(const ucommon::Socket::address &ia, int InterfaceIndex=0)
Definition: udp.cpp:311
ost::Socket::join
Error join(const ucommon::Socket::address &ia, int iface=0)
Definition: socket.cpp:488
ost::UDPTransmit::connect
Error connect(const ucommon::Socket::address &host)
Definition: udp.cpp:541
ost::UDPBroadcast::setBroadcast
Error setBroadcast(bool enable)
Definition: udp.h:271
ucommon::Socket::so
socket_t so
Definition: socket.h:330
port
static shell::numericopt port('p', "--port", _TEXT("port to use"), "port", 0)
ost::Socket::errBindingFailed
Definition: socket.h:131
ucommon::Socket::address::getPort
in_port_t getPort(void) const
Definition: socket.h:539
ost::UDPDuplex::connect
Error connect(const ucommon::Socket::address &host)
Definition: udp.cpp:663
AI_PASSIVE
#define AI_PASSIVE
Definition: socket.cpp:100
ost::UDPReceive::connect
Error connect(const ucommon::Socket::address &host)
Definition: udp.cpp:623
ost::UDPTransmit::UDPTransmit
UDPTransmit(Family family=IPV4)
Definition: udp.cpp:534
ost::Socket::endSocket
void endSocket(void)
Definition: socket.cpp:136
ost::Socket::state
State volatile state
Definition: socket.h:187
ucommon::Socket::address::isAny
bool isAny() const
Definition: socket.h:634
addrinfo::ai_addr
struct sockaddr * ai_addr
Definition: socket.cpp:90
ost::UDPTransmit
Unreliable Datagram Peer Associations.
Definition: udp.h:302
ost::Socket
Definition: socket.h:92
addrinfo::ai_family
int ai_family
Definition: socket.cpp:85
ost::Socket::getPeer
ucommon::Socket::address getPeer() const
Definition: socket.cpp:950
ost::Socket::errSuccess
Definition: socket.h:115
ost::UDPSocket::disconnect
Error disconnect(void)
Definition: udp.cpp:376
addrinfo::ai_protocol
int ai_protocol
Definition: socket.cpp:87
INVALID_SOCKET
#define INVALID_SOCKET
Definition: platform.h:416
ost::Socket::isConnected
bool isConnected(void) const
Definition: socket.cpp:1093
ost::Socket::connectError
Error connectError(void) const
Definition: socket.cpp:262
ost::UDPSocket::connect
void connect(const ucommon::Socket::address &host)
Definition: udp.cpp:391
ucommon::Socket::address::ipv4
static struct sockaddr_in * ipv4(struct sockaddr *address)
Definition: socket.cpp:1402
ucommon::Socket::address
friend class address
Definition: socket.h:850
ucommon::getaddrinfo
static int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hintsp, struct addrinfo **res)
Definition: socket.cpp:215
addrinfo::ai_next
struct addrinfo * ai_next
Definition: socket.cpp:91
socket_errno
#define socket_errno
Definition: udp.cpp:60
ost::Socket::sendBuffer
Error sendBuffer(unsigned size)
Definition: socket.cpp:351
ost::UDPDuplex::disconnect
Error disconnect(void)
Definition: udp.cpp:698
ost::Socket::Error
Error
Definition: socket.h:114
ost::UDPTransmit::setBroadcast
Error setBroadcast(bool enable)
Definition: udp.h:440
ost
Definition: address.cpp:63
ost::UDPSocket::getInterfaceIndex
Socket::Error getInterfaceIndex(const char *ethX, int &InterfaceIndex)
Definition: udp.cpp:317
socket.h
socket operations.
AF_UNSPEC
#define AF_UNSPEC
Definition: socket.cpp:418
_IOLEN64
#define _IOLEN64
Definition: udp.cpp:88
ucommon::Socket::address
Definition: socket.h:364
udp.h
udp derived socket classes.
ost::UDPTransmit::cConnect
Error cConnect(const IPV4Address &ia, tpport_t port)
Definition: udp.cpp:551
ost::Socket::Family
Family
Definition: socket.h:105
addrinfo::ai_socktype
int ai_socktype
Definition: socket.cpp:86
ost::UDPSocket::receive
ssize_t receive(void *buf, size_t len, bool reply=false)
Definition: udp.cpp:277
ost::Socket::errServiceUnavailable
Definition: socket.h:136
ucommon::Socket::address::withPort
address withPort(in_port_t port) const
Definition: socket.cpp:1163
ost::UDPBroadcast::UDPBroadcast
UDPBroadcast(const IPV4Address &ia, tpport_t port)
Definition: udp.cpp:496
ost::UDPSocket::send
ssize_t send(const void *buf, size_t len)
Definition: udp.cpp:265
addrinfo::ai_flags
int ai_flags
Definition: socket.cpp:84
config.h
ucommon::Socket::len
static socklen_t len(const struct sockaddr *address)
Definition: socket.cpp:3410
ost::Socket::getaddress
struct in_addr getaddress(const IPV4Address &ia) const
Definition: socket.h:646
ost::IPV4Broadcast
Definition: address.h:629
ucommon::Socket::address::family
int family(void) const
Definition: socket.cpp:1136
ost::UDPSocket::peer
Socket::address peer
Definition: udp.h:108
ost::Socket::receiveBuffer
Error receiveBuffer(unsigned size)
Definition: socket.cpp:371
ucommon::Socket::shutdown
void shutdown(void)
Definition: socket.h:1140
ost::UDPSocket::family
Family family
Definition: udp.h:110
ost::UDPSocket::setPeer
void setPeer(const ucommon::Socket::address &host)
Definition: udp.cpp:386
ucommon::Socket::address::setLoopback
void setLoopback(int family=AF_UNSPEC)
Definition: socket.cpp:1356
ost::UDPDuplex::UDPDuplex
UDPDuplex(const ucommon::Socket::address &bind)
Definition: udp.cpp:649
ucommon::Socket::address::get
const struct sockaddr * get(void) const
Definition: socket.cpp:1128
ucommon::Socket::query
static struct addrinfo * query(const char *host, const char *service, int type=SOCK_STREAM, int protocol=0)
Definition: socket.cpp:956
ucommon::addr
const struct sockaddr * addr(Socket::address &address)
Definition: socket.h:2089
ost::UDPBroadcast::setPeer
void setPeer(const IPV4Host &ia, tpport_t port)
addrinfo
Definition: socket.cpp:83
ucommon::Socket::port
static in_port_t port(const struct sockaddr *address)
Definition: socket.cpp:3117