2011/7/28 Jeremy Evans <merch-redmine / jeremyevans.net>:

>> > * ext/socket/lib/socket.rb: Don't check ipv6_recvpktinfo. This fixes a=
 failure in one of the socket tests:
>>
>> Why this fixes the problem?
>> We can't merge this without understanding.
>
> I think this is a general bug in the code.  If ipv6_recvpktinfo is true (=
which it is on OpenBSD since OpenBSD supports IPV6_PKTINFO), the Addrinfo f=
or IPV6 address "::" is not added as a socket to use.  The code looks like =
this:
>
> 516       elsif ai.ipv6? && ai.ip_address =3D=3D "::" && !ipv6_recvpktinf=
o
> 517         local_addrs.each {|a|
> 518           next if !a.ipv6?
> 519           ip_list << Addrinfo.new(a.to_sockaddr, :INET6, :DGRAM, 0);
> 520         }
>
> 527       sockets =3D ip_sockets_port0(ip_list, false)
>
> 544     pktinfo_sockets =3D {}
> 545     sockets.each {|s|
> 546       ai =3D s.local_address
> 547       if ipv6_recvpktinfo && ai.ipv6? && ai.ip_address =3D=3D "::"
> 548         s.setsockopt(:IPV6, ipv6_recvpktinfo, 1)
> 549         pktinfo_sockets[s] =3D true
> 550       end
> 551     }
>
> The pktinfo_sockets hash here is never used.  And even if it was, because=
 you are not adding the '::' address to ip_addrs if ipv6_recvpktinfo, no so=
cket is being created for it, so you will never hit lines 548-549.  The att=
ached patch removes the "&& !ipv6_recvpktinfo" from 516 and the pktinfo_soc=
kets hash handling.

Thank you for notifying pktinfo_sockets is not used.

However I don't understand why ip_list doesn't contain '::' address on Open=
BSD.

   516        elsif ai.ipv6? && ai.ip_address =3D=3D "::" && !ipv6_recvpkti=
nfo
   517          local_addrs.each {|a|
   518            next if !a.ipv6?
   519            ip_list << Addrinfo.new(a.to_sockaddr, :INET6, :DGRAM, 0)=
;
   520          }
   521        else
   522          ip_list << ai
   523        end

The line 522 should add '::' address to ip_list on platforms which
supports IPV6_PKTINFO.

Your patch, removing "&& !ipv6_recvpktinfo", means we don't use IPV6_PKTINF=
O.
It is not my intent.  (and it doesn't supports dynamic IP address change.)
--=20
Tanaka Akira