diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-06 15:31:22 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-06 15:31:22 +0000 |
commit | 230411caa2cf512a9f82d917c10d2785e936bf16 (patch) | |
tree | 55c447897c449710018f9990d61104361ec4f043 /lib/resolv.rb | |
parent | e1797bc7dd2178550cf15d7a6af4f7f0eae003b4 (diff) | |
download | ruby-230411caa2cf512a9f82d917c10d2785e936bf16.tar.gz |
* 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
Diffstat (limited to 'lib/resolv.rb')
-rw-r--r-- | lib/resolv.rb | 9 |
1 files changed, 5 insertions, 4 deletions
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 |