2 .\" Copyright 1994, The X/Open Company Ltd. All Rights Reserved Portions Copyright 1989 AT&T Portions Copyright (c) 1998, Sun Microsystems, Inc. All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\" This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH CONNECT 3XNET "Jun 10, 2002"
12 connect \- connect a socket
16 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
17 #include <sys/socket.h>
19 \fBint\fR \fBconnect\fR(\fBint\fR \fIsocket\fR, \fBconst struct sockaddr *\fR\fIaddress\fR,
20 \fBsocklen_t\fR \fIaddress_len\fR);
25 The \fBconnect()\fR function requests a connection to be made on a socket. The
26 function takes the following arguments:
33 Specifies the file descriptor associated with the socket.
42 Points to a \fBsockaddr\fR structure containing the peer address. The length
43 and format of the address depend on the address family of the socket.
49 \fB\fIaddress_len\fR\fR
52 Specifies the length of the \fBsockaddr\fR structure pointed to by the
53 \fIaddress\fR argument.
58 If the socket has not already been bound to a local address, \fBconnect()\fR
59 will bind it to an address which, unless the socket's address family is
60 AF_UNIX, is an unused local address.
63 If the initiating socket is not connection-mode, then \fBconnect()\fR sets the
64 socket's peer address, but no connection is made. For SOCK_DGRAM sockets, the
65 peer address identifies where all datagrams are sent on subsequent
66 \fBsend\fR(3XNET) calls, and limits the remote sender for subsequent
67 \fBrecv\fR(3XNET) calls. If \fIaddress\fR is a null address for the protocol,
68 the socket's peer address will be reset.
71 If the initiating socket is connection-mode, then \fBconnect()\fR attempts to
72 establish a connection to the address specified by the \fIaddress\fR argument.
75 If the connection cannot be established immediately and O_NONBLOCK is not set
76 for the file descriptor for the socket, \fBconnect()\fR will block for up to an
77 unspecified timeout interval until the connection is established. If the
78 timeout interval expires before the connection is established, \fBconnect()\fR
79 will fail and the connection attempt will be aborted. If \fBconnect()\fR is
80 interrupted by a signal that is caught while blocked waiting to establish a
81 connection, \fBconnect()\fR will fail and set \fBerrno\fR to \fBEINTR\fR, but
82 the connection request will not be aborted, and the connection will be
83 established asynchronously.
86 If the connection cannot be established immediately and O_NONBLOCK is set for
87 the file descriptor for the socket, \fBconnect()\fR will fail and set
88 \fBerrno\fR to \fBEINPROGRESS\fR, but the connection request will not be
89 aborted, and the connection will be established asynchronously. Subsequent
90 calls to \fBconnect()\fR for the same socket, before the connection is
91 established, will fail and set \fBerrno\fR to \fBEALREADY\fR.
94 When the connection has been established asynchronously, \fBselect\fR(3C) and
95 \fBpoll\fR(2) will indicate that the file descriptor for the socket is ready
99 The socket in use may require the process to have appropriate privileges to use
100 the \fBconnect()\fR function.
103 If \fBconnect()\fR fails, the state of the socket is unspecified. Portable
104 applications should close the file descriptor and create a new socket before
105 attempting to reconnect.
108 Upon successful completion, \fBconnect()\fR returns 0. Otherwise, \(mi1 is
109 returned and \fBerrno\fR is set to indicate the error.
112 The \fBconnect()\fR function will fail if:
116 \fB\fBEADDRNOTAVAIL\fR\fR
119 The specified address is not available from the local machine.
125 \fB\fBEAFNOSUPPORT\fR\fR
128 The specified address is not a valid address for the address family of the
138 A connection request is already in progress for the specified socket.
147 The \fIsocket\fR argument is not a valid file descriptor.
153 \fB\fBECONNREFUSED\fR\fR
156 The target address was not listening for connections or refused the connection
166 The address parameter can not be accessed.
172 \fB\fBEINPROGRESS\fR\fR
175 O_NONBLOCK is set for the file descriptor for the socket and the connection
176 cannot be immediately established; the connection will be established
186 The attempt to establish a connection was interrupted by delivery of a signal
187 that was caught; the connection will be established asynchronously.
196 The specified socket is connection-mode and is already connected.
202 \fB\fBENETUNREACH\fR\fR
205 No route to the network is present.
214 The \fIsocket\fR argument does not refer to a socket.
220 \fB\fBEPROTOTYPE\fR\fR
223 The specified address has a different type than the socket bound to the
224 specified peer address.
230 \fB\fBETIMEDOUT\fR\fR
233 The attempt to connect timed out before a connection was made.
238 If the address family of the socket is AF_UNIX, then \fBconnect()\fR will fail
246 An I/O error occurred while reading from or writing to the file system.
255 Too many symbolic links were encountered in translating the pathname in
262 \fB\fBENAMETOOLONG\fR\fR
265 A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
266 pathname exceeded \fIPATH_MAX\fR characters.
275 A component of the pathname does not name an existing file or the pathname is
285 A component of the path prefix of the pathname in \fIaddress\fR is not a
291 The \fBconnect()\fR function may fail if:
298 Search permission is denied for a component of the path prefix; or write access
299 to the named socket is denied.
305 \fB\fBEADDRINUSE\fR\fR
308 Attempt to establish a connection that uses addresses that are already in use.
314 \fB\fBECONNRESET\fR\fR
317 Remote host reset the connection request.
323 \fB\fBEHOSTUNREACH\fR\fR
326 The destination host cannot be reached (probably because the host is down or a
327 remote router cannot reach it).
336 The \fIaddress_len\fR argument is not a valid length for the address family; or
337 invalid address family in sockaddr structure.
343 \fB\fBENAMETOOLONG\fR\fR
346 Pathname resolution of a symbolic link produced an intermediate result whose
347 length exceeds \fIPATH_MAX\fR.
356 The local interface used to reach the destination is down.
365 No buffer space is available.
374 There were insufficient STREAMS resources available to complete the operation.
380 \fB\fBEOPNOTSUPP\fR\fR
383 The socket is listening and can not be connected.
388 See \fBattributes\fR(5) for descriptions of the following attributes:
396 ATTRIBUTE TYPE ATTRIBUTE VALUE
398 Interface Stability Standard
405 \fBsockaddr\fR(3SOCKET),
406 \fBclose\fR(2), \fBpoll\fR(2), \fBaccept\fR(3XNET), \fBbind\fR(3XNET),
407 \fBgetsockname\fR(3XNET), \fBselect\fR(3C), \fBsend\fR(3XNET),
408 \fBshutdown\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),