Przeglądaj źródła

More reliable IPv6 detection

inet:gethostbyname/1 might fail for IPv6 literals, therefore check first
if host is an IPv6 address literal.
pull/34/head
Filipe David Manana 14 lat temu
rodzic
commit
f5640f564b
1 zmienionych plików z 18 dodań i 3 usunięć
  1. +18
    -3
      src/ibrowse_http_client.erl

+ 18
- 3
src/ibrowse_http_client.erl Wyświetl plik

@ -496,10 +496,10 @@ do_connect(Host, Port, Options, _State, Timeout) ->
get_sock_options(Host, Options, SSLOptions) ->
Caller_socket_options = get_value(socket_options, Options, []),
Ipv6Options = case inet:gethostbyname(Host) of
{ok, #hostent{h_addrtype = inet6}} ->
Ipv6Options = case is_ipv6_host(Host) of
true ->
[inet6];
_ ->
false ->
[]
end,
Other_sock_options = filter_sock_options(SSLOptions ++ Caller_socket_options ++ Ipv6Options),
@ -510,6 +510,21 @@ get_sock_options(Host, Options, SSLOptions) ->
[binary, {active, false} | Other_sock_options]
end.
is_ipv6_host(Host) ->
case inet_parse:address(Host) of
{ok, {_, _, _, _, _, _, _, _}} ->
true;
{ok, {_, _, _, _}} ->
false;
_ ->
case inet:gethostbyname(Host) of
{ok, #hostent{h_addrtype = inet6}} ->
true;
_ ->
false
end
end.
%% We don't want the caller to specify certain options
filter_sock_options(Opts) ->
lists:filter(fun({active, _}) ->

Ładowanie…
Anuluj
Zapisz