Skip to content

Commit

Permalink
Use port number 0 for ephemeral port
Browse files Browse the repository at this point in the history
Hopefully RFC-6056 is being applied.
Fixes #63.
  • Loading branch information
nobu committed Jan 20, 2025
1 parent 5880fd4 commit 49681ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ def self.free_request_id(host, port, id) # :nodoc:

def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
begin
port = random(1024..65535)
udpsock.bind(bind_host, port)
# Simply use 0 with assuming RFC-6056 is applied.
udpsock.bind(bind_host, 0)
rescue Errno::EADDRINUSE, # POSIX
Errno::EACCES, # SunOS: See PRIV_SYS_NFS in privileges(5)
Errno::EPERM # FreeBSD: security.mac.portacl.port_high is configurable. See mac_portacl(4).
Expand Down

0 comments on commit 49681ed

Please sign in to comment.