1 .\" $NetBSD: connect.2,v 1.28 2010/05/31 12:16:20 njoly Exp $
3 .\" Copyright (c) 1983, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)connect.2 8.1 (Berkeley) 6/4/93
37 .Nd initiate a connection on a socket
43 .Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen"
50 this call specifies the peer with which the socket is to be associated;
51 this address is that to which datagrams are to be sent,
52 and the only address from which datagrams are to be received.
53 If the socket is of type
55 this call attempts to make a connection to
57 The other socket is specified by
59 which is an address in the communications space of the socket.
61 indicates the amount of space pointed to by
64 Each communications space interprets the
66 parameter in its own way.
67 Generally, stream sockets may successfully
69 only once; datagram sockets may use
71 multiple times to change their association.
72 Datagram sockets may dissolve the association
73 by connecting to an invalid address, such as a null address.
77 call is interrupted by a signal, it will return with errno set to
79 and the connection attempt will proceed as if the socket was non-blocking.
85 If the connection or binding succeeds, 0 is returned.
86 Otherwise a \-1 is returned, and a more specific error
96 is not a valid descriptor.
99 is a descriptor for a file, not a socket.
100 .It Bq Er EADDRNOTAVAIL
101 The specified address is not available on this machine.
102 .It Bq Er EAFNOSUPPORT
103 Addresses in the specified address family cannot be used with this socket.
105 The socket is already connected.
107 Connection establishment timed out without establishing a connection.
108 .It Bq Er ECONNREFUSED
109 The attempt to connect was forcefully rejected.
110 .It Bq Er ENETUNREACH
111 The network isn't reachable from this host.
113 The address is already in use.
117 parameter specifies an area outside
118 the process address space.
119 .It Bq Er EINPROGRESS
120 The socket is non-blocking and the connection cannot be completed immediately.
125 for completion by selecting or polling the socket for writing.
126 The success or failure of the connect operation may be determined by using
128 to read the socket error status with the
133 The returned socket error status is zero on success, or one of the
134 error codes listed here on failure.
136 Either the socket is non-blocking mode or a previous call to
138 was interrupted by a signal, and the connection attempt has not yet
141 The connection attempt was interrupted by a signal.
144 The following errors are specific to connecting names in the
147 These errors may not apply in future versions of the
152 A component of the path prefix is not a directory.
153 .It Bq Er ENAMETOOLONG
154 A component of a pathname exceeded
156 characters, or an entire path name exceeded
160 The named socket does not exist.
162 Search permission is denied for a component of the path prefix, or
163 write access to the named socket is denied.
165 Too many symbolic links were encountered in translating the pathname.
177 function call appeared in