summaryrefslogtreecommitdiff
path: root/ext/socket/sockport.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-15 11:30:19 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-15 11:30:19 +0000
commite41b789c9980e2ae4bdb9d320a498e8529524dec (patch)
treed2485790588f10744d390e51a69cba110067db11 /ext/socket/sockport.h
parent140934c6611e77d7c1e0ce9f30e8861a20cc32ca (diff)
* ext/socket/sockport.h (SET_SIN_LEN): defined for strict-aliasing
rule. (INIT_SOCKADDR_IN): ditto. * ext/socket/raddrinfo.c (make_inetaddr): use INIT_SOCKADDR_IN. (addrinfo_ipv6_to_ipv4): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/sockport.h')
-rw-r--r--ext/socket/sockport.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/socket/sockport.h b/ext/socket/sockport.h
index 517b8f7..95f4214 100644
--- a/ext/socket/sockport.h
+++ b/ext/socket/sockport.h
@@ -22,6 +22,13 @@
# define SET_SA_LEN(sa, len) (void)(len)
#endif
+/* for strict-aliasing rule */
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
+# define SET_SIN_LEN(sa, len) (void)((sa)->sin_len = (len))
+#else
+# define SET_SIN_LEN(sa, len) SET_SA_LEN((struct sockaddr *)(sa), (len))
+#endif
+
#define INIT_SOCKADDR(addr, family, len) \
do { \
struct sockaddr *init_sockaddr_ptr = (addr); \
@@ -31,6 +38,15 @@
SET_SA_LEN(init_sockaddr_ptr, init_sockaddr_len); \
} while (0)
+#define INIT_SOCKADDR_IN(addr, family, len) \
+ do { \
+ struct sockaddr_in *init_sockaddr_ptr = (addr); \
+ socklen_t init_sockaddr_len = (len); \
+ memset(init_sockaddr_ptr, 0, init_sockaddr_len); \
+ init_sockaddr_ptr->sin_family = (family); \
+ SET_SIN_LEN(init_sockaddr_ptr, init_sockaddr_len); \
+ } while (0)
+
#ifndef IN_MULTICAST
# define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
# define IN_MULTICAST(i) IN_CLASSD(i)