diff --git a/ChangeLog b/ChangeLog index a259f9ec5c..02853b2dc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Feb 15 20:29:11 2013 Tanaka Akira + + * 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. + Fri Feb 15 18:24:48 2013 Nobuyoshi Nakada * lib/mkmf.rb (MakeMakefile#try_run): bail out explicitly if cross diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index e8955d7acb..067be4f831 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -253,7 +253,7 @@ make_inetaddr(unsigned int host, char *buf, size_t buflen) { struct sockaddr_in sin; - INIT_SOCKADDR((struct sockaddr *)&sin, AF_INET, sizeof(sin)); + INIT_SOCKADDR_IN(&sin, AF_INET, sizeof(sin)); sin.sin_addr.s_addr = host; make_ipaddr0((struct sockaddr*)&sin, sizeof(sin), buf, buflen); } @@ -1929,7 +1929,7 @@ addrinfo_ipv6_to_ipv4(VALUE self) addr = &((struct sockaddr_in6 *)&rai->addr)->sin6_addr; if (IN6_IS_ADDR_V4MAPPED(addr) || IN6_IS_ADDR_V4COMPAT(addr)) { struct sockaddr_in sin4; - INIT_SOCKADDR((struct sockaddr *)&sin4, AF_INET, sizeof(sin4)); + INIT_SOCKADDR_IN(&sin4, AF_INET, sizeof(sin4)); memcpy(&sin4.sin_addr, (char*)addr + sizeof(*addr) - sizeof(sin4.sin_addr), sizeof(sin4.sin_addr)); return rsock_addrinfo_new((struct sockaddr *)&sin4, (socklen_t)sizeof(sin4), PF_INET, rai->socktype, rai->protocol, diff --git a/ext/socket/sockport.h b/ext/socket/sockport.h index 517b8f7420..95f4214d44 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)