Skip to content

Commit 7f77bb7

Browse files
committed
Support IPv6 :listen_ip values
Using `inet:parse_address` allows parsing an IPv6 address, e.g. `"::1"`. This commit also adds support for passing raw tuples as the address.
1 parent 6436504 commit 7f77bb7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/bypass/instance.ex

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,21 @@ defmodule Bypass.Instance do
456456
# and limit the range of interfaces it will listen on to just
457457
# the configured interface. Loopback is a default interface.
458458
defp listen_ip do
459-
Application.get_env(:bypass, :listen_ip, "127.0.0.1")
460-
|> String.split(".")
461-
|> Enum.map(&Integer.parse/1)
462-
|> Enum.map(&elem(&1, 0))
463-
|> List.to_tuple()
459+
case Application.get_env(:bypass, :listen_ip, {127, 0, 0, 1}) do
460+
listen_ip when is_tuple(listen_ip) ->
461+
listen_ip
462+
463+
listen_ip ->
464+
listen_ip
465+
|> to_charlist()
466+
|> :inet.parse_address()
467+
|> case do
468+
{:ok, listen_ip} ->
469+
listen_ip
470+
471+
{:error, :einval} ->
472+
raise ArgumentError, "invalid listen_ip: #{inspect(listen_ip)}"
473+
end
474+
end
464475
end
465476
end

0 commit comments

Comments
 (0)