aboutsummaryrefslogtreecommitdiffstats
path: root/lib/eldap/src/eldap.erl
diff options
context:
space:
mode:
authorEdwin Fine <[email protected]>2014-02-09 13:27:50 -0500
committerEdwin Fine <[email protected]>2014-02-09 13:27:50 -0500
commit02d46a1464c3bcd69b0de046c21146ccc6bf10c4 (patch)
tree03b493c70a8e697f69dc3fb62d98e8300e7fee89 /lib/eldap/src/eldap.erl
parent0cbf6ec7444df2c0441debc6bcd5aba0bbc7104d (diff)
downloadotp-02d46a1464c3bcd69b0de046c21146ccc6bf10c4.tar.gz
otp-02d46a1464c3bcd69b0de046c21146ccc6bf10c4.tar.bz2
otp-02d46a1464c3bcd69b0de046c21146ccc6bf10c4.zip
Add support for IPv6 connections
Currently, eldap assumes that only IPv4 will be used. This change enables callers to use IPv6 by including the [inet6] option in the eldap:open/2 options list. This adds inet6 to the gen_tcp or ssl connect. For backward compatibility, [inet] is the default if inet6 is omitted.
Diffstat (limited to 'lib/eldap/src/eldap.erl')
-rw-r--r--lib/eldap/src/eldap.erl21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/eldap/src/eldap.erl b/lib/eldap/src/eldap.erl
index af5bf94c97..f0f8b39427 100644
--- a/lib/eldap/src/eldap.erl
+++ b/lib/eldap/src/eldap.erl
@@ -45,9 +45,10 @@
log, % User provided log function
timeout = infinity, % Request timeout
anon_auth = false, % Allow anonymous authentication
- ldaps = false, % LDAP/LDAPS
+ ldaps = false, % LDAP/LDAPS
using_tls = false, % true if LDAPS or START_TLS executed
- tls_opts = [] % ssl:ssloption()
+ tls_opts = [], % ssl:ssloption()
+ tcp_opts = [] % inet6 support
}).
%%% For debug purposes
@@ -372,6 +373,8 @@ parse_args([{sslopts, Opts}|T], Cpid, Data) when is_list(Opts) ->
parse_args(T, Cpid, Data#eldap{ldaps = true, using_tls=true, tls_opts = Opts ++ Data#eldap.tls_opts});
parse_args([{sslopts, _}|T], Cpid, Data) ->
parse_args(T, Cpid, Data);
+parse_args([{tcpopts, Opts}|T], Cpid, Data) when is_list(Opts) ->
+ parse_args(T, Cpid, Data#eldap{tcp_opts = inet6_opt(Opts) ++ Data#eldap.tcp_opts});
parse_args([{log, F}|T], Cpid, Data) when is_function(F) ->
parse_args(T, Cpid, Data#eldap{log = F});
parse_args([{log, _}|T], Cpid, Data) ->
@@ -382,6 +385,14 @@ parse_args([H|_], Cpid, _) ->
parse_args([], _, Data) ->
Data.
+inet6_opt(Opts) ->
+ case proplists:get_value(inet6, Opts) of
+ true ->
+ [inet6];
+ _ ->
+ []
+ end.
+
%%% Try to connect to the hosts in the listed order,
%%% and stop with the first one to which a successful
%%% connection is made.
@@ -401,9 +412,11 @@ try_connect([],_) ->
{error,"connect failed"}.
do_connect(Host, Data, Opts) when Data#eldap.ldaps == false ->
- gen_tcp:connect(Host, Data#eldap.port, Opts, Data#eldap.timeout);
+ gen_tcp:connect(Host, Data#eldap.port, Opts ++ Data#eldap.tcp_opts,
+ Data#eldap.timeout);
do_connect(Host, Data, Opts) when Data#eldap.ldaps == true ->
- ssl:connect(Host, Data#eldap.port, Opts++Data#eldap.tls_opts).
+ ssl:connect(Host, Data#eldap.port,
+ Opts ++ Data#eldap.tls_opts ++ Data#eldap.tcp_opts).
loop(Cpid, Data) ->
receive