ruby-changes:28541
From: akr <ko1@a...>
Date: Mon, 6 May 2013 20:51:18 +0900 (JST)
Subject: [ruby-changes:28541] akr:r40593 (trunk): * ext/socket/socket.c (socket_s_ip_address_list): Fill sin6_scope_id
akr 2013-05-06 20:51:07 +0900 (Mon, 06 May 2013) New Revision: 40593 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40593 Log: * ext/socket/socket.c (socket_s_ip_address_list): Fill sin6_scope_id if getifaddrs() returns an IPv6 link local address which sin6_scope_id is zero, such as on OpenIndiana SunOS 5.11. Modified files: trunk/ChangeLog trunk/ext/socket/socket.c Index: ChangeLog =================================================================== --- ChangeLog (revision 40592) +++ ChangeLog (revision 40593) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon May 6 20:50:37 2013 Tanaka Akira <akr@f...> + + * ext/socket/socket.c (socket_s_ip_address_list): Fill sin6_scope_id + if getifaddrs() returns an IPv6 link local address which + sin6_scope_id is zero, such as on OpenIndiana SunOS 5.11. + Sun May 5 18:56:52 2013 Nobuyoshi Nakada <nobu@r...> * insns.def (defined): use vm_search_superclass() like as normal super Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 40592) +++ ext/socket/socket.c (revision 40593) @@ -1658,6 +1658,26 @@ socket_s_ip_address_list(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1658 for (p = ifp; p; p = p->ifa_next) { if (p->ifa_addr != NULL && IS_IP_FAMILY(p->ifa_addr->sa_family)) { struct sockaddr *addr = p->ifa_addr; +#if defined(AF_INET6) + /* + * OpenIndiana SunOS 5.11 getifaddrs() returns IPv6 link local + * address with sin6_scope_id == 0. + * So fill it from the interface name (ifa_name). + */ + struct sockaddr_in6 addr6; + if (addr->sa_family == AF_INET6) { + socklen_t len = (socklen_t)sizeof(struct sockaddr_in6); + memcpy(&addr6, addr, len); + addr = (struct sockaddr *)&addr6; + if (IN6_IS_ADDR_LINKLOCAL(&addr6.sin6_addr) && + addr6.sin6_scope_id == 0) { + unsigned int ifindex = if_nametoindex(p->ifa_name); + if (ifindex != 0) { + addr6.sin6_scope_id = ifindex; + } + } + } +#endif rb_ary_push(list, sockaddr_obj(addr, sockaddr_len(addr))); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/