[前][次][番号順一覧][スレッド一覧]

ruby-changes:24365

From: naruse <ko1@a...>
Date: Tue, 17 Jul 2012 17:42:02 +0900 (JST)
Subject: [ruby-changes:24365] naruse:r36416 (trunk): Support IPv6 address. [Bug #6746]

naruse	2012-07-17 17:41:21 +0900 (Tue, 17 Jul 2012)

  New Revision: 36416

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36416

  Log:
    Support IPv6 address. [Bug #6746]

  Modified files:
    trunk/test/net/http/test_http.rb

Index: test/net/http/test_http.rb
===================================================================
--- test/net/http/test_http.rb	(revision 36415)
+++ test/net/http/test_http.rb	(revision 36416)
@@ -632,7 +632,7 @@
     @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 @@
     @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 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]