1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2009-10-06 15:31:22 +00:00
parent e1797bc7dd
commit 230411caa2
2 changed files with 12 additions and 4 deletions

View file

@ -1,3 +1,10 @@
Wed Oct 7 00:27:01 2009 Tanaka Akira <akr@fsij.org>
* 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 <akr@fsij.org>
* io.c (io_reopen): avoid close if possible.

View file

@ -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