Skip to content

Commit

Permalink
Use Socket.ip_address_list to get loopback addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Aug 3, 2017
1 parent d31d68a commit d2e9d7d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/puma/binder.rb
Expand Up @@ -245,9 +245,10 @@ def parse(binds, logger)
end
end

def localhost_addresses
addrs = TCPSocket.gethostbyname "localhost"
addrs[3..-1].uniq
def loopback_addresses
Socket.ip_address_list.select do |addrinfo|
addrinfo.ipv6_loopback? || addrinfo.ipv4_loopback?
end.map { |addrinfo| addrinfo.ip_address }.uniq
end

# Tell the server to listen on host +host+, port +port+.
Expand All @@ -259,7 +260,7 @@ def localhost_addresses
#
def add_tcp_listener(host, port, optimize_for_latency=true, backlog=1024)
if host == "localhost"
localhost_addresses.each do |addr|
loopback_addresses.each do |addr|
add_tcp_listener addr, port, optimize_for_latency, backlog
end
return
Expand Down Expand Up @@ -298,7 +299,7 @@ def add_ssl_listener(host, port, ctx,
MiniSSL.check

if host == "localhost"
localhost_addresses.each do |addr|
loopback_addresses.each do |addr|
add_ssl_listener addr, port, ctx, optimize_for_latency, backlog
end
return
Expand Down

0 comments on commit d2e9d7d

Please sign in to comment.