ruby-changes:27426
From: akr <ko1@a...>
Date: Mon, 25 Feb 2013 02:51:39 +0900 (JST)
Subject: [ruby-changes:27426] akr:r39477 (trunk): * ext/socket: define and use union_sockaddr instead of struct
akr 2013-02-25 02:51:17 +0900 (Mon, 25 Feb 2013) New Revision: 39477 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39477 Log: * ext/socket: define and use union_sockaddr instead of struct sockaddr_storage for less casts. * ext/socket/rubysocket.h (union_sockaddr): defined. * ext/socket/socket.c (sock_accept): use union_sockaddr. (sock_accept_nonblock): ditto. (sock_sysaccept): ditto. (sock_s_getnameinfo): ditto. * ext/socket/basicsocket.c (bsock_getsockname): ditto. (bsock_getpeername): ditto. (bsock_local_address): ditto. (bsock_remote_address): ditto. * ext/socket/ancdata.c (bsock_recvmsg_internal): ditto. * ext/socket/init.c (recvfrom_arg): ditto. (recvfrom_blocking): ditto. (rsock_s_recvfrom): ditto. (rsock_s_recvfrom_nonblock): ditto. (rsock_getfamily): ditto. * ext/socket/raddrinfo.c (rb_addrinfo_t): ditto. (ai_get_afamily): ditto. (inspect_sockaddr): ditto. (addrinfo_mdump): ditto. (addrinfo_mload): ditto. (addrinfo_getnameinfo): ditto. (addrinfo_ip_port): ditto. (extract_in_addr): ditto. (addrinfo_ipv6_to_ipv4): ditto. (addrinfo_unix_path): ditto. * ext/socket/tcpserver.c (tcp_accept): ditto. (tcp_accept_nonblock): ditto. (tcp_sysaccept): ditto. * ext/socket/ipsocket.c (ip_addr): ditto. (ip_peeraddr): ditto. (ip_s_getaddress): ditto. Modified files: trunk/ChangeLog trunk/ext/socket/ancdata.c trunk/ext/socket/basicsocket.c trunk/ext/socket/init.c trunk/ext/socket/ipsocket.c trunk/ext/socket/raddrinfo.c trunk/ext/socket/rubysocket.h trunk/ext/socket/socket.c trunk/ext/socket/tcpserver.c Index: ChangeLog =================================================================== --- ChangeLog (revision 39476) +++ ChangeLog (revision 39477) @@ -1,3 +1,47 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Feb 25 02:37:56 2013 Tanaka Akira <akr@f...> + + * ext/socket: define and use union_sockaddr instead of struct + sockaddr_storage for less casts. + + * ext/socket/rubysocket.h (union_sockaddr): defined. + + * ext/socket/socket.c (sock_accept): use union_sockaddr. + (sock_accept_nonblock): ditto. + (sock_sysaccept): ditto. + (sock_s_getnameinfo): ditto. + + * ext/socket/basicsocket.c (bsock_getsockname): ditto. + (bsock_getpeername): ditto. + (bsock_local_address): ditto. + (bsock_remote_address): ditto. + + * ext/socket/ancdata.c (bsock_recvmsg_internal): ditto. + + * ext/socket/init.c (recvfrom_arg): ditto. + (recvfrom_blocking): ditto. + (rsock_s_recvfrom): ditto. + (rsock_s_recvfrom_nonblock): ditto. + (rsock_getfamily): ditto. + + * ext/socket/raddrinfo.c (rb_addrinfo_t): ditto. + (ai_get_afamily): ditto. + (inspect_sockaddr): ditto. + (addrinfo_mdump): ditto. + (addrinfo_mload): ditto. + (addrinfo_getnameinfo): ditto. + (addrinfo_ip_port): ditto. + (extract_in_addr): ditto. + (addrinfo_ipv6_to_ipv4): ditto. + (addrinfo_unix_path): ditto. + + * ext/socket/tcpserver.c (tcp_accept): ditto. + (tcp_accept_nonblock): ditto. + (tcp_sysaccept): ditto. + + * ext/socket/ipsocket.c (ip_addr): ditto. + (ip_peeraddr): ditto. + (ip_s_getaddress): ditto. + Sun Feb 24 21:15:05 2013 Tadayoshi Funaba <tadf@d...> * ext/date/date_core.c: [ruby-core:52303] Index: ext/socket/rubysocket.h =================================================================== --- ext/socket/rubysocket.h (revision 39476) +++ ext/socket/rubysocket.h (revision 39477) @@ -151,6 +151,18 @@ struct sockaddr_storage { https://github.com/ruby/ruby/blob/trunk/ext/socket/rubysocket.h#L151 }; #endif +typedef union { + struct sockaddr addr; + struct sockaddr_in in; +#ifdef AF_INET6 + struct sockaddr_in6 in6; +#endif +#ifdef HAVE_TYPE_STRUCT_SOCKADDR_UN + struct sockaddr_un un; +#endif + struct sockaddr_storage storage; +} union_sockaddr; + #ifdef __APPLE__ /* * CMSG_ macros are broken on 64bit darwin, because __DARWIN_ALIGN Index: ext/socket/init.c =================================================================== --- ext/socket/init.c (revision 39476) +++ ext/socket/init.c (revision 39477) @@ -91,7 +91,7 @@ struct recvfrom_arg { https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L91 int fd, flags; VALUE str; socklen_t alen; - struct sockaddr_storage buf; + union_sockaddr buf; }; static VALUE @@ -101,7 +101,7 @@ recvfrom_blocking(void *data) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L101 socklen_t len0 = arg->alen; ssize_t ret; ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str), - arg->flags, (struct sockaddr*)&arg->buf, &arg->alen); + arg->flags, &arg->buf.addr, &arg->alen); if (ret != -1 && len0 < arg->alen) arg->alen = len0; return (VALUE)ret; @@ -160,16 +160,16 @@ rsock_s_recvfrom(VALUE sock, int argc, V https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L160 } #endif if (arg.alen && arg.alen != sizeof(arg.buf)) /* OSX doesn't return a from result for connection-oriented sockets */ - return rb_assoc_new(str, rsock_ipaddr((struct sockaddr*)&arg.buf, arg.alen, fptr->mode & FMODE_NOREVLOOKUP)); + return rb_assoc_new(str, rsock_ipaddr(&arg.buf.addr, arg.alen, fptr->mode & FMODE_NOREVLOOKUP)); else return rb_assoc_new(str, Qnil); #ifdef HAVE_SYS_UN_H case RECV_UNIX: - return rb_assoc_new(str, rsock_unixaddr((struct sockaddr_un*)&arg.buf, arg.alen)); + return rb_assoc_new(str, rsock_unixaddr(&arg.buf.un, arg.alen)); #endif case RECV_SOCKET: - return rb_assoc_new(str, rsock_io_socket_addrinfo(sock, (struct sockaddr*)&arg.buf, arg.alen)); + return rb_assoc_new(str, rsock_io_socket_addrinfo(sock, &arg.buf.addr, arg.alen)); default: rb_bug("rsock_s_recvfrom called with bad value"); } @@ -180,7 +180,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, in https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L180 { rb_io_t *fptr; VALUE str; - struct sockaddr_storage buf; + union_sockaddr buf; socklen_t alen = (socklen_t)sizeof buf; VALUE len, flg; long buflen; @@ -212,7 +212,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, in https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L212 rb_io_check_closed(fptr); rb_io_set_nonblock(fptr); len0 = alen; - slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)&buf, &alen); + slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, &buf.addr, &alen); if (slen != -1 && len0 < alen) alen = len0; @@ -236,11 +236,11 @@ rsock_s_recvfrom_nonblock(VALUE sock, in https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L236 case RECV_IP: if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */ - addr = rsock_ipaddr((struct sockaddr*)&buf, alen, fptr->mode & FMODE_NOREVLOOKUP); + addr = rsock_ipaddr(&buf.addr, alen, fptr->mode & FMODE_NOREVLOOKUP); break; case RECV_SOCKET: - addr = rsock_io_socket_addrinfo(sock, (struct sockaddr*)&buf, alen); + addr = rsock_io_socket_addrinfo(sock, &buf.addr, alen); break; default: @@ -596,14 +596,14 @@ rsock_s_accept(VALUE klass, int fd, stru https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L596 int rsock_getfamily(int sockfd) { - struct sockaddr_storage ss; + union_sockaddr ss; socklen_t sslen = (socklen_t)sizeof(ss); - ss.ss_family = AF_UNSPEC; - if (getsockname(sockfd, (struct sockaddr*)&ss, &sslen) < 0) + ss.addr.sa_family = AF_UNSPEC; + if (getsockname(sockfd, &ss.addr, &sslen) < 0) return AF_UNSPEC; - return ss.ss_family; + return ss.addr.sa_family; } void Index: ext/socket/raddrinfo.c =================================================================== --- ext/socket/raddrinfo.c (revision 39476) +++ ext/socket/raddrinfo.c (revision 39477) @@ -537,7 +537,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L537 int socktype; int protocol; socklen_t sockaddr_len; - struct sockaddr_storage addr; + union_sockaddr addr; } rb_addrinfo_t; static void @@ -944,7 +944,7 @@ get_afamily(struct sockaddr *addr, sockl https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L944 static int ai_get_afamily(rb_addrinfo_t *rai) { - return get_afamily((struct sockaddr *)&rai->addr, rai->sockaddr_len); + return get_afamily(&rai->addr.addr, rai->sockaddr_len); } static VALUE @@ -955,10 +955,10 @@ inspect_sockaddr(VALUE addrinfo, VALUE r https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L955 if (rai->sockaddr_len == 0) { rb_str_cat2(ret, "empty-sockaddr"); } - else if ((long)rai->sockaddr_len < ((char*)&rai->addr.ss_family + sizeof(rai->addr.ss_family)) - (char*)&rai->addr) + else if ((long)rai->sockaddr_len < ((char*)&rai->addr.addr.sa_family + sizeof(rai->addr.addr.sa_family)) - (char*)&rai->addr) rb_str_cat2(ret, "too-short-sockaddr"); else { - switch (rai->addr.ss_family) { + switch (rai->addr.addr.sa_family) { case AF_INET: { struct sockaddr_in *addr; @@ -967,7 +967,7 @@ inspect_sockaddr(VALUE addrinfo, VALUE r https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L967 rb_str_cat2(ret, "too-short-AF_INET-sockaddr"); } else { - addr = (struct sockaddr_in *)&rai->addr; + addr = &rai->addr.in; rb_str_catf(ret, "%d.%d.%d.%d", ((unsigned char*)&addr->sin_addr)[0], ((unsigned char*)&addr->sin_addr)[1], @@ -993,12 +993,12 @@ inspect_sockaddr(VALUE addrinfo, VALUE r https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L993 rb_str_cat2(ret, "too-short-AF_INET6-sockaddr"); } else { - addr = (struct sockaddr_in6 *)&rai->addr; + addr = &rai->addr.in6; /* use getnameinfo for scope_id. * RFC 4007: IPv6 Scoped Address Architecture * draft-ietf-ipv6-scope-api-00.txt: Scoped Address Extensions to the IPv6 Basic Socket API */ - error = getnameinfo((struct sockaddr *)&rai->addr, rai->sockaddr_len, + error = getnameinfo(&rai->addr.addr, rai->sockaddr_len, hbuf, (socklen_t)sizeof(hbuf), NULL, 0, NI_NUMERICHOST|NI_NUMERICSERV); if (error) { @@ -1021,7 +1021,7 @@ inspect_sockaddr(VALUE addrinfo, VALUE r https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1021 #ifdef HAVE_SYS_UN_H case AF_UNIX: { - struct sockaddr_un *addr = (struct sockaddr_un *)&rai->addr; + struct sockaddr_un *addr = &rai->addr.un; char *p, *s, *e; s = addr->sun_path; e = (char*)addr + rai->sockaddr_len; @@ -1058,9 +1058,9 @@ inspect_sockaddr(VALUE addrinfo, VALUE r https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1058 default: { - ID id = rsock_intern_family(rai->addr.ss_family); + ID id = rsock_intern_family(rai->addr.addr.sa_family); if (id == 0) - rb_str_catf(ret, "unknown address family %d", rai->addr.ss_family); + rb_str_catf(ret, "unknown address family %d", rai->addr.addr.sa_family); else rb_str_catf(ret, "%s address format unknown", rb_id2name(id)); break; @@ -1215,7 +1215,7 @@ addrinfo_mdump(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1215 #ifdef HAVE_SYS_UN_H case AF_UNIX: { - struct sockaddr_un *su = (struct sockaddr_un *)&rai->addr; + struct sockaddr_un *su = &rai->addr.un; char *s, *e; s = su->sun_path; e = (char*)su + rai->sockaddr_len; @@ -1230,7 +1230,7 @@ addrinfo_mdump(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1230 { char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; int error; - error = getnameinfo((struct sockaddr *)&rai->addr, rai->sockaddr_len, + error = getnameinfo(&rai->addr.addr, rai->sockaddr_len, hbuf, (socklen_t)sizeof(hbuf), pbuf, (socklen_t)sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV); if (error) { @@ -1251,7 +1251,7 @@ addrinfo_mload(VALUE self, VALUE ary) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1251 VALUE v; VALUE canonname, inspectname; int afamily, pfamily, socktype, protocol; - struct sockaddr_storage ss; + union_sockaddr ss; socklen_t len; rb_addrinfo_t *rai; @@ -1348,7 +1348,7 @@ addrinfo_mload(VALUE self, VALUE ary) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1348 } DATA_PTR(self) = rai = alloc_addrinfo(); - init_addrinfo(rai, (struct sockaddr *)&ss, len, + init_addrinfo(rai, &ss.addr, len, pfamily, socktype, protocol, canonname, inspectname); return self; @@ -1576,7 +1576,7 @@ addrinfo_getnameinfo(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1576 if (rai->socktype == SOCK_DGRAM) flags |= NI_DGRAM; - error = getnameinfo((struct sockaddr *)&rai->addr, rai->sockaddr_len, + error = getnameinfo(&rai->addr.addr, rai->sockaddr_len, hbuf, (socklen_t)sizeof(hbuf), pbuf, (socklen_t)sizeof(pbuf), flags); if (error) { @@ -1667,14 +1667,14 @@ addrinfo_ip_port(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1667 case AF_INET: if (rai->sockaddr_len != sizeof(struct sockaddr_in)) rb_raise(rb_eSocket, "unexpected sockaddr size for IPv4"); - port = ntohs(((struct sockaddr_in *)&rai->addr)->sin_port); + port = ntohs(rai->addr.in.sin_port); break; #ifdef AF_INET6 case AF_INET6: if (rai->sockaddr_len != sizeof(struct sockaddr_in6)) rb_raise(rb_eSocket, "unexpected sockaddr size for IPv6"); - port = ntohs(((struct sockaddr_in6 *)&rai->addr)->sin6_port); + port = ntohs(rai->addr.in6.sin6_port); break; #endif @@ -1691,7 +1691,7 @@ extract_in_addr(VALUE self, uint32_t *ad https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1691 rb_addrinfo_t *rai = get_addrinfo(self); int family = ai_get_afamily(rai); if (family != AF_INET) return 0; - *addrp = ntohl(((struct sockaddr_in *)&rai->addr)->sin_addr.s_addr); + *addrp = ntohl(rai->addr.in.sin_addr.s_addr); return 1; } @@ -1747,7 +1747,7 @@ extract_in6_addr(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1747 rb_addrinfo_t *rai = get_addrinfo(self); int family = ai_get_afamily(rai); if (family != AF_INET6) return NULL; - return &((struct sockaddr_in6 *)&rai->addr)->sin6_addr; + return &rai->addr.in6.sin6_addr; } /* @@ -1923,7 +1923,7 @@ addrinfo_ipv6_to_ipv4(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1923 struct in6_addr *addr; int family = ai_get_afamily(rai); if (family != AF_INET6) return Qnil; - addr = &((struct sockaddr_in6 *)&rai->addr)->sin6_addr; + addr = &rai->addr.in6.sin6_addr; if (IN6_IS_ADDR_V4MAPPED(addr) || IN6_IS_ADDR_V4COMPAT(addr)) { struct sockaddr_in sin4; INIT_SOCKADDR_IN(&sin4, sizeof(sin4)); @@ -1959,7 +1959,7 @@ addrinfo_unix_path(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1959 if (family != AF_UNIX) rb_raise(rb_eSocket, "need AF_UNIX address"); - addr = (struct sockaddr_un *)&rai->addr; + addr = &rai->addr.un; s = addr->sun_path; e = (char*)addr + rai->sockaddr_len; Index: ext/socket/tcpserver.c =================================================================== --- ext/socket/tcpserver.c (revision 39476) +++ ext/socket/tcpserver.c (revision 39477) @@ -47,13 +47,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/tcpserver.c#L47 tcp_accept(VALUE sock) { rb_io_t *fptr; - struct sockaddr_storage from; + union_sockaddr from; socklen_t fromlen; GetOpenFile(sock, fptr); fromlen = (socklen_t)sizeof(from); - return rsock_s_accept(rb_cTCPSocket, fptr->fd, - (struct sockaddr*)&from, &fromlen); + return rsock_s_accept(rb_cTCPSocket, fptr->fd, &from.addr, &fromlen); } /* @@ -93,13 +92,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/tcpserver.c#L92 tcp_accept_nonblock(VALUE sock) { rb_io_t *fptr; - struct sockaddr_storage from; + union_sockaddr from; socklen_t fromlen; GetOpenFile(sock, fptr); fromlen = (socklen_t)sizeof(from); - return rsock_s_accept_nonblock(rb_cTCPSocket, fptr, - (struct sockaddr *)&from, &fromlen); + return rsock_s_accept_nonblock(rb_cTCPSocket, fptr, &from.addr, &fromlen); } /* @@ -120,12 +118,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/tcpserver.c#L118 tcp_sysaccept(VALUE sock) { rb_io_t *fptr; - struct sockaddr_storage from; + union_sockaddr from; socklen_t fromlen; GetOpenFile(sock, fptr); fromlen = (socklen_t)sizeof(from); - return rsock_s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen); + return rsock_s_accept(0, fptr->fd, &from.addr, &fromlen); } void Index: ext/socket/ipsocket.c =================================================================== --- ext/socket/ipsocket.c (revision 39476) +++ ext/socket/ipsocket.c (revision 39477) @@ -184,7 +184,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L184 ip_addr(int argc, VALUE *argv, VALUE sock) { rb_io_t *fptr; - struct sockaddr_storage addr; + union_sockaddr addr; socklen_t len = (socklen_t)sizeof addr; int norevlookup; @@ -192,9 +192,9 @@ ip_addr(int argc, VALUE *argv, VALUE soc https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L192 if (argc < 1 || !rsock_revlookup_flag(argv[0], &norevlookup)) norevlookup = fptr->mode & FMODE_NOREVLOOKUP; - if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0) + if (getsockname(fptr->fd, &addr.addr, &len) < 0) rb_sys_fail("getsockname(2)"); - return rsock_ipaddr((struct sockaddr*)&addr, len, norevlookup); + return rsock_ipaddr(&addr.addr, len, norevlookup); } /* @@ -225,7 +225,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L225 ip_peeraddr(int argc, VALUE *argv, VALUE sock) { rb_io_t *fptr; - struct sockaddr_storage addr; + union_sockaddr addr; socklen_t len = (socklen_t)sizeof addr; int norevlookup; @@ -233,9 +233,9 @@ ip_peeraddr(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L233 if (argc < 1 || !rsock_revlookup_flag(argv[0], &norevlookup)) norevlookup = fptr->mode & FMODE_NOREVLOOKUP; - if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0) + if (getpeername(fptr->fd, &addr.addr, &len) < 0) rb_sys_fail("getpeername(2)"); - return rsock_ipaddr((struct sockaddr*)&addr, len, norevlookup); + return rsock_ipaddr(&addr.addr, len, norevlookup); } /* @@ -278,14 +278,14 @@ ip_recvfrom(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L278 static VALUE ip_s_getaddress(VALUE obj, VALUE host) { - struct sockaddr_storage addr; + union_sockaddr addr; struct addrinfo *res = rsock_addrinfo(host, Qnil, SOCK_STREAM, 0); /* just take the first one */ memcpy(&addr, res->ai_addr, res->ai_addrlen); freeaddrinfo(res); - return rsock_make_ipaddr((struct sockaddr*)&addr, res->ai_addrlen); + return rsock_make_ipaddr(&addr.addr, res->ai_addrlen); } void Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 39476) +++ ext/socket/socket.c (revision 39477) @@ -755,13 +755,13 @@ sock_accept(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L755 { rb_io_t *fptr; VALUE sock2; - struct sockaddr_storage buf; + union_sockaddr buf; socklen_t len = (socklen_t)sizeof buf; GetOpenFile(sock, fptr); - sock2 = rsock_s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)&buf,&len); + sock2 = rsock_s_accept(rb_cSocket,fptr->fd,&buf.addr,&len); - return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len)); + return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, &buf.addr, len)); } /* @@ -820,12 +820,12 @@ sock_accept_nonblock(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L820 { rb_io_t *fptr; VALUE sock2; - struct sockaddr_storage buf; + union_sockaddr buf; socklen_t len = (socklen_t)sizeof buf; GetOpenFile(sock, fptr); - sock2 = rsock_s_accept_nonblock(rb_cSocket, fptr, (struct sockaddr *)&buf, &len); - return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, (struct sockaddr*)&buf, len)); + sock2 = rsock_s_accept_nonblock(rb_cSocket, fptr, &buf.addr, &len); + return rb_assoc_new(sock2, rsock_io_socket_addrinfo(sock2, &buf.addr, len)); } /* @@ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/