@@ -112,11 +112,32 @@ open_ldap_connection([Host|Hosts], Port, SSL, Timeout, Settings) ->
112112 end ,
113113 % % Note: timeout option sets not only connect timeout but a timeout for any
114114 % % request to ldap server
115- case eldap :open ([Host ], [{port , Port }, {timeout , Timeout } | SSLOpts ]) of
115+ Opts = [{port , Port }, {timeout , Timeout } | SSLOpts ],
116+ case do_open_ldap_connection (Host , Opts ) of
116117 {ok , Handle } -> {ok , Handle , Host };
117118 {error , _ } -> open_ldap_connection (Hosts , Port , SSL , Timeout , Settings )
118119 end .
119120
121+ do_open_ldap_connection (Host , Opts ) ->
122+ ToTry = case {misc :is_raw_ip (Host ), misc :is_raw_ipv6 (Host )} of
123+ {_ , true } ->
124+ [inet6 ];
125+ {true , _ } ->
126+ [inet ];
127+ _ ->
128+ case misc :get_net_family () of
129+ inet ->
130+ [inet , inet6 ];
131+ inet6 ->
132+ [inet6 , inet ]
133+ end
134+ end ,
135+ lists :foldl (fun (_Afamily , {ok , Handle }) ->
136+ {ok , Handle };
137+ (Afamily , _ ) ->
138+ eldap :open ([Host ], [{tcpopts , [Afamily ]} | Opts ])
139+ end , undefined , ToTry ).
140+
120141with_connection (Settings , Fun ) ->
121142 Hosts = proplists :get_value (hosts , Settings ),
122143 Port = proplists :get_value (port , Settings ),
0 commit comments