4
%% Copyright Ericsson AB 2007-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 2007-2010. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
27
27
-include("inet_sctp.hrl").
29
29
-export([open/0,open/1,open/2,close/1]).
30
-export([listen/2,connect/4,connect/5]).
30
-export([listen/2,connect/4,connect/5,connect_init/4,connect_init/5]).
31
31
-export([eof/2,abort/2]).
32
32
-export([send/3,send/4,recv/1,recv/2]).
33
33
-export([error_string/1]).
80
80
connect(S, Addr, Port, Opts) ->
81
81
connect(S, Addr, Port, Opts, infinity).
83
connect(S, Addr, Port, Opts, Timeout) when is_port(S), is_list(Opts) ->
83
connect(S, Addr, Port, Opts, Timeout) ->
84
case do_connect(S, Addr, Port, Opts, Timeout, true) of
86
erlang:error(badarg, [S,Addr,Port,Opts,Timeout]);
91
connect_init(S, Addr, Port, Opts) ->
92
connect_init(S, Addr, Port, Opts, infinity).
94
connect_init(S, Addr, Port, Opts, Timeout) ->
95
case do_connect(S, Addr, Port, Opts, Timeout, false) of
97
erlang:error(badarg, [S,Addr,Port,Opts,Timeout]);
102
do_connect(S, Addr, Port, Opts, Timeout, ConnWait) when is_port(S), is_list(Opts) ->
84
103
case inet_db:lookup_socket(S) of
86
105
case Mod:getserv(Port) of
90
109
try Mod:getaddr(Addr, Timer) of
92
Mod:connect(S, IP, Port, Opts, Timer);
111
ConnectTimer = if ConnWait == false ->
116
Mod:connect(S, IP, Port, Opts, ConnectTimer);
95
119
inet:stop_timer(Timer)
99
erlang:error(badarg, [S,Addr,Port,Opts,Timeout])
105
connect(S, Addr, Port, Opts, Timeout) ->
106
erlang:error(badarg, [S,Addr,Port,Opts,Timeout]).
129
do_connect(_S, _Addr, _Port, _Opts, _Timeout, _ConnWait) ->
142
166
when is_port(S), is_integer(Stream) ->
143
167
case inet_db:lookup_socket(S) of
145
Mod:sendmsg(S, #sctp_sndrcvinfo{
147
assoc_id = AssocId}, Data);
169
Mod:send(S, AssocId, Stream, Data);
150
172
send(S, AssocId, Stream, Data)
151
173
when is_port(S), is_integer(AssocId), is_integer(Stream) ->
152
174
case inet_db:lookup_socket(S) of
154
Mod:sendmsg(S, #sctp_sndrcvinfo{
156
assoc_id = AssocId}, Data);
176
Mod:send(S, AssocId, Stream, Data);
159
179
send(S, AssocChange, Stream, Data) ->
217
%% Get the SCTP moudule
218
mod() -> inet_db:sctp_module().
237
%% Get the SCTP module, but IPv6 address overrides default IPv4
239
case inet_db:sctp_module() of
240
inet_sctp when tuple_size(Address) =:= 8 ->
220
246
%% Get the SCTP module, but option sctp_module|inet|inet6 overrides
221
mod([{sctp_module,Mod}|_]) ->
247
mod([{sctp_module,Mod}|_], _Address) ->
249
mod([inet|_], _Address) ->
251
mod([inet6|_], _Address) ->
253
mod([{ip, Address}|Opts], _) ->
255
mod([{ifaddr, Address}|Opts], _) ->
257
mod([_|Opts], Address) ->