summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-20 06:52:18 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-20 06:52:18 +0000
commitb27be82d83f65c62ac0ff588eb60ba391a932bef (patch)
tree119d742a771d6aaab61d4adc9637458f1c665a01 /lib
parentd7b8cbbaf3991da0f34798217978e216e39acf18 (diff)
merge revision(s) 25246:
* 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/branches/ruby_1_8_7@25873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/resolv.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1c03f0c003..4f0c71cc40 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -592,10 +592,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
@@ -692,8 +692,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