From 8e415cb7094e9ea4287a56daaf227666f2862ed2 Mon Sep 17 00:00:00 2001 From: Per Hedeland Date: Tue, 24 Aug 2010 19:53:45 +0200 Subject: Let an 8-tuple given as ip_address() for gen_tcp/gen_udp/gen_sctp imply 'inet6' Currently an 8-tuple representing an IPv6 address is not accepted by gen_tcp:listen/2, gen_tcp:connect/3,4, gen_udp:open/2, or gen_sctp:open/1,2, unless the 'inet6' option is also given. This means that an application that has obtained the address, e.g. from configuration that allows for either IPv4 or IPv6, must always check the type of the address before passing it to these functions. Letting the functions infer 'inet6' from the 8-tuple, in case other options do not override this choice, improves usability. --- lib/kernel/src/gen_sctp.erl | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'lib/kernel/src/gen_sctp.erl') diff --git a/lib/kernel/src/gen_sctp.erl b/lib/kernel/src/gen_sctp.erl index a1542ab507..cccfa75005 100644 --- a/lib/kernel/src/gen_sctp.erl +++ b/lib/kernel/src/gen_sctp.erl @@ -39,7 +39,7 @@ open() -> open([]). open(Opts) when is_list(Opts) -> - Mod = mod(Opts), + Mod = mod(Opts, undefined), case Mod:open(Opts) of {error,badarg} -> erlang:error(badarg, [Opts]); @@ -234,17 +234,27 @@ controlling_process(S, Pid) -> %% Utilites %% -%% Get the SCTP moudule -mod() -> inet_db:sctp_module(). +%% Get the SCTP module, but IPv6 address overrides default IPv4 +mod(Address) -> + case inet_db:sctp_module() of + inet_sctp when tuple_size(Address) =:= 8 -> + inet6_sctp; + Mod -> + Mod + end. %% Get the SCTP module, but option sctp_module|inet|inet6 overrides -mod([{sctp_module,Mod}|_]) -> +mod([{sctp_module,Mod}|_], _Address) -> Mod; -mod([inet|_]) -> +mod([inet|_], _Address) -> inet_sctp; -mod([inet6|_]) -> +mod([inet6|_], _Address) -> inet6_sctp; -mod([_|Opts]) -> - mod(Opts); -mod([]) -> - mod(). +mod([{ip, Address}|Opts], _) -> + mod(Opts, Address); +mod([{ifaddr, Address}|Opts], _) -> + mod(Opts, Address); +mod([_|Opts], Address) -> + mod(Opts, Address); +mod([], Address) -> + mod(Address). -- cgit v1.2.3