]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/connectx.2
xnu-2782.20.48.tar.gz
[apple/xnu.git] / bsd / man / man2 / connectx.2
CommitLineData
39236c6e
A
1.\"
2.\" Copyright (c) 2012 Apple Inc. All rights reserved.
3.\"
4.\" @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5.\"
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.
14.\"
15.\" Please obtain a copy of the License at
16.\" http://www.opensource.apple.com/apsl/ and read it before using this file.
17.\"
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.
25.\"
26.\" @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27.\"
28.Dd November 14, 2012
29.Dt CONNECTX 2
30.Os Darwin
31.Sh NAME
32.Nm connectx
33.Nd initiate one or more connections on a socket
34.Sh SYNOPSIS
35.Fd #include <sys/socket.h>
36.Ft int
37.Fo connectx
38.Fa "int socket"
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"
46.Fc
47.Sh DESCRIPTION
48The parameter
49.Fa socket
50is a socket. The communication domain of the socket determines the
51availability and behavior of
52.Fn connectx .
53In general,
54.Fn connectx
55may be used as a substitute for cases when
56.Xr bind 2
57and
58.Xr connect 2
59are issued in succession.
60.Pp
61When the source address
62.Fa saddress
63parameter is specified,
64.Fn connectx
65binds the connection to one of the addresses, as if
66.Xr bind 2
67is used. The length of
68.Fa saddress
69buffer is specified by
70.Fa saddress_len .
71This buffer may hold more than one addresses, where each successive address
72immediately follows the previous one. The parameter
73.Fa ifscope
74may also be specified instead of
75.Fa saddress ,
76in order to bind the connection to the interface whose interface index
77equals to
78.Fa ifscope .
79Both
80.Fa saddress
81and
82.Fa ifscope
83parameters may be specified in order to add more constraints to the connection.
84.Pp
85At least one destination address must be specified in the
86.Fa daddress
87parameter. The
88.Fa daddress_len
89specifies the length of that buffer. When more than one addresses
90is specified, each successive address immediately follows the previous one.
91.Pp
92Each communications domain interprets the
93.Fa saddress
94and
95.Fa daddress
96parameters in its own way. When multiple addresses are specified, one
97of the addresses will be chosen. The rules used in selecting the
98address vary between communicaton domains.
99.Pp
100Changes related to the connection state may be monitored by registering for the
101.Dv NOTE_CONNINFO_UPDATED
102.Xr kqueue 2
103event, using the predefined system filter
104.Dv EVFILT_SOCK .
105Details regarding the event may be retrieved by calling
106.Xr getconninfo 3 .
107.Sh MULTIPATH
108On a multipath socket,
109.Fn connectx
110may be used multiple times, in order to establish the initial session
111association with the peer socket upon the first connection, and to further
112establish additional connections related to that assocication on subsequent
113ones.
114.Pp
115The parameter
116.Fa associd
117specifies the association identifier. When
118.Fn connectx
119is initially called to establish an associtation, the association identifier
120is not yet known, and
121.Dv ASSOCID_ANY
122must be specified. After the initial connection is established, the
123association identifier may be retrieved using
124.Xr getassocids 3 ,
125and the value may then be used on subsequent
126.Fn connectx
127calls.
128.Pp
129If the initial connection is established without any protocol-level
130multipath association, the error
131.Er EPROTO
132will be returned, and the connection can be extracted to a new socket with
133the same properties of
134.Fa socket ,
135by calling
136.Xr peeloff 2 .
137.Pp
138An association representing one or more connections, or a single connection
139may be dissolved by calling
140.Xr disconnectx 2 .
141.Sh NON-MULTIPATH
142On non-multipath socket,
143.Fn connectx
144behaves much like a combination of
145.Xr bind 2
146and
147.Xr connect 2 .
148The parameter
149.Fa associd
150must always be set to
151.Dv ASSOCID_ANY .
152.Pp
153Generally, non-multipath stream sockets may successfully
154.Fn connectx
155only once; datagram sockets may use
156.Fn connectx
157multiple times to change their association, after first dissolving the
158existing association by calling
159.Xr disconnectx 2 .
160.Sh RETURN VALUES
161Upon successful completion, a value of 0 is returned and the connection
162identifier is returned through the
163.Fa connid
164parameter. If the initial connection establishes an association with
165a peer socket, the association identifier may be retrieved by calling
166.Xr getassocids 2 .
167Both of these identifiers are unique
168on a per
169.Fa socket
170basis. Upon failure, a value of -1 is returned and the global integer
171variable
172.Va errno
173is set to indicate the error.
174.Sh ERRORS
175The
176.Fn connectx
177system call will fail if:
178.Bl -tag -width Er
179.\" ==========
180.It Bq Er EACCES
181The destination address is a broadcast address and the
182socket option
183.Dv SO_BROADCAST
184is not set.
185.\" ==========
186.It Bq Er EADDRINUSE
187The address is already in use.
188.\" ==========
189.It Bq Er EADDRNOTAVAIL
190The specified address is not available on this machine.
191.\" ==========
192.It Bq Er EAFNOSUPPORT
193Addresses in the specified address family cannot be used with this socket.
194.\" ==========
195.It Bq Er EALREADY
196The socket is non-blocking
197and a previous connection attempt
198has not yet been completed.
199.\" ==========
200.It Bq Er EBADF
201.Fa socket
202is not a valid descriptor.
203.\" ==========
204.It Bq Er ECONNREFUSED
205The attempt to connect was ignored
206(because the target is not listening for connections)
207or explicitly rejected.
208.\" ==========
209.It Bq Er EFAULT
210The
211.Fa address
212parameter specifies an area outside
213the process address space.
214.\" ==========
215.It Bq Er EHOSTUNREACH
216The target host cannot be reached (e.g., down, disconnected).
217.\" ==========
218.It Bq Er EINPROGRESS
219The socket is non-blocking
220and the connection cannot
221be completed immediately.
222It is possible to
223.Xr select 2
224for completion by selecting the socket for writing.
225.\" ==========
226.It Bq Er EINTR
227Its execution was interrupted by a signal.
228.\" ==========
229.It Bq Er EINVAL
230An invalid argument was detected
231(e.g.,
232.Fa address_len
233is not valid for the address family,
234the specified address family is invalid).
235.\" ==========
236.It Bq Er EISCONN
237The socket is already connected.
238.\" ==========
239.It Bq Er ENETDOWN
240The local network interface is not functioning.
241.\" ==========
242.It Bq Er ENETUNREACH
243The network isn't reachable from this host.
244.\" ==========
245.It Bq Er ENOBUFS
246The system call was unable to allocate a needed memory buffer.
247.\" ==========
248.It Bq Er ENOTSOCK
249.Fa socket
250is not a file descriptor for a socket.
251.\" ==========
252.It Bq Er EOPNOTSUPP
253Because
254.Fa socket
255is listening, no connection is allowed.
256.\" ==========
257.It Bq Er EPROTO
258The connection was successfully established without any protocol-level
259association. The connection can be extracted to a new socket using
260.Xr peeloff 2 .
261.\" ==========
262.It Bq Er EPROTOTYPE
263.Fa address
264has a different type than the socket
265that is bound to the specified peer address.
266.\" ==========
267.It Bq Er ETIMEDOUT
268Connection establishment timed out without establishing a connection.
269.\" ==========
270.It Bq Er ECONNRESET
271Remote host reset the connection request.
272.Sh SEE ALSO
273.Xr accept 2 ,
274.Xr bind 2 ,
275.Xr connect 2 ,
276.Xr disconnectx 2 ,
277.Xr kqueue 2 ,
278.Xr peeloff 2 ,
279.Xr select 2 ,
280.Xr socket 2 ,
281.Xr getassocids 3 ,
282.Xr getconnids 3 ,
283.Xr getconninfo 3 ,
284.Xr compat 5
285.Sh HISTORY
286The
287.Fn connectx
288function call appeared in Darwin 13.0.0