Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Socket.ip_address_list to get loopback addresses #1318

Merged
merged 1 commit into from Aug 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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