use Socket.getifaddrs to show interface names and so on
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
28e78bf7f2
commit
c3ebc82832
@ -317,9 +317,9 @@ class TestSocket < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_udp_server
|
def test_udp_server
|
||||||
begin
|
begin
|
||||||
ip_addrs = Socket.ip_address_list
|
ifaddrs = Socket.getifaddrs
|
||||||
rescue NotImplementedError
|
rescue NotImplementedError
|
||||||
skip "Socket.ip_address_list not implemented"
|
skip "Socket.getifaddrs not implemented"
|
||||||
end
|
end
|
||||||
|
|
||||||
ifconfig = nil
|
ifconfig = nil
|
||||||
@ -327,7 +327,8 @@ class TestSocket < Test::Unit::TestCase
|
|||||||
famlies = {}
|
famlies = {}
|
||||||
sockets.each {|s| famlies[s.local_address.afamily] = s }
|
sockets.each {|s| famlies[s.local_address.afamily] = s }
|
||||||
nd6 = {}
|
nd6 = {}
|
||||||
ip_addrs.reject! {|ai|
|
ifaddrs.reject! {|ifa|
|
||||||
|
ai = ifa.addr
|
||||||
s = famlies[ai.afamily]
|
s = famlies[ai.afamily]
|
||||||
next true unless s
|
next true unless s
|
||||||
next true if ai.ipv6_linklocal? # IPv6 link-local address is too troublesome in this test.
|
next true if ai.ipv6_linklocal? # IPv6 link-local address is too troublesome in this test.
|
||||||
@ -340,14 +341,14 @@ class TestSocket < Test::Unit::TestCase
|
|||||||
next true
|
next true
|
||||||
end
|
end
|
||||||
when /freebsd/
|
when /freebsd/
|
||||||
if ifr_name = ai.ip_address[/%(.*)/, 1]
|
if ifa.addr.ipv6_linklocal?
|
||||||
# FreeBSD 9.0 with default setting (ipv6_activate_all_interfaces
|
# FreeBSD 9.0 with default setting (ipv6_activate_all_interfaces
|
||||||
# is not YES) sets IFDISABLED to interfaces which don't have
|
# is not YES) sets IFDISABLED to interfaces which don't have
|
||||||
# global IPv6 address.
|
# global IPv6 address.
|
||||||
# Link-local IPv6 addresses on those interfaces don't work.
|
# Link-local IPv6 addresses on those interfaces don't work.
|
||||||
ulSIOCGIFINFO_IN6 = 3225971052
|
ulSIOCGIFINFO_IN6 = 3225971052
|
||||||
ulND6_IFF_IFDISABLED = 8
|
ulND6_IFF_IFDISABLED = 8
|
||||||
in6_ondireq = ifr_name
|
in6_ondireq = ifa.name
|
||||||
s.ioctl(ulSIOCGIFINFO_IN6, in6_ondireq)
|
s.ioctl(ulSIOCGIFINFO_IN6, in6_ondireq)
|
||||||
flag = in6_ondireq.unpack('A16L6').last
|
flag = in6_ondireq.unpack('A16L6').last
|
||||||
next true if flag & ulND6_IFF_IFDISABLED != 0
|
next true if flag & ulND6_IFF_IFDISABLED != 0
|
||||||
@ -394,14 +395,15 @@ class TestSocket < Test::Unit::TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_addrs.each {|ai|
|
ifaddrs.each {|ifa|
|
||||||
|
ai = ifa.addr
|
||||||
Addrinfo.udp(ai.ip_address, port).connect {|s|
|
Addrinfo.udp(ai.ip_address, port).connect {|s|
|
||||||
ping_p = false
|
ping_p = false
|
||||||
msg1 = "<<<#{ai.inspect}>>>"
|
msg1 = "<<<#{ai.inspect}>>>"
|
||||||
s.sendmsg msg1
|
s.sendmsg msg1
|
||||||
unless IO.select([s], nil, nil, 10)
|
unless IO.select([s], nil, nil, 10)
|
||||||
nd6options = nd6.key?(ai) ? "nd6=%x " % nd6[ai] : ''
|
nd6options = nd6.key?(ai) ? "nd6=%x " % nd6[ai] : ''
|
||||||
raise "no response from #{ai.inspect} #{nd6options}ping=#{ping_p}"
|
raise "no response from #{ifa.inspect} #{nd6options}ping=#{ping_p}"
|
||||||
end
|
end
|
||||||
msg2, addr = s.recvmsg
|
msg2, addr = s.recvmsg
|
||||||
msg2, _, _ = Marshal.load(msg2)
|
msg2, _, _ = Marshal.load(msg2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user