summaryrefslogtreecommitdiff
path: root/ext/socket/sockport.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-19 10:37:43 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-19 10:37:43 +0000
commit2e6b97a45d077979121b29484a8831034d47ef50 (patch)
treebb94b8e14405cd8101f11b69d5ba29d8697b1128 /ext/socket/sockport.h
parentdd1c3a75096b97c1ebcb8597c001761ddfb3c1bf (diff)
* ext/socket: Bypass getaddrinfo() if node and serv are numeric.
Reporeted by Naotoshi Seo. [ruby-core:60801] [Bug #9525] * ext/socket/extconf.rb: Detect struct sockaddr_in6.sin6_len. * ext/socket/sockport.h (SET_SIN6_LEN): New macro. (INIT_SOCKADDR_IN6): Ditto. * ext/socket/rubysocket.h (struct rb_addrinfo): Add allocated_by_malloc field. * ext/socket/raddrinfo.c (numeric_getaddrinfo): New function. (rb_getaddrinfo): Call numeric_getaddrinfo at first. (rb_freeaddrinfo): Free struct addrinfo properly when it is allocated by numeric_getaddrinfo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/sockport.h')
-rw-r--r--ext/socket/sockport.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/socket/sockport.h b/ext/socket/sockport.h
index a3c698e..2b58958 100644
--- a/ext/socket/sockport.h
+++ b/ext/socket/sockport.h
@@ -29,6 +29,12 @@
# define SET_SIN_LEN(sa, len) SET_SA_LEN((struct sockaddr *)(sa), (len))
#endif
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
+# define SET_SIN6_LEN(sa, len) (void)((sa)->sin6_len = (len))
+#else
+# define SET_SIN6_LEN(sa, len) SET_SA_LEN((struct sockaddr *)(sa), (len))
+#endif
+
#define INIT_SOCKADDR(addr, family, len) \
do { \
struct sockaddr *init_sockaddr_ptr = (addr); \
@@ -47,6 +53,15 @@
SET_SIN_LEN(init_sockaddr_ptr, init_sockaddr_len); \
} while (0)
+#define INIT_SOCKADDR_IN6(addr, len) \
+ do { \
+ struct sockaddr_in6 *init_sockaddr_ptr = (addr); \
+ socklen_t init_sockaddr_len = (len); \
+ memset(init_sockaddr_ptr, 0, init_sockaddr_len); \
+ init_sockaddr_ptr->sin6_family = AF_INET6; \
+ SET_SIN6_LEN(init_sockaddr_ptr, init_sockaddr_len); \
+ } while (0)
+
/* for strict-aliasing rule */
#ifdef HAVE_TYPE_STRUCT_SOCKADDR_UN