13 #if defined(INET6) && (defined(LOOKUP_ORDER_HACK_INET) || defined(LOOKUP_ORDER_HACK_INET6)) 14 #define LOOKUP_ORDERS (sizeof(lookup_order_table) / sizeof(lookup_order_table[0])) 15 static const int lookup_order_table[] = {
16 #if defined(LOOKUP_ORDER_HACK_INET) 18 #elif defined(LOOKUP_ORDER_HACK_INET6) 26 ruby_getaddrinfo(
const char *nodename,
const char *servname,
36 for (i = 0; i < LOOKUP_ORDERS; i++) {
37 af = lookup_order_table[i];
39 tmp_hints.ai_family = af;
40 error =
getaddrinfo(nodename, servname, &tmp_hints, res);
53 #define getaddrinfo(node,serv,hints,res) ruby_getaddrinfo((node),(serv),(hints),(res)) 58 ruby_getaddrinfo__aix(
const char *nodename,
const char *servname,
61 int error =
getaddrinfo(nodename, servname, hints, res);
74 #define getaddrinfo(node,serv,hints,res) ruby_getaddrinfo__aix((node),(serv),(hints),(res)) 76 ruby_getnameinfo__aix(
const struct sockaddr *sa,
size_t salen,
77 char *host,
size_t hostlen,
78 char *serv,
size_t servlen,
int flags)
80 struct sockaddr_in6 *sa6;
83 if (sa->sa_family == AF_INET6) {
84 sa6 = (
struct sockaddr_in6 *)sa;
85 a6 = sa6->sin6_addr.u6_addr.u6_addr32;
87 if (a6[0] == 0 && a6[1] == 0 && a6[2] == 0 && a6[3] == 0) {
88 strncpy(host,
"::", hostlen);
89 snprintf(serv, servlen,
"%d", sa6->sin6_port);
93 return getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
96 #define getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \ 97 ruby_getnameinfo__aix((sa), (salen), (host), (hostlen), (serv), (servlen), (flags)) 102 #if defined(__APPLE__) 104 ruby_getaddrinfo__darwin(
const char *nodename,
const char *servname,
108 const char *tmp_servname;
112 tmp_servname = servname;
114 if (nodename && servname) {
117 #ifdef AI_NUMERICSERV 123 error =
getaddrinfo(nodename, tmp_servname, &tmp_hints, res);
145 #define getaddrinfo(node,serv,hints,res) ruby_getaddrinfo__darwin((node),(serv),(hints),(res)) 148 #ifndef GETADDRINFO_EMU 157 #ifdef HAVE_INET_PTON 159 parse_numeric_port(
const char *
service,
int *portp)
168 if (strspn(service,
"0123456789") !=
strlen(service))
198 return (
void *)(
VALUE)ret;
207 #ifdef HAVE_INET_PTON 208 # if defined __MINGW64__ 209 # define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d) 214 if (node && parse_numeric_port(service, &port)) {
215 static const struct {
225 int hint_socktype = hints ? hints->
ai_socktype : 0;
226 int hint_protocol = hints ? hints->
ai_protocol : 0;
230 if ((hint_family ==
PF_UNSPEC || hint_family == PF_INET6) &&
231 strspn(node,
"0123456789abcdefABCDEF.:") ==
strlen(node) &&
235 if ((hint_socktype == 0 || hint_socktype ==
list[i].socktype) &&
236 (hint_protocol == 0 ||
list[i].protocol == 0 || hint_protocol ==
list[i].protocol)) {
238 struct sockaddr_in6 *sa =
xmalloc(
sizeof(
struct sockaddr_in6));
240 memcpy(&sa->sin6_addr, ipv6addr,
sizeof(ipv6addr));
241 sa->sin6_port = htons(port);
245 ai0->
ai_addrlen =
sizeof(
struct sockaddr_in6);
246 ai0->
ai_addr = (
struct sockaddr *)sa;
256 strspn(node,
"0123456789.") ==
strlen(node) &&
260 if ((hint_socktype == 0 || hint_socktype ==
list[i].socktype) &&
261 (hint_protocol == 0 ||
list[i].protocol == 0 || hint_protocol ==
list[i].protocol)) {
263 struct sockaddr_in *sa =
xmalloc(
sizeof(
struct sockaddr_in));
265 memcpy(&sa->sin_addr, ipv4addr,
sizeof(ipv4addr));
266 sa->sin_port = htons(port);
271 ai0->
ai_addr = (
struct sockaddr *)sa;
294 int allocated_by_malloc = 0;
298 allocated_by_malloc = 1;
300 #ifdef GETADDRINFO_EMU 339 #ifndef GETADDRINFO_EMU 342 const struct sockaddr *
sa;
364 char *host,
size_t hostlen,
365 char *serv,
size_t servlen,
int flags)
367 #ifdef GETADDRINFO_EMU 368 return getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
407 struct sockaddr_in sin;
410 sin.sin_addr.s_addr = host;
411 make_ipaddr0((
struct sockaddr*)&sin,
sizeof(sin), buf, buflen);
419 if (!p || *p ==
'\0')
423 if (ep && *ep ==
'\0')
429 #define str_equal(ptr, len, name) \ 430 ((ptr)[0] == name[0] && \ 431 rb_strlen_lit(name) == (len) && memcmp(ptr, name, len) == 0) 432 #define SafeStringValueCStr(v) do {\ 434 rb_check_safe_obj(v);\ 456 if (!len ||
str_equal(name, len,
"<any>")) {
460 else if (
str_equal(name, len,
"<broadcast>")) {
464 else if (len >= hbuflen) {
484 #ifdef AI_NUMERICSERV 495 if (len >= pbuflen) {
512 int additional_flags = 0;
514 hostp =
host_str(host, hbuf,
sizeof(hbuf), &additional_flags);
515 portp =
port_str(port, pbuf,
sizeof(pbuf), &additional_flags);
520 hints->
ai_flags |= additional_flags;
524 if (hostp && hostp[
strlen(hostp)-1] ==
'\n') {
536 struct sockaddr sa = { 0 };
539 if (fd < 0 || getsockname(fd, &sa, &sa_len) != 0 ||
540 (size_t)sa_len <
offsetof(
struct sockaddr, sa_family) +
sizeof(sa.sa_family)) {
561 VALUE family, port, addr1, addr2;
564 char hbuf[1024], pbuf[1024];
572 sprintf(pbuf,
"unknown:%d", sockaddr->sa_family);
601 rsock_unixpath_str(
struct sockaddr_un *sockaddr,
socklen_t len)
604 s = sockaddr->sun_path;
605 e = (
char *)sockaddr + len;
606 while (s < e && *(e-1) ==
'\0')
615 rsock_unixaddr(
struct sockaddr_un *sockaddr,
socklen_t len)
618 rsock_unixpath_str(sockaddr, len));
622 rsock_unix_sockaddr_len(
VALUE path)
638 return (
socklen_t)
sizeof(
struct sockaddr_un);
677 if (h->h_aliases !=
NULL) {
678 for (pch = h->h_aliases; *pch; pch++) {
688 for (ai = addr; ai; ai = ai->
ai_next) {
689 rb_ary_push(ary, (*ipaddr)(ai->ai_addr, ai->ai_addrlen));
735 #define addrinfo_free RUBY_TYPED_DEFAULT_FREE 754 #define IS_ADDRINFO(obj) rb_typeddata_is_kind_of((obj), &addrinfo_type) 784 int pfamily,
int socktype,
int protocol,
801 int family,
int socktype,
int protocol,
809 init_addrinfo(rai, addr, len, family, socktype, protocol, canonname, inspectname);
824 if (!
NIL_P(socktype)) {
827 if (!
NIL_P(protocol)) {
859 canonname, inspectname);
874 sizeof(hbuf), pbuf,
sizeof(pbuf),
890 if (
NIL_P(inspectname))
897 if (
NIL_P(inspectname))
902 if (!
NIL_P(inspectname)) {
930 canonname, inspectname);
959 canonname, inspectname);
973 struct sockaddr_un un;
978 if (
sizeof(un.sun_path) < (
size_t)
RSTRING_LEN(path))
980 "too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
983 INIT_SOCKADDR_UN(&un,
sizeof(
struct sockaddr_un));
986 len = rsock_unix_sockaddr_len(path);
1042 VALUE sockaddr_arg, sockaddr_ary, pfamily, socktype, protocol;
1043 int i_pfamily, i_socktype, i_protocol;
1044 struct sockaddr *sockaddr_ptr;
1052 rb_scan_args(argc, argv,
"13", &sockaddr_arg, &pfamily, &socktype, &protocol);
1059 if (!
NIL_P(sockaddr_ary)) {
1077 if (!
NIL_P(nodename))
1081 #ifdef AI_NUMERICSERV 1092 #ifdef HAVE_SYS_UN_H 1097 init_unix_addrinfo(rai, path, SOCK_STREAM);
1108 sockaddr_ptr = (
struct sockaddr *)
RSTRING_PTR(sockaddr_arg);
1111 i_pfamily, i_socktype, i_protocol,
1112 canonname, inspectname);
1121 if ((
socklen_t)((
char*)&addr->sa_family +
sizeof(addr->sa_family) - (
char*)addr) <= len)
1122 return addr->sa_family;
1149 else if ((
long)socklen < ((
char*)&sockaddr->
addr.sa_family +
sizeof(sockaddr->
addr.sa_family)) - (
char*)sockaddr)
1152 switch (sockaddr->addr.sa_family) {
1161 struct sockaddr_in *addr;
1163 addr = &sockaddr->in;
1164 if ((
socklen_t)(((
char*)&addr->sin_addr)-(
char*)addr+0+1) <= socklen)
1165 rb_str_catf(ret,
"%d", ((
unsigned char*)&addr->sin_addr)[0]);
1168 if ((
socklen_t)(((
char*)&addr->sin_addr)-(
char*)addr+1+1) <= socklen)
1169 rb_str_catf(ret,
".%d", ((
unsigned char*)&addr->sin_addr)[1]);
1172 if ((
socklen_t)(((
char*)&addr->sin_addr)-(
char*)addr+2+1) <= socklen)
1173 rb_str_catf(ret,
".%d", ((
unsigned char*)&addr->sin_addr)[2]);
1176 if ((
socklen_t)(((
char*)&addr->sin_addr)-(
char*)addr+3+1) <= socklen)
1177 rb_str_catf(ret,
".%d", ((
unsigned char*)&addr->sin_addr)[3]);
1181 if ((
socklen_t)(((
char*)&addr->sin_port)-(
char*)addr+(
int)
sizeof(addr->sin_port)) < socklen) {
1182 port = ntohs(addr->sin_port);
1189 if ((
socklen_t)
sizeof(
struct sockaddr_in) != socklen)
1190 rb_str_catf(ret,
" (%d bytes for %d bytes sockaddr_in)",
1192 (
int)
sizeof(
struct sockaddr_in));
1199 struct sockaddr_in6 *addr;
1203 if (socklen < (
socklen_t)
sizeof(
struct sockaddr_in6)) {
1204 rb_str_catf(ret,
"too-short-AF_INET6-sockaddr %d bytes", (
int)socklen);
1207 addr = &sockaddr->in6;
1218 if (addr->sin6_port == 0) {
1222 port = ntohs(addr->sin6_port);
1225 if ((
socklen_t)
sizeof(
struct sockaddr_in6) < socklen)
1226 rb_str_catf(ret,
"(sockaddr %d bytes too long)", (
int)(socklen -
sizeof(
struct sockaddr_in6)));
1232 #ifdef HAVE_SYS_UN_H 1235 struct sockaddr_un *addr = &sockaddr->un;
1238 e = (
char*)addr + socklen;
1239 while (s < e && *(e-1) ==
'\0')
1246 int printable_only = 1;
1252 if (printable_only) {
1267 #if defined(AF_PACKET) && defined(__linux__) 1271 struct sockaddr_ll *addr;
1272 const char *sep =
"[";
1273 #define CATSEP do { rb_str_cat2(ret, sep); sep = " "; } while (0); 1275 addr = (
struct sockaddr_ll *)sockaddr;
1279 if (
offsetof(
struct sockaddr_ll, sll_protocol) +
sizeof(addr->sll_protocol) <= (
size_t)socklen) {
1281 rb_str_catf(ret,
"protocol=%d", ntohs(addr->sll_protocol));
1283 if (
offsetof(
struct sockaddr_ll, sll_ifindex) +
sizeof(addr->sll_ifindex) <= (
size_t)socklen) {
1286 if (if_indextoname(addr->sll_ifindex, buf) ==
NULL)
1287 rb_str_catf(ret,
"ifindex=%d", addr->sll_ifindex);
1291 if (
offsetof(
struct sockaddr_ll, sll_hatype) +
sizeof(addr->sll_hatype) <= (
size_t)socklen) {
1295 if (
offsetof(
struct sockaddr_ll, sll_pkttype) +
sizeof(addr->sll_pkttype) <= (
size_t)socklen) {
1297 if (addr->sll_pkttype == PACKET_HOST)
1299 else if (addr->sll_pkttype == PACKET_BROADCAST)
1301 else if (addr->sll_pkttype == PACKET_MULTICAST)
1303 else if (addr->sll_pkttype == PACKET_OTHERHOST)
1305 else if (addr->sll_pkttype == PACKET_OUTGOING)
1308 rb_str_catf(ret,
"pkttype=%d", addr->sll_pkttype);
1310 if (socklen != (
socklen_t)(
offsetof(
struct sockaddr_ll, sll_addr) + addr->sll_halen)) {
1312 if (
offsetof(
struct sockaddr_ll, sll_halen) +
sizeof(addr->sll_halen) <= (
size_t)socklen) {
1316 if (
offsetof(
struct sockaddr_ll, sll_addr) < (
size_t)socklen) {
1320 len = addr->sll_halen;
1321 if ((
size_t)socklen <
offsetof(
struct sockaddr_ll, sll_addr) + len)
1322 len = socklen -
offsetof(
struct sockaddr_ll, sll_addr);
1323 for (i = 0; i <
len; i++) {
1329 if (socklen < (
socklen_t)(
offsetof(
struct sockaddr_ll, sll_halen) +
sizeof(addr->sll_halen)) ||
1330 (
socklen_t)(
offsetof(
struct sockaddr_ll, sll_addr) + addr->sll_halen) != socklen) {
1332 rb_str_catf(ret,
"(%d bytes for %d bytes sockaddr_ll)",
1333 (
int)socklen, (
int)
sizeof(
struct sockaddr_ll));
1343 #if defined(AF_LINK) && defined(HAVE_TYPE_STRUCT_SOCKADDR_DL) 1358 struct sockaddr_dl *addr = &sockaddr->dl;
1359 char *np =
NULL, *ap =
NULL, *endp;
1360 int nlen = 0, alen = 0;
1362 const char *sep =
"[";
1363 #define CATSEP do { rb_str_cat2(ret, sep); sep = " "; } while (0); 1367 endp = ((
char *)addr) + socklen;
1369 if (
offsetof(
struct sockaddr_dl, sdl_data) < socklen) {
1370 np = addr->sdl_data;
1371 nlen = addr->sdl_nlen;
1372 if (endp - np < nlen)
1373 nlen = (int)(endp - np);
1375 off = addr->sdl_nlen;
1377 if (
offsetof(
struct sockaddr_dl, sdl_data) + off < socklen) {
1378 ap = addr->sdl_data + off;
1379 alen = addr->sdl_alen;
1380 if (endp - ap < alen)
1381 alen = (int)(endp - ap);
1390 if (ap && 0 < alen) {
1392 for (i = 0; i < alen; i++)
1393 rb_str_catf(ret,
"%s%02x", i == 0 ?
"" :
":", (
unsigned char)ap[i]);
1396 if (socklen < (
socklen_t)(
offsetof(
struct sockaddr_dl, sdl_nlen) +
sizeof(addr->sdl_nlen)) ||
1397 socklen < (
socklen_t)(
offsetof(
struct sockaddr_dl, sdl_alen) +
sizeof(addr->sdl_alen)) ||
1398 socklen < (
socklen_t)(
offsetof(
struct sockaddr_dl, sdl_slen) +
sizeof(addr->sdl_slen)) ||
1401 socklen < (
socklen_t)(
offsetof(
struct sockaddr_dl, sdl_data) + addr->sdl_nlen + addr->sdl_alen + addr->sdl_slen)) {
1403 rb_str_catf(ret,
"(%d bytes for %d bytes sockaddr_dl)",
1404 (
int)socklen, (
int)
sizeof(
struct sockaddr_dl));
1417 rb_str_catf(ret,
"unknown address family %d", sockaddr->addr.sa_family);
1459 internet_p = internet_p || rai->
pfamily == PF_INET6;
1461 if (internet_p && rai->
socktype == SOCK_STREAM &&
1465 else if (internet_p && rai->
socktype == SOCK_DGRAM &&
1484 goto unknown_protocol;
1529 VALUE sockaddr, afamily, pfamily, socktype, protocol, canonname, inspectname;
1568 switch(afamily_int) {
1569 #ifdef HAVE_SYS_UN_H 1572 struct sockaddr_un *su = &rai->
addr.un;
1576 while (s < e && *(e-1) ==
'\0')
1598 return rb_ary_new3(7, afamily, sockaddr, pfamily, socktype, protocol, canonname, inspectname);
1606 VALUE canonname, inspectname;
1607 int afamily, pfamily, socktype, protocol;
1668 #ifdef HAVE_SYS_UN_H 1671 struct sockaddr_un uaddr;
1672 INIT_SOCKADDR_UN(&uaddr,
sizeof(
struct sockaddr_un));
1675 if (
sizeof(uaddr.sun_path) < (
size_t)
RSTRING_LEN(v))
1677 "too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
1681 memcpy(&ss, &uaddr, len);
1691 #ifdef AI_NUMERICSERV 1707 pfamily, socktype, protocol,
1708 canonname, inspectname);
1924 char hbuf[1024], pbuf[1024];
2025 port = ntohs(rai->
addr.
in.sin_port);
2032 port = ntohs(rai->
addr.in6.sin6_port);
2048 if (family != AF_INET)
return 0;
2049 *addrp = ntohl(rai->
addr.
in.sin_addr.s_addr);
2062 if ((a & 0xff000000) == 0x0a000000 ||
2063 (a & 0xfff00000) == 0xac100000 ||
2064 (a & 0xffff0000) == 0xc0a80000)
2078 if ((a & 0xff000000) == 0x7f000000)
2092 if ((a & 0xf0000000) == 0xe0000000)
2099 static struct in6_addr *
2100 extract_in6_addr(
VALUE self)
2104 if (family != AF_INET6)
return NULL;
2105 return &rai->
addr.in6.sin6_addr;
2113 addrinfo_ipv6_unspecified_p(
VALUE self)
2115 struct in6_addr *addr = extract_in6_addr(
self);
2116 if (addr && IN6_IS_ADDR_UNSPECIFIED(addr))
return Qtrue;
2125 addrinfo_ipv6_loopback_p(
VALUE self)
2127 struct in6_addr *addr = extract_in6_addr(
self);
2128 if (addr && IN6_IS_ADDR_LOOPBACK(addr))
return Qtrue;
2137 addrinfo_ipv6_multicast_p(
VALUE self)
2139 struct in6_addr *addr = extract_in6_addr(
self);
2140 if (addr && IN6_IS_ADDR_MULTICAST(addr))
return Qtrue;
2149 addrinfo_ipv6_linklocal_p(
VALUE self)
2151 struct in6_addr *addr = extract_in6_addr(
self);
2152 if (addr && IN6_IS_ADDR_LINKLOCAL(addr))
return Qtrue;
2161 addrinfo_ipv6_sitelocal_p(
VALUE self)
2163 struct in6_addr *addr = extract_in6_addr(
self);
2164 if (addr && IN6_IS_ADDR_SITELOCAL(addr))
return Qtrue;
2173 addrinfo_ipv6_unique_local_p(
VALUE self)
2175 struct in6_addr *addr = extract_in6_addr(
self);
2185 addrinfo_ipv6_v4mapped_p(
VALUE self)
2187 struct in6_addr *addr = extract_in6_addr(
self);
2188 if (addr && IN6_IS_ADDR_V4MAPPED(addr))
return Qtrue;
2197 addrinfo_ipv6_v4compat_p(
VALUE self)
2199 struct in6_addr *addr = extract_in6_addr(
self);
2200 if (addr && IN6_IS_ADDR_V4COMPAT(addr))
return Qtrue;
2209 addrinfo_ipv6_mc_nodelocal_p(
VALUE self)
2211 struct in6_addr *addr = extract_in6_addr(
self);
2212 if (addr && IN6_IS_ADDR_MC_NODELOCAL(addr))
return Qtrue;
2221 addrinfo_ipv6_mc_linklocal_p(
VALUE self)
2223 struct in6_addr *addr = extract_in6_addr(
self);
2224 if (addr && IN6_IS_ADDR_MC_LINKLOCAL(addr))
return Qtrue;
2233 addrinfo_ipv6_mc_sitelocal_p(
VALUE self)
2235 struct in6_addr *addr = extract_in6_addr(
self);
2236 if (addr && IN6_IS_ADDR_MC_SITELOCAL(addr))
return Qtrue;
2245 addrinfo_ipv6_mc_orglocal_p(
VALUE self)
2247 struct in6_addr *addr = extract_in6_addr(
self);
2248 if (addr && IN6_IS_ADDR_MC_ORGLOCAL(addr))
return Qtrue;
2257 addrinfo_ipv6_mc_global_p(
VALUE self)
2259 struct in6_addr *addr = extract_in6_addr(
self);
2260 if (addr && IN6_IS_ADDR_MC_GLOBAL(addr))
return Qtrue;
2275 addrinfo_ipv6_to_ipv4(
VALUE self)
2278 struct in6_addr *addr;
2280 if (family != AF_INET6)
return Qnil;
2281 addr = &rai->
addr.in6.sin6_addr;
2282 if (IN6_IS_ADDR_V4MAPPED(addr) || IN6_IS_ADDR_V4COMPAT(addr)) {
2283 struct sockaddr_in sin4;
2285 memcpy(&sin4.sin_addr, (
char*)addr +
sizeof(*addr) -
sizeof(sin4.sin_addr),
sizeof(sin4.sin_addr));
2297 #ifdef HAVE_SYS_UN_H 2307 addrinfo_unix_path(
VALUE self)
2311 struct sockaddr_un *addr;
2314 if (family != AF_UNIX)
2317 addr = &rai->
addr.un;
2323 (
size_t)rai->
sockaddr_len, (
size_t)(s - (
char *)addr));
2324 if (addr->sun_path +
sizeof(addr->sun_path) < e)
2326 "too long AF_UNIX path (%"PRIuSIZE
" bytes given but %"PRIuSIZE
" bytes max)",
2327 (
size_t)(e - addr->sun_path),
sizeof(addr->sun_path));
2328 while (s < e && *(e-1) ==
'\0')
2382 rb_scan_args(argc, argv,
"24", &node, &service, &family, &socktype, &protocol, &flags);
2440 #ifdef HAVE_SYS_UN_H 2457 VALUE path, vsocktype, addr;
2463 if (
NIL_P(vsocktype))
2464 socktype = SOCK_STREAM;
2470 init_unix_addrinfo(rai, path, socktype);
2527 ret = getsockopt(fd, SOL_SOCKET, SO_TYPE, (
void*)&socktype, &optlen);
2577 #ifdef HAVE_SYS_UN_H 2618 #ifdef HAVE_SYS_UN_H
RUBY_EXTERN VALUE rb_cData
VALUE rb_ary_entry(VALUE ary, long offset)
#define SafeStringValueCStr(v)
VALUE rb_str_equal(VALUE str1, VALUE str2)
static int str_is_number(const char *)
size_t strlen(const char *)
VALUE rsock_inspect_sockaddr(struct sockaddr *sockaddr_arg, socklen_t socklen, VALUE ret)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static rb_addrinfo_t * check_addrinfo(VALUE self)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE addrinfo_ipv6_p(VALUE self)
VALUE rsock_make_ipaddr(struct sockaddr *addr, socklen_t addrlen)
#define TypedData_Wrap_Struct(klass, data_type, sval)
int rsock_socktype_arg(VALUE type)
static VALUE addrinfo_list_new(VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags)
const struct sockaddr * sa
VALUE rb_ary_push(VALUE ary, VALUE item)
static void * nogvl_getaddrinfo(void *arg)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
static VALUE addrinfo_ipv4_loopback_p(VALUE self)
void rb_raise(VALUE exc, const char *fmt,...)
ID rsock_intern_ipproto(int val)
#define IN6_IS_ADDR_UNIQUE_LOCAL(a)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
static VALUE addrinfo_protocol(VALUE self)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static void make_inetaddr(unsigned int host, char *buf, size_t buflen)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
VALUE rb_check_sockaddr_string_type(VALUE val)
void rb_gc_mark(VALUE ptr)
static VALUE addrinfo_ipv4_p(VALUE self)
VALUE rb_tainted_str_new_cstr(const char *)
static size_t addrinfo_memsize(const void *ptr)
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
const struct addrinfo * hints
#define GetOpenFile(obj, fp)
void rsock_init_addrinfo(void)
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
const char * rb_obj_classname(VALUE)
static VALUE addrinfo_ipv4_multicast_p(VALUE self)
void rb_freeaddrinfo(struct rb_addrinfo *ai)
static VALUE addrinfo_to_sockaddr(VALUE self)
VALUE rsock_make_hostent(VALUE host, struct rb_addrinfo *addr, VALUE(*ipaddr)(struct sockaddr *, socklen_t))
#define RB_TYPE_P(obj, type)
VALUE rsock_addrinfo_new(struct sockaddr *addr, socklen_t len, int family, int socktype, int protocol, VALUE canonname, VALUE inspectname)
#define MEMZERO(p, type, n)
VALUE rsock_sockaddr_string_value_with_addrinfo(volatile VALUE *v, VALUE *rai_ret)
struct rb_addrinfo * rsock_addrinfo(VALUE host, VALUE port, int family, int socktype, int flags)
int rsock_ipproto_to_int(const char *str, long len, int *valp)
int rsock_family_arg(VALUE domain)
VALUE rb_str_cat2(VALUE, const char *)
static int ai_get_afamily(rb_addrinfo_t *rai)
VALUE rb_str_buf_cat2(VALUE, const char *)
static VALUE addrinfo_initialize(int argc, VALUE *argv, VALUE self)
#define STRTOUL(str, endptr, base)
static VALUE addrinfo_ip_unpack(VALUE self)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE addrinfo_getnameinfo(int argc, VALUE *argv, VALUE self)
static char * host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr)
struct rb_addrinfo * rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack)
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define offsetof(p_type, field)
static const rb_data_type_t addrinfo_type
static struct rb_addrinfo * call_getaddrinfo(VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags, int socktype_hack)
int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
ID rsock_intern_protocol_family(int val)
#define MEMCPY(p1, p2, type, n)
int rsock_family_to_int(const char *str, long len, int *valp)
static VALUE addrinfo_s_udp(VALUE self, VALUE host, VALUE port)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
static int get_afamily(struct sockaddr *addr, socklen_t len)
static VALUE addrinfo_unix_p(VALUE self)
VALUE rsock_freeaddrinfo(VALUE arg)
static void init_addrinfo_getaddrinfo(rb_addrinfo_t *rai, VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags, VALUE inspectnode, VALUE inspectservice)
int rsock_socktype_to_int(const char *str, long len, int *valp)
char * rsock_sockaddr_string_value_ptr(volatile VALUE *v)
VALUE rb_sprintf(const char *format,...)
static void * nogvl_getnameinfo(void *arg)
static VALUE addrinfo_firstonly_new(VALUE node, VALUE service, VALUE family, VALUE socktype, VALUE protocol, VALUE flags)
static VALUE addrinfo_s_getaddrinfo(int argc, VALUE *argv, VALUE self)
void freeaddrinfo(struct addrinfo *ai)
VALUE rsock_fd_socket_addrinfo(int fd, struct sockaddr *addr, socklen_t len)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE addrinfo_mload(VALUE self, VALUE ary)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
static rb_addrinfo_t * alloc_addrinfo(void)
static VALUE addrinfo_pfamily(VALUE self)
static VALUE addrinfo_ip_address(VALUE self)
ID rsock_intern_family(int val)
static VALUE addrinfo_s_ip(VALUE self, VALUE host)
static char * port_str(VALUE port, char *pbuf, size_t pbuflen, int *flags_ptr)
#define INIT_SOCKADDR_IN6(addr, len)
RUBY_EXTERN VALUE rb_cInteger
const char * rb_id2name(ID)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
VALUE rb_str_new_cstr(const char *)
ID rsock_intern_socktype(int val)
static VALUE addrinfo_ip_p(VALUE self)
void rb_sys_fail(const char *mesg)
static VALUE addrinfo_s_allocate(VALUE klass)
static void init_addrinfo(rb_addrinfo_t *rai, struct sockaddr *sa, socklen_t len, int pfamily, int socktype, int protocol, VALUE canonname, VALUE inspectname)
static int inet_pton(int af, const char *hostname, void *pton)
static void make_ipaddr0(struct sockaddr *addr, socklen_t addrlen, char *buf, size_t buflen)
static VALUE make_hostent_internal(struct hostent_arg *arg)
static int numeric_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
register unsigned int len
static VALUE addrinfo_afamily(VALUE self)
#define StringValueCStr(v)
int rb_getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
int rsock_fd_family(int fd)
static VALUE inspect_sockaddr(VALUE addrinfo, VALUE ret)
static VALUE addrinfo_canonname(VALUE self)
#define INIT_SOCKADDR_IN(addr, len)
static VALUE addrinfo_ipv4_private_p(VALUE self)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_check_array_type(VALUE ary)
void rsock_raise_socket_error(const char *reason, int error)
VALUE rb_str_catf(VALUE str, const char *format,...)
VALUE rb_check_string_type(VALUE)
static VALUE addrinfo_s_tcp(VALUE self, VALUE host, VALUE port)
struct rb_encoding_entry * list
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
int rb_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct rb_addrinfo **res)
struct addrinfo * ai_next
static VALUE addrinfo_socktype(VALUE self)
static void addrinfo_mark(void *ptr)
static VALUE make_inspectname(VALUE node, VALUE service, struct addrinfo *res)
static VALUE addrinfo_ip_port(VALUE self)
struct rb_addrinfo * addr
VALUE rsock_addrinfo_inspect_sockaddr(VALUE self)
static VALUE addrinfo_mdump(VALUE self)
static rb_addrinfo_t * get_addrinfo(VALUE self)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static VALUE addrinfo_inspect(VALUE self)
struct sockaddr * ai_addr
VALUE(* ipaddr)(struct sockaddr *, socklen_t)
static int extract_in_addr(VALUE self, uint32_t *addrp)
VALUE rsock_sockaddr_string_value(volatile VALUE *v)
#define str_equal(ptr, len, name)
VALUE rb_str_new(const char *, long)