16686 want wider masks for AMD TOM/TOM2 MSRs
[illumos-gate.git] / usr / src / man / man3xnet / connect.3xnet
blobe0c233e5ba300ce4c844327980f94f03e6b8aca7
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Portions Copyright 1989 AT&T
44 .\" Copyright 1994, The X/Open Company Ltd.  All Rights Reserved.
45 .\" Portions Copyright (c) 1998, Sun Microsystems, Inc.  All Rights Reserved.
46 .\"
47 .TH CONNECT 3XNET "Jun 10, 2002"
48 .SH NAME
49 connect \- connect a socket
50 .SH SYNOPSIS
51 .LP
52 .nf
53 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
54 #include <sys/socket.h>
56 \fBint\fR \fBconnect\fR(\fBint\fR \fIsocket\fR, \fBconst struct sockaddr *\fR\fIaddress\fR,
57     \fBsocklen_t\fR \fIaddress_len\fR);
58 .fi
60 .SH DESCRIPTION
61 .LP
62 The \fBconnect()\fR function requests a connection to be made on a socket.  The
63 function takes the following arguments:
64 .sp
65 .ne 2
66 .na
67 \fB\fIsocket\fR\fR
68 .ad
69 .RS 15n
70 Specifies the file descriptor associated with the socket.
71 .RE
73 .sp
74 .ne 2
75 .na
76 \fB\fIaddress\fR\fR
77 .ad
78 .RS 15n
79 Points to a \fBsockaddr\fR structure containing the peer address.  The length
80 and format of the address depend on the address family of the socket.
81 .RE
83 .sp
84 .ne 2
85 .na
86 \fB\fIaddress_len\fR\fR
87 .ad
88 .RS 15n
89 Specifies the length of the \fBsockaddr\fR structure pointed to by the
90 \fIaddress\fR argument.
91 .RE
93 .sp
94 .LP
95 If the socket has not already been bound to a local address,  \fBconnect()\fR
96 will bind it to an address which, unless the socket's address family  is
97 AF_UNIX, is an unused local address.
98 .sp
99 .LP
100 If the initiating socket is not connection-mode, then \fBconnect()\fR sets the
101 socket's peer address, but no connection is made.  For SOCK_DGRAM sockets, the
102 peer address identifies where all datagrams are sent on subsequent
103 \fBsend\fR(3XNET) calls, and limits the remote sender for subsequent
104 \fBrecv\fR(3XNET) calls. If \fIaddress\fR is a null address for the protocol,
105 the socket's peer address will be reset.
108 If the initiating socket is connection-mode, then \fBconnect()\fR attempts to
109 establish a connection to the address specified by the \fIaddress\fR argument.
112 If the connection cannot be established immediately and O_NONBLOCK is not set
113 for the file descriptor for the socket, \fBconnect()\fR will block for up to an
114 unspecified timeout interval until the connection is established.  If the
115 timeout interval expires before the connection is established, \fBconnect()\fR
116 will fail and the connection attempt will be aborted.  If \fBconnect()\fR is
117 interrupted by a signal that is caught while blocked waiting to establish a
118 connection, \fBconnect()\fR will fail and set \fBerrno\fR to \fBEINTR\fR, but
119 the connection request will not be aborted, and the connection will be
120 established asynchronously.
123 If the connection cannot be established immediately and O_NONBLOCK is set for
124 the file descriptor for the socket, \fBconnect()\fR will fail and set
125 \fBerrno\fR to \fBEINPROGRESS\fR, but the connection request will not be
126 aborted, and the connection will be established asynchronously. Subsequent
127 calls to \fBconnect()\fR for the same socket, before the connection is
128 established, will fail and set \fBerrno\fR to \fBEALREADY\fR.
131 When the connection has been established asynchronously, \fBselect\fR(3C) and
132 \fBpoll\fR(2) will indicate that the file descriptor for the socket is ready
133 for writing.
136 The socket in use may require the process to have appropriate privileges to use
137 the \fBconnect()\fR function.
138 .SH USAGE
140 If \fBconnect()\fR fails, the state of the socket is unspecified.  Portable
141 applications should close the file descriptor and create a new socket before
142 attempting to reconnect.
143 .SH RETURN VALUES
145 Upon successful completion, \fBconnect()\fR returns 0.  Otherwise, \(mi1 is
146 returned and \fBerrno\fR is set to indicate the error.
147 .SH ERRORS
149 The \fBconnect()\fR function will fail if:
151 .ne 2
153 \fB\fBEADDRNOTAVAIL\fR\fR
155 .RS 17n
156 The specified address is not available from the local machine.
160 .ne 2
162 \fB\fBEAFNOSUPPORT\fR\fR
164 .RS 17n
165 The specified address is not a valid address for the address family of the
166 specified socket.
170 .ne 2
172 \fB\fBEALREADY\fR\fR
174 .RS 17n
175 A connection request is already in progress for the specified socket.
179 .ne 2
181 \fB\fBEBADF\fR\fR
183 .RS 17n
184 The \fIsocket\fR argument is not a valid file descriptor.
188 .ne 2
190 \fB\fBECONNREFUSED\fR\fR
192 .RS 17n
193 The target address was not listening for connections or refused the connection
194 request.
198 .ne 2
200 \fB\fBEFAULT\fR\fR
202 .RS 17n
203 The address parameter can not be accessed.
207 .ne 2
209 \fB\fBEINPROGRESS\fR\fR
211 .RS 17n
212 O_NONBLOCK is set for the file descriptor for the socket and the connection
213 cannot be immediately established; the connection will be established
214 asynchronously.
218 .ne 2
220 \fB\fBEINTR\fR\fR
222 .RS 17n
223 The attempt to establish a connection was interrupted by delivery of a signal
224 that was caught; the connection will be established asynchronously.
228 .ne 2
230 \fB\fBEISCONN\fR\fR
232 .RS 17n
233 The specified socket is connection-mode and is already connected.
237 .ne 2
239 \fB\fBENETUNREACH\fR\fR
241 .RS 17n
242 No route to the network is present.
246 .ne 2
248 \fB\fBENOTSOCK\fR\fR
250 .RS 17n
251 The \fIsocket\fR argument does not refer to a socket.
255 .ne 2
257 \fB\fBEPROTOTYPE\fR\fR
259 .RS 17n
260 The specified address has a different type than the socket bound to the
261 specified peer address.
265 .ne 2
267 \fB\fBETIMEDOUT\fR\fR
269 .RS 17n
270 The attempt to connect timed out before a connection was made.
275 If the address family of the socket is AF_UNIX, then \fBconnect()\fR will fail
278 .ne 2
280 \fB\fBEIO\fR\fR
282 .RS 16n
283 An I/O error occurred while reading from or writing to the file system.
287 .ne 2
289 \fB\fBELOOP\fR\fR
291 .RS 16n
292 Too many symbolic links were encountered in translating the pathname in
293 \fIaddress\fR.
297 .ne 2
299 \fB\fBENAMETOOLONG\fR\fR
301 .RS 16n
302 A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
303 pathname exceeded \fIPATH_MAX\fR characters.
307 .ne 2
309 \fB\fBENOENT\fR\fR
311 .RS 16n
312 A component of the pathname does not name an existing file or the pathname is
313 an empty string.
317 .ne 2
319 \fB\fBENOTDIR\fR\fR
321 .RS 16n
322 A component of the path prefix of the pathname in \fIaddress\fR is not a
323 directory.
328 The \fBconnect()\fR function may fail if:
330 .ne 2
332 \fB\fBEACCES\fR\fR
334 .RS 16n
335 Search permission is denied for a component of the path prefix; or write access
336 to the named socket is denied.
340 .ne 2
342 \fB\fBEADDRINUSE\fR\fR
344 .RS 16n
345 Attempt to establish a connection that uses addresses that are already in use.
349 .ne 2
351 \fB\fBECONNRESET\fR\fR
353 .RS 16n
354 Remote host reset the connection request.
358 .ne 2
360 \fB\fBEHOSTUNREACH\fR\fR
362 .RS 16n
363 The destination host cannot be reached (probably because the host is down or a
364 remote router cannot reach it).
368 .ne 2
370 \fB\fBEINVAL\fR\fR
372 .RS 16n
373 The \fIaddress_len\fR argument is not a valid length for the address family; or
374 invalid address family in sockaddr structure.
378 .ne 2
380 \fB\fBENAMETOOLONG\fR\fR
382 .RS 16n
383 Pathname resolution of a symbolic link produced an intermediate result whose
384 length exceeds \fIPATH_MAX\fR.
388 .ne 2
390 \fB\fBENETDOWN\fR\fR
392 .RS 16n
393 The local interface used to reach the destination is down.
397 .ne 2
399 \fB\fBENOBUFS\fR\fR
401 .RS 16n
402 No buffer space is available.
406 .ne 2
408 \fB\fBENOSR\fR\fR
410 .RS 16n
411 There were insufficient STREAMS resources available to complete the operation.
415 .ne 2
417 \fB\fBEOPNOTSUPP\fR\fR
419 .RS 16n
420 The socket is listening and can not be connected.
423 .SH ATTRIBUTES
425 See \fBattributes\fR(7) for descriptions of the following attributes:
430 box;
431 c | c
432 l | l .
433 ATTRIBUTE TYPE  ATTRIBUTE VALUE
435 Interface Stability     Standard
437 MT-Level        MT-Safe
440 .SH SEE ALSO
442 .BR close (2),
443 .BR poll (2),
444 .BR select (3C),
445 .BR sockaddr (3SOCKET),
446 .BR accept (3XNET),
447 .BR bind (3XNET),
448 .BR getsockname (3XNET),
449 .BR send (3XNET),
450 .BR shutdown (3XNET),
451 .BR socket (3XNET),
452 .BR attributes (7),
453 .BR standards (7)