2 #ifndef UVCC_NETSTRUCT__HPP 3 #define UVCC_NETSTRUCT__HPP 13 #include <sys/socket.h> 14 #include <netinet/in.h> 35 inline int init(::sockaddr_in &_sin)
37 std::memset(&_sin, 0,
sizeof(_sin));
38 _sin.sin_family = AF_INET;
47 inline int init(::sockaddr_in &_sin,
const char *_ip,
const char *_port =
nullptr)
49 int pnum = _port ? std::atoi(_port) : 0;
50 return ::uv_ip4_addr(_ip, pnum, &_sin);
60 inline int init(::sockaddr_in6 &_sin6)
62 std::memset(&_sin6, 0,
sizeof(_sin6));
63 _sin6.sin6_family = AF_INET6;
72 inline int init(::sockaddr_in6 &_sin6,
const char *_ip,
const char *_port =
nullptr)
74 int pnum = _port ? std::atoi(_port) : 0;
75 return ::uv_ip6_addr(_ip, pnum, &_sin6);
84 inline int init(::sockaddr_storage &_ss,
decltype(::sockaddr::sa_family) _family = AF_UNSPEC)
86 std::memset(&_ss, 0,
sizeof(_ss));
87 _ss.ss_family = _family;
91 inline int init(::sockaddr_storage &_ss,
const ::sockaddr &_sa)
93 std::memset(&_ss, 0,
sizeof(_ss));
94 switch (_sa.sa_family)
97 reinterpret_cast< ::sockaddr_in& >(_ss) =
reinterpret_cast<
const ::sockaddr_in& >(_sa);
100 reinterpret_cast< ::sockaddr_in6& >(_ss) =
reinterpret_cast<
const ::sockaddr_in6& >(_sa);
103 return UV_EAFNOSUPPORT;
108 inline int init(::sockaddr_storage &_ss,
const char *_ip,
const char *_port =
nullptr)
110 std::memset(&_ss, 0,
sizeof(_ss));
112 init(reinterpret_cast< ::sockaddr_in& >(_ss)
, _ip
, _port
) == 0
114 init(reinterpret_cast< ::sockaddr_in6& >(_ss)
, _ip
, _port
) == 0
158 inline int init(::addrinfo &_ai,
159 decltype(::addrinfo::ai_family) _family = AF_UNSPEC,
160 decltype(::addrinfo::ai_socktype) _socktype = 0,
161 decltype(::addrinfo::ai_flags) _flags = AI_ADDRCONFIG
164 std::memset(&_ai, 0,
sizeof(_ai));
165 _ai.ai_family = _family;
166 _ai.ai_socktype = _socktype;
167 _ai.ai_flags = _flags;
Namespace for all uvcc definitions.
int init(::addrinfo &_ai, decltype(::addrinfo::ai_family) _family=AF_UNSPEC, decltype(::addrinfo::ai_socktype) _socktype=0, decltype(::addrinfo::ai_flags) _flags=AI_ADDRCONFIG)
Initialize an addrinfo structure for to be used as a hints argument in uv::getaddrinfo request...
int init(::sockaddr_in &_sin, const char *_ip, const char *_port=nullptr)
Initialize a sockaddr_in structure from strings containing an IPv4 address and (optionally) a port...
int init(::sockaddr_in6 &_sin6, const char *_ip, const char *_port=nullptr)
Initialize a sockaddr_in6 structure from strings containing an IPv6 address and (optionally) a port...
int init(::sockaddr_in6 &_sin6)
Initialize a sockaddr_in6 structure.
int init(::sockaddr_in &_sin)
Initialize a sockaddr_in structure.