From 230411caa2cf512a9f82d917c10d2785e936bf16 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 6 Oct 2009 15:31:22 +0000 Subject: [PATCH] * lib/resolv.rb (Resolv::DNS.bind_random_port): bind to "::" for IPv6. (Resolv::DNS::ConnectedUDP#initialize): specify is_ipv6 argument of bind_random_port. [ruby-core:25970] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ lib/resolv.rb | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 512b915c6a..4f45ac5b73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Oct 7 00:27:01 2009 Tanaka Akira + + * lib/resolv.rb (Resolv::DNS.bind_random_port): bind to "::" for IPv6. + (Resolv::DNS::ConnectedUDP#initialize): specify is_ipv6 argument of + bind_random_port. + [ruby-core:25970] + Tue Oct 6 21:30:58 2009 Tanaka Akira * io.c (io_reopen): avoid close if possible. diff --git a/lib/resolv.rb b/lib/resolv.rb index ed8859d3c4..265a4b7f0c 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -599,10 +599,10 @@ class Resolv } end - def self.bind_random_port(udpsock) # :nodoc: + def self.bind_random_port(udpsock, is_ipv6=false) # :nodoc: begin port = rangerand(1024..65535) - udpsock.bind("", port) + udpsock.bind(is_ipv6 ? "::" : "", port) rescue Errno::EADDRINUSE retry end @@ -699,8 +699,9 @@ class Resolv super() @host = host @port = port - @sock = UDPSocket.new(host.index(':') ? Socket::AF_INET6 : Socket::AF_INET) - DNS.bind_random_port(@sock) + is_ipv6 = host.index(':') + @sock = UDPSocket.new(is_ipv6 ? Socket::AF_INET6 : Socket::AF_INET) + DNS.bind_random_port(@sock, is_ipv6) @sock.connect(host, port) @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD end