Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,19 @@ def self.free_request_id(host, port, id) # :nodoc:
def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
udpsock.bind(bind_host, 0)
end
when /mswin|mingw/
# Sequential port assignment
def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
# SO_EXCLUSIVEADDRUSE: make bind fail if another socket already uses the port
udpsock.setsockopt(Socket::SOL_SOCKET, ~Socket::SO_REUSEADDR, 1)
begin
# Ephemeral port number range recommended by RFC 6056
port = random(1024..65535)
udpsock.bind(bind_host, port)
rescue Errno::EADDRINUSE, Errno::EACCES
retry
end
end
else
# Sequential port assignment
def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
Expand Down
Loading