1 .\" $NetBSD: connect.2,v 1.8 1995/10/12 15:40:48 jtc 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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)connect.2 8.1 (Berkeley) 6/4/93
41 .Nd initiate a connection on a socket
43 .Fd #include <sys/types.h>
44 .Fd #include <sys/socket.h>
48 .Fa "const struct sockaddr *address"
49 .Fa "socklen_t address_len"
57 this call specifies the peer with which the socket is to be associated;
58 this address is that to which datagrams are to be sent,
59 and the only address from which datagrams are to be received.
60 If the socket is of type
62 this call attempts to make a connection to
64 The other socket is specified by
66 which is an address in the communications space of the socket.
68 Each communications space interprets the
70 parameter in its own way.
71 Generally, stream sockets may successfully
73 only once; datagram sockets may use
75 multiple times to change their association.
76 Datagram sockets may dissolve the association
79 or by connecting to an invalid address, such as a null address
81 the address family set to
85 will be harmlessly returned).
87 Upon successful completion, a value of 0 is returned.
88 Otherwise, a value of -1 is returned and the global integer variable
90 is set to indicate the error.
94 system call will fail if:
98 The destination address is a broadcast address and the
104 The address is already in use.
106 .It Bq Er EADDRNOTAVAIL
107 The specified address is not available on this machine.
109 .It Bq Er EAFNOSUPPORT
110 Addresses in the specified address family cannot be used with this socket.
113 The socket is non-blocking
114 and a previous connection attempt
115 has not yet been completed.
119 is not a valid descriptor.
121 .It Bq Er ECONNREFUSED
122 The attempt to connect was ignored
123 (because the target is not listening for connections)
124 or explicitly rejected.
129 parameter specifies an area outside
130 the process address space.
132 .It Bq Er EHOSTUNREACH
133 The target host cannot be reached (e.g., down, disconnected).
135 .It Bq Er EINPROGRESS
136 The socket is non-blocking
137 and the connection cannot
138 be completed immediately.
141 for completion by selecting the socket for writing.
144 Its execution was interrupted by a signal.
147 An invalid argument was detected
150 is not valid for the address family,
151 the specified address family is invalid).
154 The socket is already connected.
157 The local network interface is not functioning.
159 .It Bq Er ENETUNREACH
160 The network isn't reachable from this host.
163 The system call was unable to allocate a needed memory buffer.
167 is not a file descriptor for a socket.
172 is listening, no connection is allowed.
176 has a different type than the socket
177 that is bound to the specified peer address.
180 Connection establishment timed out without establishing a connection.
183 Remote host reset the connection request.
186 The following errors are specific to connecting names in the UNIX domain.
187 These errors may not apply in future versions of the UNIX IPC domain.
191 Search permission is denied for a component of the path prefix.
194 Write access to the named socket is denied.
197 An I/O error occurred while reading from or writing to the file system.
200 Too many symbolic links were encountered in translating the pathname.
201 This is taken to be indicative of a looping symbolic link.
203 .It Bq Er ENAMETOOLONG
204 A component of a pathname exceeded
206 characters, or an entire path name exceeded
211 The named socket does not exist.
214 A component of the path prefix is not a directory.
217 .Fd #include <sys/types.h>
218 .Fd #include <sys/socket.h>
234 function call appeared in