UCommon
socket.h
Go to the documentation of this file.
1// Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2// Copyright (C) 2015 Cherokees of Idaho.
3//
4// This file is part of GNU uCommon C++.
5//
6// GNU uCommon C++ is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// GNU uCommon C++ is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18
27#ifndef _UCOMMON_SOCKET_H_
28#define _UCOMMON_SOCKET_H_
29
30#ifndef _UCOMMON_TIMERS_H_
31#include <ucommon/timers.h>
32#endif
33
34#ifndef _UCOMMON_LINKED_H_
35#include <ucommon/linked.h>
36#endif
37
38#ifndef _UCOMMON_STRING_H_
39#include <ucommon/string.h>
40#endif
41
42#ifndef _UCOMMON_TYPEREF_H_
43#include <ucommon/typeref.h>
44#endif
45
46extern "C" {
47 struct addrinfo;
48}
49
50#ifdef _MSWINDOWS_
51#define SHUT_RDWR SD_BOTH
52#define SHUT_WR SD_SEND
53#define SHUT_RD SD_RECV
54typedef uint16_t in_port_t;
55typedef uint32_t in_addr_t;
56#else
57#include <unistd.h>
58#include <sys/socket.h>
59#include <net/if.h>
60#include <netinet/in.h>
61#include <netdb.h>
62#endif
63
64#if defined(__ANDROID__)
65typedef uint16_t in_port_t;
66#endif
67
68#include <errno.h>
69#include <stdio.h>
70
71#ifndef IPTOS_LOWDELAY
72#define IPTOS_LOWDELAY 0x10
73#define IPTOS_THROUGHPUT 0x08
74#define IPTOS_RELIABILITY 0x04
75#define IPTOS_MINCOST 0x02
76#endif
77
78#ifdef AF_UNSPEC
79#define DEFAULT_FAMILY AF_UNSPEC
80#else
81#define DEFAULT_FAMILY AF_INET
82#endif
83
84typedef struct sockaddr *sockaddr_t;
85
86typedef struct sockaddr sockaddr_struct; // older gcc needs...?
87
92{
93 union
94 {
95 struct in_addr ipv4;
96#ifdef AF_INET6
97 struct in6_addr ipv6;
98#endif
99 };
100};
101
102#if defined(AF_INET6) || defined(__CYGWIN__)
111{
112 union {
113#ifdef AF_INET6
114 struct sockaddr_in6 ipv6;
115#endif
116 struct sockaddr_in ipv4;
117 struct sockaddr address;
118 };
119};
120#else
122{
123 union {
124 struct sockaddr_in ipv4;
125 struct sockaddr address;
126 };
127};
128
129struct sockaddr_storage
130{
131#ifdef AF_UNIX
132 char sa_data[128];
133#else
134 char sa_data[sizeof(struct sockaddr_in)];
135#endif
136};
137#endif
138
139#ifndef SOCK_DCCP
140#define SOCK_DCCP 6
141#endif
142
143#ifndef IPPROTO_DCCP
144#define IPPROTO_DCCP 23
145#endif
146
147#ifndef SOL_DCCP
148#define SOL_DCCP 269
149#endif
150
151#define DCCP_SOCKOPT_AVAILABLE_CCIDS 12
152#define DCCP_SOCKOPT_CCID 13
153#define DCCP_SOCKOPT_TX_CCID 14
154#define DCCP_SOCKOPT_RX_CCID 15
155
156namespace ucommon {
157
167class __EXPORT cidr : public LinkedObject
168{
169protected:
170 int Family;
171 struct hostaddr_internet Netmask, Network;
172 char Name[16];
173
174 unsigned mask(const char *cp) const;
175
176 struct hostaddr_internet broadcast(void) const;
177
178 unsigned mask(void) const;
179
180public:
185
190
197 cidr(const char *string);
198
204 cidr(policy **policy, const char *string);
205
212 cidr(policy **policy, const char *string, const char *name);
213
218 cidr(const cidr& existing);
219
226 static const cidr *find(const policy *policy, const struct sockaddr *address);
227
235 static const cidr *container(const policy *policy, const struct sockaddr *address);
236
244 inline const char *getName(void) const {
245 return Name;
246 }
247
252 inline int getFamily(void) const {
253 return Family;
254 }
255
260 inline struct hostaddr_internet getNetwork(void) const {
261 return Network;
262 }
263
268 inline struct hostaddr_internet getNetmask(void) const {
269 return Netmask;
270 }
271
276 inline struct hostaddr_internet getBroadcast(void) const {
277 return broadcast();
278 }
279
284 inline unsigned getMask(void) const {
285 return mask();
286 }
287
292 void set(const char *string);
293
299 bool is_member(const struct sockaddr *address) const;
300
306 inline bool operator==(const struct sockaddr *address) const {
307 return is_member(address);
308 }
309
315 inline bool operator!=(const struct sockaddr *address) const {
316 return !is_member(address);
317 }
318};
319
327class __EXPORT Socket
328{
329protected:
330 socket_t so;
331 int ioerr;
332 timeout_t iowait;
333
334public:
335 // temporary splints...
336 typedef struct hostaddr_internet host_t;
337 typedef cidr cidr_t;
338
347 static struct addrinfo *query(const char *host, const char *service, int type = SOCK_STREAM, int protocol = 0);
348
354 static void release(struct addrinfo *list);
355
364 class __EXPORT address
365 {
366 protected:
367 struct addrinfo *list;
368
369 public:
380 address(int family, const char *address, int type = SOCK_STREAM, int protocol = 0);
381
394 address(int family, const char *hostname, const char *service = NULL);
395
402 address(const char *host, const char *service, int type = SOCK_STREAM);
403
411 address(const char *hostname, in_port_t port = 0);
412
416 address(const in_addr& address, in_port_t port = 0);
417
421 address(const in6_addr& address, in_port_t port = 0);
422
426 address(const sockaddr& address) : list(NULL) {
427 insert(&address);
428 }
429
433 address(const addrinfo* address) : list(NULL) {
434 insert(address);
435 }
436
441
446 address(const address& reference);
447
453
458
464 bool operator==(const address& other) const;
465
466 inline bool operator!=(const address& other) const {
467 return !(*this==other);
468 }
469
470 inline bool equals(const address& other) const {
471 return *this == other;
472 }
473
478 const struct sockaddr *get(void) const;
479
480 struct sockaddr *modify(void);
481
482 inline const struct sockaddr *getAddr(void) const {
483 return get();
484 }
485
486 inline const struct sockaddr *operator()(void) const {
487 return get();
488 }
489
494 inline operator struct sockaddr *() {
495 return modify();
496 }
497
503 const struct sockaddr *get(int family) const;
504
505 struct sockaddr *modify(int family);
506
507 inline const struct sockaddr *operator()(int family) const {
508 return get(family);
509 }
510
511 inline operator struct sockaddr_in *() {
512 return (struct sockaddr_in *)modify(AF_INET);
513 }
514
515#ifdef AF_INET6
516 inline operator struct sockaddr_in6 *() {
517 return (struct sockaddr_in6 *)modify(AF_INET6);
518 }
519#endif
520
525 int family(void) const;
526
531 inline size_t getLength(void) const {
532 return len(get());
533 }
534
539 inline in_port_t getPort(void) const {
540 return getPort(get());
541 }
542
547 void setPort(in_port_t port);
548
553 address withPort(in_port_t port) const;
554
559 struct sockaddr *find(const struct sockaddr *addr) const;
560
565 inline struct addrinfo *getList(void) const {
566 return list;
567 }
568
573 inline operator struct addrinfo *() const {
574 return list;
575 }
576
581 inline struct addrinfo *operator*() const {
582 return list;
583 }
584
597 size_t print(char* dst, size_t dst_sz, bool port=false, bool force_brackets=false) const {
598 return print(get(), dst, dst_sz, port, force_brackets);
599 }
600
605 inline operator bool() const {
606 return list != nullptr;
607 }
608
609 inline bool is_valid() const {
610 return list != nullptr;
611 }
612
613 inline bool isValid() const {
614 return list != nullptr;
615 }
616
621 inline bool operator!() const {
622 return list == nullptr;
623 }
624
630 inline bool is_any() const {
631 return isAny(get());
632 }
633
634 inline bool isAny() const {
635 return isAny(get());
636 }
637
644 void setAny(int family = AF_UNSPEC);
645
651 inline bool is_loopback() const {
652 return isLoopback(get());
653 }
654
655 inline bool isLoopback() const {
656 return isLoopback(get());
657 }
658
665 void setLoopback(int family = AF_UNSPEC);
666
670 void clear(void);
671
678 void set(const char *hostname, const char *service = NULL, int type = SOCK_STREAM);
679
686 void add(const char *hostname, const char *service = NULL, int type = SOCK_STREAM);
687
695 void set(int family, const char *address, int type = SOCK_STREAM, int protocol = 0);
696
701 void add(sockaddr *address);
702
708 unsigned insert(const struct addrinfo *address);
709
715 unsigned remove(const struct addrinfo *address);
716
722 bool remove(const struct sockaddr *address);
723
730 bool insert(const struct sockaddr *address);
731
737 void copy(const struct addrinfo *address);
738
743 void set(struct sockaddr *address);
744
750 void set(const char *hostname, in_port_t service = 0);
751
756 static size_t getLength(const struct sockaddr *address) {
757 return len(address);
758 }
759
764 inline static in_port_t getPort(const struct sockaddr *address) {
765 return Socket::port(address);
766 }
767
773 static void setPort(struct sockaddr *address, in_port_t port);
774
780 static bool isAny(const struct sockaddr *address);
781
786 static void setAny(struct sockaddr *sa);
787
791 static sockaddr_storage any(int family);
792
798 static bool isLoopback(const struct sockaddr *address);
799
805 static void setLoopback(struct sockaddr *sa);
806
810 static sockaddr_storage loopback(int family);
811
817 static struct sockaddr *dup(struct sockaddr *address);
818
824 static struct sockaddr_in *ipv4(struct sockaddr *address);
825
826#ifdef AF_INET6
832 static struct sockaddr_in6 *ipv6(struct sockaddr *address);
833#endif
834
847 static size_t print(const struct sockaddr *src, char* dst, size_t dst_sz, bool port=false, bool ipv6_brackets=false);
848 };
849
850 friend class address;
851
856
861 Socket(const Socket& existing);
862
867 Socket(socket_t socket);
868
874 Socket(const struct addrinfo *address);
875
882 Socket(int family, int type, int protocol = 0);
883
893 Socket(const char *address, const char *port, int family = AF_UNSPEC, int type = 0, int protocol = 0);
894
898 virtual ~Socket();
899
903 void cancel(void);
904
909 static void cancel(socket_t socket);
910
914 void release(void);
915
919 inline int err(void) const {
920 return ioerr;
921 }
922
928 bool is_pending(unsigned value);
929
934 bool connected(void) const;
935
942 bool wait(timeout_t timeout = 0) const;
943
948 inline int nodelay(void) const {
949 return nodelay(so);
950 }
951
959 static bool wait(socket_t socket, timeout_t timeout = 0);
960
967 bool waitSending(timeout_t timeout = 0) const;
968
973 inline unsigned pending(void) const {
974 return pending(so);
975 }
976
982 inline int broadcast(bool enable) {
983 return broadcast(so, enable);
984 }
985
991 inline int keepalive(bool enable) {
992 return keepalive(so, enable);
993 }
994
1000 inline int blocking(bool enable) {
1001 return blocking(so, enable);
1002 }
1003
1009 inline int multicast(unsigned ttl = 1) {
1010 return multicast(so, ttl);
1011 }
1012
1018 inline int loopback(bool enable) {
1019 return loopback(so, enable);
1020 }
1021
1026 inline int getError(void) const {
1027 return error(so);
1028 }
1029
1035 inline int ttl(uint8_t time) {
1036 return ttl(so, time);
1037 }
1038
1044 inline int sendsize(unsigned size) {
1045 return sendsize(so, size);
1046 }
1047
1053 inline int sendwait(unsigned size) {
1054 return sendwait(so, size);
1055 }
1056
1062 inline int recvsize(unsigned size) {
1063 return recvsize(so, size);
1064 }
1065
1071 static int type(const socket_t socket);
1072
1079 static unsigned segsize(socket_t socket, unsigned size = 0);
1080
1087 static bool ccid(socket_t socket, uint8_t id);
1088
1093 inline int type(void) const {
1094 return type(so);
1095 }
1096
1102 inline unsigned segsize(unsigned size) {
1103 return segsize(so, size);
1104 }
1105
1111 inline bool ccid(uint8_t id) {
1112 return ccid(so, id);
1113 }
1114
1123 inline int tos(int type) {
1124 return tos(so, type);
1125 }
1126
1133 inline int priority(int scheduling) {
1134 return priority(so, scheduling);
1135 }
1136
1140 inline void shutdown(void) {
1141 ::shutdown(so, SHUT_RDWR);
1142 }
1143
1151 int connectto(struct addrinfo *list);
1152
1159 int disconnect(void);
1160
1166 int join(const struct addrinfo *list, const int ifindex = 0);
1167
1173 int drop(const struct addrinfo *list, const int ifindex = 0);
1174
1180 int wait(timeout_t timeout = Timer::inf);
1181
1188 size_t peek(void *data, size_t number) const;
1189
1197 size_t readfrom(void *data, size_t number, struct sockaddr_storage *address = NULL);
1198
1206 size_t writeto(const void *data, size_t number, const struct sockaddr *address = NULL);
1207
1220 size_t readline(char *data, size_t size);
1221
1227 size_t printf(const char *format, ...) __PRINTF(2,3);
1228
1240 size_t readline(String& buffer);
1241
1242 stringref_t readline(size_t maxsize);
1243
1255 static ssize_t readline(socket_t socket, char *data, size_t size, timeout_t timeout = Timer::inf);
1256
1263 static ssize_t printf(socket_t socket, const char *format, ...) __PRINTF(2,3);
1264
1272 size_t writes(const char *string);
1273
1278 operator bool() const;
1279
1284 bool operator!() const;
1285
1291 Socket& operator=(socket_t socket);
1292
1297 inline operator socket_t() const {
1298 return so;
1299 }
1300
1305 inline socket_t operator*() const {
1306 return so;
1307 }
1308
1315 static unsigned pending(socket_t socket);
1316
1323 static int sendsize(socket_t socket, unsigned size);
1324
1331 static int sendwait(socket_t socket, unsigned size);
1332
1339 static int recvsize(socket_t socket, unsigned size);
1340
1349 static int connectto(socket_t socket, struct addrinfo *list);
1350
1356 static int disconnect(socket_t socket);
1357
1364 static int drop(socket_t socket, const struct addrinfo *list, const int ifindex = 0);
1365
1372 static int join(socket_t socket, const struct addrinfo *list, const int ifindex = 0);
1373
1379 static int error(const socket_t socket);
1380
1387 static int multicast(socket_t socket, unsigned ttl = 1);
1388
1395 static int loopback(socket_t socket, bool enable);
1396
1403 static int blocking(socket_t socket, bool enable);
1404
1411 static int keepalive(socket_t socket, bool enable);
1412
1419 static int broadcast(socket_t socket, bool enable);
1420
1426 static int nodelay(socket_t socket);
1427
1434 static int priority(socket_t socket, int scheduling);
1435
1442 static int tos(socket_t socket, int type);
1443
1450 static int ttl(socket_t socket, uint8_t time);
1451
1456 static int family(socket_t socket);
1457
1463 inline static int family(const struct sockaddr_storage& address) {
1464 return ((const struct sockaddr *)&address)->sa_family;
1465 }
1466
1472 inline static int family(const struct sockaddr_internet& address) {
1473 return address.address.sa_family;
1474 }
1475
1485 static ssize_t recvfrom(socket_t socket, void *buffer, size_t size, int flags = 0, struct sockaddr_storage *address = NULL);
1486
1496 static ssize_t sendto(socket_t socket, const void *buffer, size_t size, int flags = 0, const struct sockaddr *address = NULL);
1497
1507 inline static ssize_t replyto(socket_t socket, const void *buffer, size_t size, int flags, const struct sockaddr_storage *address) {
1508 return sendto(socket, buffer, size, flags, (const struct sockaddr *)address);
1509 }
1510
1519 static int bindto(socket_t socket, const char *address, const char *service, int protocol = 0);
1520
1528 static int listento(socket_t socket, const struct sockaddr *address, int backlog = 5);
1529
1536 static int bindto(socket_t socket, const struct sockaddr *address);
1537
1544 static socket_t acceptfrom(socket_t socket, struct sockaddr_storage *address = NULL);
1545
1553 static socket_t create(int family, int type, int protocol);
1554
1562 static socket_t create(const struct addrinfo *address, int type, int protocol);
1563
1573 static socket_t create(const char *iface, const char *service, int family = AF_UNSPEC, int type = 0, int protocol = 0);
1574
1580 static socket_t create(const Socket::address &address);
1581
1586 static void release(socket_t socket);
1587
1595 static char *hostname(const struct sockaddr *address, char *buffer, size_t size);
1596
1604 static struct addrinfo *hinting(socket_t socket, struct addrinfo *hint);
1605
1616 static socklen_t query(socket_t socket, struct sockaddr_storage *address, const char *hostname, const char *service);
1617
1623 static socklen_t len(const struct sockaddr *address);
1624
1632 static bool equal(const struct sockaddr *address1, const struct sockaddr *address2);
1633
1640 static unsigned copy(struct sockaddr *target, const struct sockaddr *origin);
1641
1648 static unsigned store(struct sockaddr_storage *storage, const struct sockaddr *address);
1649
1656 static unsigned store(struct sockaddr_internet *storage, const struct sockaddr *address);
1657
1665 static bool eq_host(const struct sockaddr *address1, const struct sockaddr *address2);
1666
1674 inline static bool eq_from(const struct sockaddr_storage *address1, const struct sockaddr_storage *address2) {
1675 return equal((const struct sockaddr *)address1, (const struct sockaddr *)address2);
1676 }
1677
1685 inline static bool eq_inet(const struct sockaddr_internet *address1, const struct sockaddr_internet *address2) {
1686 return equal((const struct sockaddr *)address1, (const struct sockaddr *)address2);
1687 }
1688
1696 static bool eq_subnet(const struct sockaddr *address1, const struct sockaddr *address2);
1697
1706 static int via(struct sockaddr *address, const struct sockaddr *target, socklen_t size = 0);
1707
1715 static char *query(const struct sockaddr *address, char *buffer, socklen_t size);
1716
1722 static in_port_t port(const struct sockaddr *address);
1723
1729 inline static in_port_t port(const struct sockaddr_internet *address) {
1730 return port((const struct sockaddr *)address);
1731 }
1732
1739 static unsigned keyindex(const struct sockaddr *address, unsigned size);
1740
1747 static unsigned keyhost(const struct sockaddr *address, unsigned size);
1748
1752 static void init(void);
1753
1759 static void query(int family);
1760
1767 static void v4mapping(bool enable);
1768
1773 static int error(void);
1774
1783 static bool is_null(const char *string);
1784
1792 static bool is_numeric(const char *string);
1793
1802 static int local(socket_t socket, struct sockaddr_storage *address);
1803
1812 static int remote(socket_t socket, struct sockaddr_storage *address);
1813};
1814
1820class __EXPORT ListenSocket : protected Socket
1821{
1822private:
1823 __DELETE_COPY(ListenSocket);
1824
1825public:
1835 ListenSocket(const char *address, const char *service, unsigned backlog = 5, int family = AF_UNSPEC, int type = 0, int protocol = 0);
1836
1847 static socket_t create(const char *address, const char *service, unsigned backlog = 5, int family = AF_UNSPEC, int type = 0, int protocol = 0);
1848
1854 socket_t accept(struct sockaddr_storage *address = NULL) const;
1855
1861 inline bool wait(timeout_t timeout = Timer::inf) const {
1862 return Socket::wait(timeout);
1863 }
1864
1869 inline operator socket_t() const {
1870 return so;
1871 }
1872
1877 inline socket_t operator*() const {
1878 return so;
1879 }
1880
1885 inline socket_t getsocket(void) const {
1886 return so;
1887 }
1888
1889 inline socket_t handle(void) const {
1890 return so;
1891 }
1892
1893};
1894
1900class __EXPORT TCPServer : public ListenSocket
1901{
1902private:
1903 __DELETE_DEFAULTS(TCPServer);
1904
1905public:
1913 TCPServer(const char *address, const char *service, unsigned backlog = 5);
1914};
1915
1921{
1922protected:
1923 inline linked_sockaddr_operations() {}
1924
1928 const struct addrinfo *_nextaddrinfo(const struct addrinfo *addrinfo) const;
1929
1933 const struct sockaddr *_getaddrinfo(const struct addrinfo *addrinfo) const;
1934
1938 socket_t _getaddrsock(const struct addrinfo *addrinfo) const;
1939};
1940
1946template <>
1947class linked_pointer<sockaddr_struct> : private linked_sockaddr_operations
1948{
1949private:
1950 const struct addrinfo *ptr;
1951
1952public:
1953 inline linked_pointer(const struct addrinfo *list) {
1954 ptr = list;
1955 }
1956
1957 inline linked_pointer(const linked_pointer& copy) {
1958 ptr = copy.ptr;
1959 }
1960
1961 inline linked_pointer() {
1962 ptr = nullptr;
1963 }
1964
1965 inline linked_pointer(Socket::address& list) {
1966 ptr = list.getList();
1967 }
1968
1973 inline operator const struct sockaddr *() const {
1974 return _getaddrinfo(ptr);
1975 }
1976
1981 inline const struct sockaddr *operator*() const {
1982 return _getaddrinfo(ptr);
1983 }
1984
1985 inline operator const struct sockaddr_in *() const {
1986 return (struct sockaddr_in *)_getaddrinfo(ptr);
1987 }
1988
1989 inline const struct sockaddr_in *in(void) const {
1990 return (struct sockaddr_in *)_getaddrinfo(ptr);
1991 }
1992
1993#ifdef AF_INET6
1994 inline operator const struct sockaddr_in6 *() const {
1995 return (struct sockaddr_in6 *)_getaddrinfo(ptr);
1996 }
1997
1998 inline const struct sockaddr_in6 *in6(void) const {
1999 return (struct sockaddr_in6 *)_getaddrinfo(ptr);
2000 }
2001#endif
2002
2006 inline socket_t operator()(void) const {
2007 return _getaddrsock(ptr);
2008 }
2009
2014 inline operator bool() const {
2015 return ptr != nullptr;
2016 }
2017
2022 inline linked_pointer& operator=(const struct addrinfo *list) {
2023 ptr = list;
2024 return *this;
2025 }
2026
2032 ptr = list.getList();
2033 return *this;
2034 }
2035
2040 inline void set(const struct addrinfo *list) {
2041 ptr = list;
2042 }
2043
2048 inline void set(Socket::address& list) {
2049 ptr = list.getList();
2050 }
2051
2052
2057 inline const struct sockaddr* operator->() const {
2058 return _getaddrinfo(ptr);
2059 }
2060
2065 inline bool operator!() const {
2066 return ptr == nullptr;
2067 }
2068
2069 inline void next(void) {
2070 ptr = _nextaddrinfo(ptr);
2071 }
2072};
2073
2079inline struct addrinfo *addrinfo(Socket::address& address) {
2080 return address.getList();
2081}
2082
2089inline const struct sockaddr *addr(Socket::address& address) {
2090 return address.get();
2091}
2092
2100inline bool eq(const struct sockaddr *s1, const struct sockaddr *s2) {
2101 return Socket::equal(s1, s2);
2102}
2103
2111inline bool eq(const struct sockaddr_storage *s1, const struct sockaddr_storage *s2) {
2112 return Socket::equal((const struct sockaddr *)s1, (const struct sockaddr *)s2);
2113}
2114
2122inline bool eq_host(const struct sockaddr *s1, const struct sockaddr *s2) {
2123 return Socket::eq_host(s1, s2);
2124}
2125
2126inline bool eq_subnet(const struct sockaddr *s1, const struct sockaddr *s2) {
2127 return Socket::eq_subnet(s1, s2);
2128}
2129
2130String str(Socket& so, size_t size);
2131
2132namespace Type {
2133
2134 class HostAddress
2135 {
2136 private:
2137 struct hostaddr_internet storage;
2138
2139 public:
2140 inline HostAddress() {
2141 memset(&storage, 0, sizeof(storage));
2142 }
2143
2144 inline HostAddress(const HostAddress& copy) {
2145 memcpy(&storage, &copy.storage, sizeof(storage));
2146 }
2147
2148 inline HostAddress(const struct hostaddr_internet *addr) {
2149 memcpy(&storage, addr, sizeof(struct hostaddr_internet));
2150 }
2151
2152 inline HostAddress(const in_addr *addr) {
2153 memset(&storage, 0, sizeof(storage));
2154 memcpy(&storage, addr, sizeof(struct in_addr));
2155 }
2156
2157#ifdef AF_INET6
2158 inline HostAddress(const in6_addr *addr) {
2159 memset(&storage, 0, sizeof(storage));
2160 memcpy(&storage, addr, sizeof(struct in6_addr));
2161 }
2162#endif
2163
2164 inline operator const struct hostaddr_internet *() const {
2165 return &storage;
2166 }
2167
2168 inline struct hostaddr_internet *operator*() {
2169 return &storage;
2170 }
2171
2172 inline socklen_t size() {
2173 return sizeof(storage);
2174 }
2175
2176 inline HostAddress& operator=(const HostAddress& copy) {
2177 memcpy(&storage, &copy.storage, sizeof(storage));
2178 return *this;
2179 }
2180
2181 inline HostAddress& operator=(const struct hostaddr_internet *host) {
2182 memcpy(&storage, host, sizeof(struct hostaddr_internet));
2183 return *this;
2184 }
2185
2186 inline bool operator==(const HostAddress& check) const {
2187 return (memcmp(&check.storage, &storage, sizeof(storage)) == 0);
2188 }
2189
2190 inline bool operator!=(const HostAddress& check) const {
2191 return (memcmp(&check.storage, &storage, sizeof(storage)) != 0);
2192 }
2193
2194 inline bool operator==(const struct hostaddr_internet *host) const {
2195 return (memcmp(host, &storage, sizeof(storage)) == 0);
2196 }
2197
2198 inline bool operator!=(const struct hostaddr_internet *host) const {
2199 return (memcmp(host, &storage, sizeof(storage)) != 0);
2200 }
2201 };
2202
2203 class SockAddress
2204 {
2205 private:
2206 struct sockaddr_storage storage;
2207
2208 public:
2209 inline SockAddress() {
2210 memset(&storage, 0, sizeof(storage));
2211 }
2212
2213 inline SockAddress(const SockAddress& copy) {
2214 memcpy(&storage, &copy.storage, sizeof(storage));
2215 }
2216
2217 inline SockAddress(const struct sockaddr *addr) {
2218 Socket::store(&storage, addr);
2219 }
2220
2221 inline SockAddress& operator=(const SockAddress& copy) {
2222 memcpy(&storage, &copy.storage, sizeof(storage));
2223 return *this;
2224 }
2225
2226 inline SockAddress& operator=(const struct sockaddr *addr) {
2227 Socket::store(&storage, addr);
2228 return *this;
2229 }
2230
2231 inline operator const struct sockaddr *() const {
2232 return (const struct sockaddr*)&storage;
2233 }
2234
2235 inline struct sockaddr *operator*() {
2236 return (struct sockaddr *)&storage;
2237 }
2238
2239 inline const struct sockaddr *get() const {
2240 return (const struct sockaddr *)&storage;
2241 }
2242
2243 inline socklen_t size() {
2244 return sizeof(storage);
2245 }
2246
2247 inline bool operator==(const SockAddress& check) const {
2248 return Socket::equal(get(), check.get());
2249 }
2250
2251 inline bool operator!=(const SockAddress& check) const {
2252 return !Socket::equal(get(), check.get());
2253 }
2254
2255 inline bool operator==(const struct sockaddr *check) const {
2256 return Socket::equal(get(), check);
2257 }
2258
2259 inline bool operator!=(const struct sockaddr *check) const {
2260 return !Socket::equal(get(), check);
2261 }
2262 };
2263
2264 class InetAddress
2265 {
2266 private:
2267 struct sockaddr_internet storage;
2268
2269 public:
2270 inline InetAddress() {
2271 memset(&storage, 0, sizeof(storage));
2272 }
2273
2274 inline InetAddress(const InetAddress& copy) {
2275 memcpy(&storage, &copy.storage, sizeof(storage));
2276 }
2277
2278 inline InetAddress(const struct sockaddr *addr) {
2279 Socket::store(&storage, addr);
2280 }
2281
2282 inline InetAddress& operator=(const InetAddress& copy) {
2283 memcpy(&storage, &copy.storage, sizeof(storage));
2284 return *this;
2285 }
2286
2287 inline InetAddress& operator=(const struct sockaddr *addr) {
2288 Socket::store(&storage, addr);
2289 return *this;
2290 }
2291
2292 inline operator const struct sockaddr *() const {
2293 return (const struct sockaddr*)&storage;
2294 }
2295
2296 inline struct sockaddr *operator*() {
2297 return (struct sockaddr *)&storage;
2298 }
2299
2300 inline const struct sockaddr *get() const {
2301 return (const struct sockaddr *)&storage;
2302 }
2303
2304 inline socklen_t size() {
2305 return sizeof(storage);
2306 }
2307
2308 inline bool operator==(const SockAddress& check) const {
2309 return Socket::equal(get(), check.get());
2310 }
2311
2312 inline bool operator!=(const SockAddress& check) const {
2313 return !Socket::equal(get(), check.get());
2314 }
2315
2316 inline bool operator==(const struct sockaddr *check) const {
2317 return Socket::equal(get(), check);
2318 }
2319
2320 inline bool operator!=(const struct sockaddr *check) const {
2321 return !Socket::equal(get(), check);
2322 }
2323 };
2324}
2325
2326typedef TCPServer tcpserv_t;
2327
2328} // namespace ucommon
2329
2330#endif
A thread-safe atomic heap management system.
Linked objects, lists, templates, and containers.
Realtime timers and timer queues.
Common namespace for all ucommon objects.
Definition access.h:47
bool eq(const struct sockaddr *s1, const struct sockaddr *s2)
Compare two socket addresses to see if equal.
Definition socket.h:2100
struct addrinfo * addrinfo(Socket::address &address)
A convenience function to convert a socket address list into an addrinfo.
Definition socket.h:2079
bool eq_host(const struct sockaddr *s1, const struct sockaddr *s2)
Compare two host addresses to see if equal.
Definition socket.h:2122
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.
Definition socket.h:2089
T copy(const T &src)
Convenience function to copy objects.
Definition generics.h:395
Common base class for all objects that can be formed into a linked list.
Definition linked.h:56
A smart pointer template for iterating linked lists.
Definition linked.h:992
linked_pointer()
Create a linked pointer not attached to a list.
Definition linked.h:1036
void next(void)
Move (iterate) pointer to next member in linked list.
Definition linked.h:1106
An object that holds ipv4 or ipv6 binary encoded host addresses.
Definition socket.h:92
An object that can hold a ipv4 or ipv6 socket address.
Definition socket.h:111
A class to hold internet segment routing rules.
Definition socket.h:168
cidr(const char *string)
Create an unlinked cidr from a string.
int getFamily(void) const
Get the address family of our cidr block object.
Definition socket.h:252
unsigned getMask(void) const
Get the number of bits in the cidr bitmask.
Definition socket.h:284
cidr(const cidr &existing)
Construct a copy of an existing cidr.
cidr()
Create an uninitialized cidr.
cidr(policy **policy, const char *string, const char *name)
Create a named cidr entry on a specified policy chain.
const char * getName(void) const
Get the saved name of our cidr.
Definition socket.h:244
void set(const char *string)
Set our cidr to a string address.
bool is_member(const struct sockaddr *address) const
Test if a given socket address falls within this cidr.
static const cidr * find(const policy *policy, const struct sockaddr *address)
Find the smallest cidr entry in a list that matches the socket address.
bool operator!=(const struct sockaddr *address) const
Test if a given socket address falls outside this cidr.
Definition socket.h:315
cidr(policy **policy, const char *string)
Create an unnamed cidr entry on a specified policy chain.
bool operator==(const struct sockaddr *address) const
Test if a given socket address falls within this cidr.
Definition socket.h:306
LinkedObject policy
A convenience type for using a pointer to a linked list as a policy chain.
Definition socket.h:184
static const cidr * container(const policy *policy, const struct sockaddr *address)
Get the largest container cidr entry in a list that matches the socket address.
A generic socket base class.
Definition socket.h:328
static int recvsize(socket_t socket, unsigned size)
Set the receive size of a socket descriptor.
static in_port_t port(const struct sockaddr_internet *address)
Get the service port of an inet socket.
Definition socket.h:1729
static int listento(socket_t socket, const struct sockaddr *address, int backlog=5)
Bind the socket descriptor to a known interface listen on service port.
size_t readline(char *data, size_t size)
Read a newline of text data from the socket and save in NULL terminated string.
int recvsize(unsigned size)
Set the size of the socket receive buffer.
Definition socket.h:1062
static int broadcast(socket_t socket, bool enable)
Set socket for unicast mode broadcasts on socket descriptor.
bool is_pending(unsigned value)
See the number of bytes in the receive queue.
static int blocking(socket_t socket, bool enable)
Set socket blocking I/O mode of socket descriptor.
static struct addrinfo * hinting(socket_t socket, struct addrinfo *hint)
Create an address info lookup hint based on the family and type properties of a socket descriptor.
static bool eq_from(const struct sockaddr_storage *address1, const struct sockaddr_storage *address2)
Compare socket addresses.
Definition socket.h:1674
Socket(socket_t socket)
Create socket from existing socket descriptor.
static void release(socket_t socket)
Release (close) a socket.
int join(const struct addrinfo *list, const int ifindex=0)
Join socket to multicast group.
static int family(socket_t socket)
Get the address family of the socket descriptor.
static unsigned keyhost(const struct sockaddr *address, unsigned size)
Convert a socket host address into a hash map index.
int drop(const struct addrinfo *list, const int ifindex=0)
Drop socket from multicast group.
int broadcast(bool enable)
Set socket for unicast mode broadcasts.
Definition socket.h:982
static void init(void)
Initialize socket subsystem.
static bool eq_host(const struct sockaddr *address1, const struct sockaddr *address2)
Compare socket host addresses.
static bool wait(socket_t socket, timeout_t timeout=0)
Test for pending input data.
static ssize_t recvfrom(socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=NULL)
Get data waiting in receive queue.
static int loopback(socket_t socket, bool enable)
Set loopback to read multicast packets socket descriptor broadcasts.
static socklen_t len(const struct sockaddr *address)
Get the size of a socket address.
static int nodelay(socket_t socket)
Set tcp nodelay option on socket descriptor.
static unsigned copy(struct sockaddr *target, const struct sockaddr *origin)
Copy a socket address.
static void v4mapping(bool enable)
Set the default socket behavior for v6-v4 mapping.
static int type(const socket_t socket)
Get the type of a socket.
static socket_t create(const char *iface, const char *service, int family=0, int type=0, int protocol=0)
Create a bound socket for a service.
static int tos(socket_t socket, int type)
Set type of service of socket descriptor.
static int local(socket_t socket, struct sockaddr_storage *address)
Get local address to which the socket is bound.
int ttl(uint8_t time)
Set the time to live before packets expire.
Definition socket.h:1035
socket_t operator*() const
Get the socket descriptor by pointer reference.
Definition socket.h:1305
static unsigned store(struct sockaddr_storage *storage, const struct sockaddr *address)
Store an address into an address object.
Socket(int family, int type, int protocol=0)
Create an unbound socket of a specific type.
static char * query(const struct sockaddr *address, char *buffer, socklen_t size)
Get the hostname of a socket address.
virtual ~Socket()
Shutdown, close, and destroy socket.
static int priority(socket_t socket, int scheduling)
Set packet priority of socket descriptor.
int sendsize(unsigned size)
Set the size of the socket send buffer.
Definition socket.h:1044
int tos(int type)
Set the type of service field of outgoing packets.
Definition socket.h:1123
static unsigned keyindex(const struct sockaddr *address, unsigned size)
Convert a socket address and service into a hash map index.
static bool eq_inet(const struct sockaddr_internet *address1, const struct sockaddr_internet *address2)
Compare socket addresses.
Definition socket.h:1685
int disconnect(void)
Disconnect a connected socket.
static int via(struct sockaddr *address, const struct sockaddr *target, socklen_t size=0)
Get the socket address of the interface needed to reach a destination address.
int type(void) const
Get the type of a socket.
Definition socket.h:1093
void shutdown(void)
Shutdown the socket communication channel.
Definition socket.h:1140
unsigned segsize(unsigned size)
Set segment size and get mtu of a socket.
Definition socket.h:1102
int sendwait(unsigned size)
Set the size to wait before sending.
Definition socket.h:1053
int connectto(struct addrinfo *list)
Connect our socket to a remote host from an address list.
static char * hostname(const struct sockaddr *address, char *buffer, size_t size)
Lookup and return the host name associated with a socket address.
unsigned pending(void) const
Get the number of bytes of data in the socket receive buffer.
Definition socket.h:973
size_t peek(void *data, size_t number) const
Peek at data waiting in the socket receive buffer.
Socket(const char *address, const char *port, int family=0, int type=0, int protocol=0)
Create a bound socket.
int wait(timeout_t timeout=Timer::inf)
Socket i/o timer setting.
bool waitSending(timeout_t timeout=0) const
Test for output data sent.
int blocking(bool enable)
Set socket blocking I/O mode.
Definition socket.h:1000
int err(void) const
Get error code.
Definition socket.h:919
static int error(const socket_t socket)
Get socket error code of socket descriptor.
static socket_t create(const struct addrinfo *address, int type, int protocol)
Create a connected socket.
Socket(const struct addrinfo *address)
Create and connect a socket to an address from an address list.
int multicast(unsigned ttl=1)
Set multicast mode and multicast broadcast range.
Definition socket.h:1009
int getError(void) const
Get socket error code.
Definition socket.h:1026
static socket_t create(const Socket::address &address)
Create a connected socket for a service.
static int connectto(socket_t socket, struct addrinfo *list)
Connect socket descriptor to a remote host from an address list.
static int join(socket_t socket, const struct addrinfo *list, const int ifindex=0)
Join socket descriptor to multicast group.
int keepalive(bool enable)
Set socket for keepalive packets.
Definition socket.h:991
bool connected(void) const
Test if socket is connected.
static int sendwait(socket_t socket, unsigned size)
Set the size to wait before sending.
static unsigned store(struct sockaddr_internet *storage, const struct sockaddr *address)
Store an address into an internet address object.
static int bindto(socket_t socket, const struct sockaddr *address)
Bind the socket descriptor to a known interface.
int loopback(bool enable)
Set loopback to read multicast packets we broadcast.
Definition socket.h:1018
size_t readfrom(void *data, size_t number, struct sockaddr_storage *address=NULL)
Read data from the socket receive buffer.
static unsigned pending(socket_t socket)
Get the number of bytes pending in the receive buffer of a socket descriptor.
static bool equal(const struct sockaddr *address1, const struct sockaddr *address2)
Compare socket addresses.
static int error(void)
Return error code of last socket operation,.
static bool ccid(socket_t socket, uint8_t id)
Set congestion control id.
void cancel(void)
Cancel pending i/o by shutting down the socket.
Socket(const Socket &existing)
Create socket as duped handle of existing socket.
static socket_t create(int family, int type, int protocol)
Create a socket object unbound.
static ssize_t sendto(socket_t socket, const void *buffer, size_t size, int flags=0, const struct sockaddr *address=NULL)
Send data on socket.
static ssize_t replyto(socket_t socket, const void *buffer, size_t size, int flags, const struct sockaddr_storage *address)
Send reply on socket.
Definition socket.h:1507
static int disconnect(socket_t socket)
Disconnect a connected socket descriptor.
static int sendsize(socket_t socket, unsigned size)
Set the send size of a socket descriptor.
static int bindto(socket_t socket, const char *address, const char *service, int protocol=0)
Bind the socket descriptor to a known interface and service port.
static void release(struct addrinfo *list)
Release an address list directly.
int nodelay(void) const
Set nodelay option for tcp socket.
Definition socket.h:948
static in_port_t port(const struct sockaddr *address)
Get the service port of a socket.
size_t writeto(const void *data, size_t number, const struct sockaddr *address=NULL)
Write data to the socket send buffer.
static bool eq_subnet(const struct sockaddr *address1, const struct sockaddr *address2)
See if both addresses are in the same subnet.
static int family(const struct sockaddr_internet &address)
Get the address family of an internet socket address object.
Definition socket.h:1472
bool ccid(uint8_t id)
Set ccid of dccp socket.
Definition socket.h:1111
static bool is_null(const char *string)
Simple function to validate that a given IP address string is a "zero" address.
static socket_t acceptfrom(socket_t socket, struct sockaddr_storage *address=NULL)
Accept a socket connection from a remote host.
int priority(int scheduling)
Set packet priority, 0 to 6 unless privileged.
Definition socket.h:1133
static int ttl(socket_t socket, uint8_t time)
Set the time to live for the socket descriptor.
void release(void)
Shutdown and close the socket.
static bool is_numeric(const char *string)
Simple function to validate that a given IP address string is a numeric address.
Socket()
Create a socket object for use.
static int multicast(socket_t socket, unsigned ttl=1)
Set multicast mode and multicast broadcast range for socket descriptor.
bool wait(timeout_t timeout=0) const
Test for pending input data.
static unsigned segsize(socket_t socket, unsigned size=0)
Set segment size and get MTU.
static int drop(socket_t socket, const struct addrinfo *list, const int ifindex=0)
Drop socket descriptor from multicast group.
static int remote(socket_t socket, struct sockaddr_storage *address)
Get remote address to which the socket is connected.
size_t printf(const char *format,...)
Print formatted string to socket.
static void cancel(socket_t socket)
Cancel pending i/o by shutting down the socket.
static socklen_t query(socket_t socket, struct sockaddr_storage *address, const char *hostname, const char *service)
Lookup a host name and service address based on the addressing family and socket type of a socket des...
static int family(const struct sockaddr_storage &address)
Get the address family of a socket address object.
Definition socket.h:1463
static struct addrinfo * query(const char *host, const char *service, int type=SOCK_STREAM, int protocol=0)
Get an address list directly.
static void query(int family)
Set default socket family preference for query options when the socket type is otherwise not specifie...
static int keepalive(socket_t socket, bool enable)
Set socket for keepalive packets for socket descriptor.
A generic socket address class.
Definition socket.h:365
void set(const char *hostname, in_port_t service=0)
Set a socket address from host and service.
bool is_loopback() const
Test if the first socket address is ADDR_LOOPBACK: 127.0.0.1 or ::1.
Definition socket.h:651
void copy(const struct addrinfo *address)
Copy an existing addrinfo into our object.
struct addrinfo * operator*() const
Return the full socket address list by pointer reference.
Definition socket.h:581
static sockaddr_storage loopback(int family)
Get a ADDR_LOOPBACK socket address of the given family.
address(const char *host, const char *service, int type=SOCK_STREAM)
Construct a socket address list for a service.
address(const addrinfo *address)
Construct a socket address from an addrinfo structure.
Definition socket.h:433
static void setPort(struct sockaddr *address, in_port_t port)
Set the port of the socket address.
address(const address &reference)
Copy constructor.
void clear(void)
Clear current object.
int family(void) const
Get the family of the first member in a list of services.
bool operator!() const
Test if we have no address list.
Definition socket.h:621
static void setAny(struct sockaddr *sa)
Set the socket address to ADDR_ANY: 0.0.0.0 or ::0.
address(const in6_addr &address, in_port_t port=0)
Construct a socket address from an IPv6 address and a port number.
const struct sockaddr * get(void) const
Get the first socket address in our address list.
static void setLoopback(struct sockaddr *sa)
Set the socket address to ADDR_LOOPBACK: 127.0.0.1 or ::1 depending on the family of the pointed addr...
void add(sockaddr *address)
Add an individual socket address to our address list.
void setPort(in_port_t port)
Set the port of all addresses in the list.
void setAny(int family=0)
Clear the address list and set the first address to be the ADDR_ANY of the current family,...
~address()
Destroy address.
address & operator=(const address &rhs)
Assignment operator.
address(const sockaddr &address)
Construct a socket address from a sockaddr object.
Definition socket.h:426
void set(struct sockaddr *address)
Set an individual socket address for our address list.
size_t getLength(void) const
Get the address size of the first address.
Definition socket.h:531
address(int family, const char *address, int type=SOCK_STREAM, int protocol=0)
Construct a socket address.
address(const in_addr &address, in_port_t port=0)
Construct a socket address from an IPv4 address and a port number.
struct addrinfo * getList(void) const
Get the full socket address list from the object.
Definition socket.h:565
bool insert(const struct sockaddr *address)
Insert an individual socket address to our address list only if unique.
static struct sockaddr * dup(struct sockaddr *address)
Duplicate a socket address.
address(const char *hostname, in_port_t port=0)
Construct a socket address from host and service.
void add(const char *hostname, const char *service=NULL, int type=SOCK_STREAM)
Append additional host addresses to our list.
void set(int family, const char *address, int type=SOCK_STREAM, int protocol=0)
Set an entry for host binding.
unsigned insert(const struct addrinfo *address)
Insert unique members from another socket address list to ours.
address(int family, const char *hostname, const char *service=NULL)
Construct a socket address for an existing socket.
void set(const char *hostname, const char *service=NULL, int type=SOCK_STREAM)
Set the host addresses to form a new list.
const struct sockaddr * get(int family) const
Get the first socket address of specified family from our list.
size_t print(char *dst, size_t dst_sz, bool port=false, bool force_brackets=false) const
Print the first socket address as a human-readable string to the provided buffer and returns the prin...
Definition socket.h:597
static bool isLoopback(const struct sockaddr *address)
Test if the socket address is ADDR_LOOPBACK: 127.0.0.1 or ::1.
static size_t getLength(const struct sockaddr *address)
Returns the size of the socket address according to the family.
Definition socket.h:756
address withPort(in_port_t port) const
Returns a copy of this address list with the specified port set.
static size_t print(const struct sockaddr *src, char *dst, size_t dst_sz, bool port=false, bool ipv6_brackets=false)
Print socket address as a human-readable string to the provided buffer and returns the printed string...
bool operator==(const address &other) const
Compare two address lists.
void setLoopback(int family=0)
Clear the address list and set the first address to be the ADDR_LOOPBACK of the current family,...
static bool isAny(const struct sockaddr *address)
Test if the socket address is ADDR_ANY: 0.0.0.0 or ::0.
in_port_t getPort(void) const
Get the port of the first address .
Definition socket.h:539
unsigned remove(const struct addrinfo *address)
Remove members from another socket address list from ours.
address()
Construct an empty address.
static in_port_t getPort(const struct sockaddr *address)
Returns the port of the socket address.
Definition socket.h:764
struct sockaddr * find(const struct sockaddr *addr) const
Find a specific socket address in our address list.
static struct sockaddr_in6 * ipv6(struct sockaddr *address)
Convert address object into ipv6 address.
bool is_any() const
Test if the first socket address is ADDR_ANY: 0.0.0.0 or ::0.
Definition socket.h:630
bool remove(const struct sockaddr *address)
Remove an individual socket address from our address list.
static sockaddr_storage any(int family)
Get a ADDR_ANY socket address of the given family.
static struct sockaddr_in * ipv4(struct sockaddr *address)
Convert address object into ipv4 address.
A bound socket used to listen for inbound socket connections.
Definition socket.h:1821
socket_t getsocket(void) const
Get the socket descriptor of the listener.
Definition socket.h:1885
socket_t accept(struct sockaddr_storage *address=NULL) const
Accept a socket connection.
socket_t operator*() const
Get the socket descriptor of the listener by pointer reference.
Definition socket.h:1877
static socket_t create(const char *address, const char *service, unsigned backlog=5, int family=0, int type=0, int protocol=0)
Create a listen socket directly.
bool wait(timeout_t timeout=Timer::inf) const
Wait for a pending connection.
Definition socket.h:1861
ListenSocket(const char *address, const char *service, unsigned backlog=5, int family=0, int type=0, int protocol=0)
Create and bind a listener socket.
A generic tcp server class.
Definition socket.h:1901
TCPServer(const char *address, const char *service, unsigned backlog=5)
Create and bind a tcp server.
Helper class for linked_pointer template.
Definition socket.h:1921
socket_t _getaddrsock(const struct addrinfo *addrinfo) const
Helper function for linked_pointer<struct sockaddr>.
const struct addrinfo * _nextaddrinfo(const struct addrinfo *addrinfo) const
Helper function for linked_pointer<struct sockaddr>.
const struct sockaddr * _getaddrinfo(const struct addrinfo *addrinfo) const
Helper function for linked_pointer<struct sockaddr>.
const struct sockaddr * operator->() const
Return member from typed object our pointer references.
Definition socket.h:2057
socket_t operator()(void) const
Get socket as expression operator.
Definition socket.h:2006
const struct sockaddr * operator*() const
Return the full socket address list by pointer reference.
Definition socket.h:1981
void set(const struct addrinfo *list)
Assign our pointer from an address list.
Definition socket.h:2040
void set(Socket::address &list)
Assign our pointer from an address list.
Definition socket.h:2048
linked_pointer & operator=(const struct addrinfo *list)
Assign our pointer from an address list.
Definition socket.h:2022
bool operator!() const
Test if we have no address list.
Definition socket.h:2065
linked_pointer & operator=(Socket::address &list)
Assign our pointer from an address list.
Definition socket.h:2031
A copy-on-write string class that operates by reference count.
Definition string.h:79
Timer class to use when scheduling realtime events.
Definition timers.h:51
A common string class and character string support functions.