mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-10 17:15:09 +08:00
The first address for a shortname must be the one that matches
This commit is contained in:
parent
0cdfe8b185
commit
8a0d218cbe
1 changed files with 8 additions and 12 deletions
|
@ -87,8 +87,9 @@ defmodule Livebook.Application do
|
|||
{:error, :nxdomain} ->
|
||||
invalid_hostname!("your hostname \"#{hostname}\" does not resolve to an IP address")
|
||||
|
||||
{:ok, hostent(h_addrtype: :inet, h_addr_list: addresses)} ->
|
||||
unless any_loopback?(addresses) or any_if?(addresses) do
|
||||
# We only try the first address, so that's the one we validate.
|
||||
{:ok, hostent(h_addrtype: :inet, h_addr_list: [address | _])} ->
|
||||
unless inet_loopback?(address) or inet_if?(address) do
|
||||
invalid_hostname!(
|
||||
"your hostname \"#{hostname}\" does not resolve to a loopback address (127.0.0.0/8)"
|
||||
)
|
||||
|
@ -100,19 +101,14 @@ defmodule Livebook.Application do
|
|||
end
|
||||
end
|
||||
|
||||
defp any_loopback?(addresses) do
|
||||
Enum.any?(addresses, &match?({127, _, _, _}, &1))
|
||||
defp inet_loopback?(address) do
|
||||
match?({127, _, _, _}, address)
|
||||
end
|
||||
|
||||
defp any_if?(addresses) do
|
||||
defp inet_if?(address) do
|
||||
case :inet.getifaddrs() do
|
||||
{:ok, addrs} ->
|
||||
Enum.any?(addrs, fn {_name, flags} ->
|
||||
Enum.any?(flags, fn {key, value} -> key == :addr and value in addresses end)
|
||||
end)
|
||||
|
||||
_ ->
|
||||
false
|
||||
{:ok, addrs} -> Enum.any?(addrs, fn {_name, flags} -> {:addr, address} in flags end)
|
||||
_ -> false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue