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/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
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.
25 .\" This notice shall appear on any product containing this material.
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.
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.
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]
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.
47 .TH CONNECT 3XNET "Jun 10, 2002"
49 connect \- connect a socket
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);
62 The \fBconnect()\fR function requests a connection to be made on a socket. The
63 function takes the following arguments:
70 Specifies the file descriptor associated with the socket.
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.
86 \fB\fIaddress_len\fR\fR
89 Specifies the length of the \fBsockaddr\fR structure pointed to by the
90 \fIaddress\fR argument.
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.
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
136 The socket in use may require the process to have appropriate privileges to use
137 the \fBconnect()\fR function.
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.
145 Upon successful completion, \fBconnect()\fR returns 0. Otherwise, \(mi1 is
146 returned and \fBerrno\fR is set to indicate the error.
149 The \fBconnect()\fR function will fail if:
153 \fB\fBEADDRNOTAVAIL\fR\fR
156 The specified address is not available from the local machine.
162 \fB\fBEAFNOSUPPORT\fR\fR
165 The specified address is not a valid address for the address family of the
175 A connection request is already in progress for the specified socket.
184 The \fIsocket\fR argument is not a valid file descriptor.
190 \fB\fBECONNREFUSED\fR\fR
193 The target address was not listening for connections or refused the connection
203 The address parameter can not be accessed.
209 \fB\fBEINPROGRESS\fR\fR
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
223 The attempt to establish a connection was interrupted by delivery of a signal
224 that was caught; the connection will be established asynchronously.
233 The specified socket is connection-mode and is already connected.
239 \fB\fBENETUNREACH\fR\fR
242 No route to the network is present.
251 The \fIsocket\fR argument does not refer to a socket.
257 \fB\fBEPROTOTYPE\fR\fR
260 The specified address has a different type than the socket bound to the
261 specified peer address.
267 \fB\fBETIMEDOUT\fR\fR
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
283 An I/O error occurred while reading from or writing to the file system.
292 Too many symbolic links were encountered in translating the pathname in
299 \fB\fBENAMETOOLONG\fR\fR
302 A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
303 pathname exceeded \fIPATH_MAX\fR characters.
312 A component of the pathname does not name an existing file or the pathname is
322 A component of the path prefix of the pathname in \fIaddress\fR is not a
328 The \fBconnect()\fR function may fail if:
335 Search permission is denied for a component of the path prefix; or write access
336 to the named socket is denied.
342 \fB\fBEADDRINUSE\fR\fR
345 Attempt to establish a connection that uses addresses that are already in use.
351 \fB\fBECONNRESET\fR\fR
354 Remote host reset the connection request.
360 \fB\fBEHOSTUNREACH\fR\fR
363 The destination host cannot be reached (probably because the host is down or a
364 remote router cannot reach it).
373 The \fIaddress_len\fR argument is not a valid length for the address family; or
374 invalid address family in sockaddr structure.
380 \fB\fBENAMETOOLONG\fR\fR
383 Pathname resolution of a symbolic link produced an intermediate result whose
384 length exceeds \fIPATH_MAX\fR.
393 The local interface used to reach the destination is down.
402 No buffer space is available.
411 There were insufficient STREAMS resources available to complete the operation.
417 \fB\fBEOPNOTSUPP\fR\fR
420 The socket is listening and can not be connected.
425 See \fBattributes\fR(5) for descriptions of the following attributes:
433 ATTRIBUTE TYPE ATTRIBUTE VALUE
435 Interface Stability Standard
442 \fBsockaddr\fR(3SOCKET),
443 \fBclose\fR(2), \fBpoll\fR(2), \fBaccept\fR(3XNET), \fBbind\fR(3XNET),
444 \fBgetsockname\fR(3XNET), \fBselect\fR(3C), \fBsend\fR(3XNET),
445 \fBshutdown\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),