You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:44:31 UTC
[04/50] git commit: More reliable IPv6 detection
More reliable IPv6 detection
inet:gethostbyname/1 might fail for IPv6 literals, therefore check first
if host is an IPv6 address literal.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ibrowse/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ibrowse/commit/f5640f56
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ibrowse/tree/f5640f56
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ibrowse/diff/f5640f56
Branch: refs/heads/import
Commit: f5640f564b93c8ceea8d4b27fa54abe37214d3e2
Parents: 3367f00
Author: Filipe David Manana <fd...@apache.org>
Authored: Tue Apr 12 19:39:08 2011 +0100
Committer: Filipe David Manana <fd...@apache.org>
Committed: Tue Apr 12 19:39:08 2011 +0100
----------------------------------------------------------------------
src/ibrowse_http_client.erl | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ibrowse/blob/f5640f56/src/ibrowse_http_client.erl
----------------------------------------------------------------------
diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl
index c69b972..eb2bf31 100644
--- a/src/ibrowse_http_client.erl
+++ b/src/ibrowse_http_client.erl
@@ -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, _}) ->