2 .\" Copyright (c) 2012 Apple Inc. All rights reserved.
4 .\" @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 .\" This file contains Original Code and/or Modifications of Original Code
7 .\" as defined in and that are subject to the Apple Public Source License
8 .\" Version 2.0 (the 'License'). You may not use this file except in
9 .\" compliance with the License. The rights granted to you under the License
10 .\" may not be used to create, or enable the creation or redistribution of,
11 .\" unlawful or unlicensed copies of an Apple operating system, or to
12 .\" circumvent, violate, or enable the circumvention or violation of, any
13 .\" terms of an Apple operating system software license agreement.
15 .\" Please obtain a copy of the License at
16 .\" http://www.opensource.apple.com/apsl/ and read it before using this file.
18 .\" The Original Code and all software distributed under the License are
19 .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 .\" Please see the License for the specific language governing rights and
24 .\" limitations under the License.
26 .\" @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 .Nd initiate one or more connections on a socket
35 .Fd #include <sys/socket.h>
39 .Fa "const struct sockaddr *saddress"
40 .Fa "socklen_t saddress_len"
41 .Fa "const struct sockaddr *daddress"
42 .Fa "socklen_t daddress_len"
43 .Fa "unsigned int ifscope"
44 .Fa "associd_t associd"
45 .Fa "connid_t *connid"
50 is a socket. The communication domain of the socket determines the
51 availability and behavior of
55 may be used as a substitute for cases when
59 are issued in succession.
61 When the source address
63 parameter is specified,
65 binds the connection to one of the addresses, as if
67 is used. The length of
69 buffer is specified by
71 This buffer may hold more than one addresses, where each successive address
72 immediately follows the previous one. The parameter
74 may also be specified instead of
76 in order to bind the connection to the interface whose interface index
83 parameters may be specified in order to add more constraints to the connection.
85 At least one destination address must be specified in the
89 specifies the length of that buffer. When more than one addresses
90 is specified, each successive address immediately follows the previous one.
92 Each communications domain interprets the
96 parameters in its own way. When multiple addresses are specified, one
97 of the addresses will be chosen. The rules used in selecting the
98 address vary between communicaton domains.
100 Changes related to the connection state may be monitored by registering for the
101 .Dv NOTE_CONNINFO_UPDATED
103 event, using the predefined system filter
105 Details regarding the event may be retrieved by calling
108 On a multipath socket,
110 may be used multiple times, in order to establish the initial session
111 association with the peer socket upon the first connection, and to further
112 establish additional connections related to that assocication on subsequent
117 specifies the association identifier. When
119 is initially called to establish an associtation, the association identifier
120 is not yet known, and
122 must be specified. After the initial connection is established, the
123 association identifier may be retrieved using
125 and the value may then be used on subsequent
129 If the initial connection is established without any protocol-level
130 multipath association, the error
132 will be returned, and the connection can be extracted to a new socket with
133 the same properties of
138 An association representing one or more connections, or a single connection
139 may be dissolved by calling
142 On non-multipath socket,
144 behaves much like a combination of
150 must always be set to
153 Generally, non-multipath stream sockets may successfully
155 only once; datagram sockets may use
157 multiple times to change their association, after first dissolving the
158 existing association by calling
161 Upon successful completion, a value of 0 is returned and the connection
162 identifier is returned through the
164 parameter. If the initial connection establishes an association with
165 a peer socket, the association identifier may be retrieved by calling
167 Both of these identifiers are unique
170 basis. Upon failure, a value of -1 is returned and the global integer
173 is set to indicate the error.
177 system call will fail if:
181 The destination address is a broadcast address and the
187 The address is already in use.
189 .It Bq Er EADDRNOTAVAIL
190 The specified address is not available on this machine.
192 .It Bq Er EAFNOSUPPORT
193 Addresses in the specified address family cannot be used with this socket.
196 The socket is non-blocking
197 and a previous connection attempt
198 has not yet been completed.
202 is not a valid descriptor.
204 .It Bq Er ECONNREFUSED
205 The attempt to connect was ignored
206 (because the target is not listening for connections)
207 or explicitly rejected.
212 parameter specifies an area outside
213 the process address space.
215 .It Bq Er EHOSTUNREACH
216 The target host cannot be reached (e.g., down, disconnected).
218 .It Bq Er EINPROGRESS
219 The socket is non-blocking
220 and the connection cannot
221 be completed immediately.
224 for completion by selecting the socket for writing.
227 Its execution was interrupted by a signal.
230 An invalid argument was detected
233 is not valid for the address family,
234 the specified address family is invalid).
237 The socket is already connected.
240 The local network interface is not functioning.
242 .It Bq Er ENETUNREACH
243 The network isn't reachable from this host.
246 The system call was unable to allocate a needed memory buffer.
250 is not a file descriptor for a socket.
255 is listening, no connection is allowed.
258 The connection was successfully established without any protocol-level
259 association. The connection can be extracted to a new socket using
264 has a different type than the socket
265 that is bound to the specified peer address.
268 Connection establishment timed out without establishing a connection.
271 Remote host reset the connection request.
288 function call appeared in Darwin 13.0.0