diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-17 08:41:21 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-17 08:41:21 +0000 |
commit | da74f0f426072e97fee3494fbe9691e59bdf860b (patch) | |
tree | 42b1b774169e702a046a5c54e1780337b5911f3d /test/net | |
parent | c2bcae864e3d8ee4265d9b125f34af9236f5cea7 (diff) |
Support IPv6 address. [Bug #6746]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net')
-rw-r--r-- | test/net/http/test_http.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 49ffc5e9ea..0931133b29 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -632,7 +632,7 @@ class TestNetHTTPLocalBind < Test::Unit::TestCase @server.mount_proc('/show_ip') { |req, res| res.body = req.remote_ip } http = Net::HTTP.new(config('host'), config('port')) - http.local_host = _select_local_ip_address + http.local_host = _select_local_ip_address(config('host'), config('port')) assert_not_nil(http.local_host) assert_nil(http.local_port) @@ -645,7 +645,7 @@ class TestNetHTTPLocalBind < Test::Unit::TestCase @server.mount_proc('/show_port') { |req, res| res.body = req.peeraddr[1].to_s } http = Net::HTTP.new(config('host'), config('port')) - http.local_host = _select_local_ip_address + http.local_host = _select_local_ip_address(config('host'), config('port')) http.local_port = [*10000..20000].shuffle.first.to_s assert_not_nil(http.local_host) assert_not_nil(http.local_port) @@ -654,9 +654,11 @@ class TestNetHTTPLocalBind < Test::Unit::TestCase assert_equal(http.local_port, res.body) end - def _select_local_ip_address + def _select_local_ip_address(saddr, sport) Socket.ip_address_list.find { |addr| - addr.ipv4? and not addr.ipv4_loopback? and not addr.ipv4_multicast? + next if Addrinfo.tcp(saddr, sport).afamily != addr.afamily + addr.ipv4? ? !addr.ipv4_loopback? && !addr.ipv4_multicast? \ + : !addr.ipv6_loopback? && !addr.ipv6_multicast? }.ip_address end end |