diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-01-18 17:31:43 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-01-18 17:31:43 +0000 |
commit | d3a170133743122dd06d12fa6539df0b05cbaa0d (patch) | |
tree | 0dd57164a629deaf6b326df6c8427e87d28d895d /src/rabbit_networking.erl | |
parent | 59df942314b1f23d255a83c72d351fb58ad1ef79 (diff) | |
download | rabbitmq-server-d3a170133743122dd06d12fa6539df0b05cbaa0d.tar.gz |
Allow gethostaddr(Host, auto) to return more than one IP address in the case where a hostname resolves both A and AAAA.
Diffstat (limited to 'src/rabbit_networking.erl')
-rw-r--r-- | src/rabbit_networking.erl | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl index 5243f17a..3e63b2b6 100644 --- a/src/rabbit_networking.erl +++ b/src/rabbit_networking.erl @@ -144,25 +144,22 @@ start() -> getaddr(Host, Family) -> case inet_parse:address(Host) of - {ok, IPAddress} -> {IPAddress, resolve_family(IPAddress, Family)}; + {ok, IPAddress} -> [{IPAddress, resolve_family(IPAddress, Family)}]; {error, _} -> gethostaddr(Host, Family) end. gethostaddr(Host, auto) -> - case inet:getaddr(Host, inet6) of - {ok, IPAddress6} -> - {IPAddress6, inet6}; - {error, Reason6} -> - case inet:getaddr(Host, inet) of - {ok, IPAddress4} -> {IPAddress4, inet}; - {error, Reason4} -> host_lookup_error( - Host, {{ipv6, Reason6}, {ipv4, Reason4}}) - end + Lookups = [{Family, inet:getaddr(Host, Family)} || Family <- [inet, inet6]], + case [{IP, Family} || {Family, {ok, IP}} <- Lookups] of + [] -> + host_lookup_error(Host, Lookups); + IPs -> + IPs end; gethostaddr(Host, Family) -> case inet:getaddr(Host, Family) of - {ok, IPAddress} -> {IPAddress, Family}; + {ok, IPAddress} -> [{IPAddress, Family}]; {error, Reason} -> host_lookup_error(Host, Reason) end. @@ -187,14 +184,14 @@ check_tcp_listener_address(NamePrefix, {Host, Port}) -> check_tcp_listener_address(NamePrefix, {Host, Port, auto}); check_tcp_listener_address(NamePrefix, {Host, Port, Family0}) -> - {IPAddress, Family} = getaddr(Host, Family0), if is_integer(Port) andalso (Port >= 0) andalso (Port =< 65535) -> ok; true -> error_logger:error_msg("invalid port ~p - not 0..65535~n", [Port]), throw({error, {invalid_port, Port}}) end, - Name = rabbit_misc:tcp_name(NamePrefix, IPAddress, Port), - [{IPAddress, Port, Family, Name}]. + [{IPAddress, Port, Family, + rabbit_misc:tcp_name(NamePrefix, IPAddress, Port)} || + {IPAddress, Family} <- getaddr(Host, Family0)]. check_tcp_listener_address_auto(NamePrefix, Port) -> case ipv6_status(Port) of |