1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
4 .\" Portions extracted from /usr/include/sys/socket.h, which does not have
5 .\" any authorship information in it. It is probably available under the GPL.
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" Other portions are from the 6.9 (Berkeley) 3/10/91 man page:
30 .\" Copyright (c) 1983 The Regents of the University of California.
31 .\" All rights reserved.
33 .\" Redistribution and use in source and binary forms, with or without
34 .\" modification, are permitted provided that the following conditions
36 .\" 1. Redistributions of source code must retain the above copyright
37 .\" notice, this list of conditions and the following disclaimer.
38 .\" 2. Redistributions in binary form must reproduce the above copyright
39 .\" notice, this list of conditions and the following disclaimer in the
40 .\" documentation and/or other materials provided with the distribution.
41 .\" 3. All advertising materials mentioning features or use of this software
42 .\" must display the following acknowledgement:
43 .\" This product includes software developed by the University of
44 .\" California, Berkeley and its contributors.
45 .\" 4. Neither the name of the University nor the names of its contributors
46 .\" may be used to endorse or promote products derived from this software
47 .\" without specific prior written permission.
49 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
62 .\" Modified 1998, 1999 by Andi Kleen
63 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
65 .TH CONNECT 2 2008-12-03 "Linux" "Linux Programmer's Manual"
67 connect \- initiate a connection on a socket
70 .BR "#include <sys/types.h>" " /* See NOTES */"
72 .B #include <sys/socket.h>
74 .BI "int connect(int " sockfd ", const struct sockaddr *" addr ,
75 .BI " socklen_t " addrlen );
80 system call connects the socket referred to by the file descriptor
82 to the address specified by
86 argument specifies the size of
88 The format of the address in
90 is determined by the address space of the socket
102 is the address to which datagrams are sent by default, and the only
103 address from which datagrams are received.
104 If the socket is of type
108 this call attempts to make a connection to the socket that is bound
109 to the address specified by
112 Generally, connection-based protocol sockets may successfully
114 only once; connectionless protocol sockets may use
116 multiple times to change their association.
117 Connectionless sockets may
118 dissolve the association by connecting to an address with the
124 (supported on Linux since kernel 2.2).
126 If the connection or binding succeeds, zero is returned.
127 On error, \-1 is returned, and
129 is set appropriately.
131 The following are general socket errors only.
132 There may be other domain-specific error codes.
135 For UNIX domain sockets, which are identified by pathname:
136 Write permission is denied on the socket file,
137 or search permission is denied for one of the directories
140 .BR path_resolution (7).)
142 .BR EACCES ", " EPERM
143 The user tried to connect to a broadcast address without having the socket
144 broadcast flag enabled or the connection request failed because of a local
148 Local address is already in use.
151 The passed address didn't have the correct address family in its
156 No more free local ports or insufficient entries in the routing cache.
159 see the description of
160 .I /proc/sys/net/ipv4/ip_local_port_range
162 for information on how to increase the number of local ports.
165 The socket is nonblocking and a previous connection attempt has not yet
169 The file descriptor is not a valid index in the descriptor table.
172 No-one listening on the remote address.
175 The socket structure address is outside the user's address space.
178 The socket is nonblocking and the connection cannot be completed
184 for completion by selecting the socket for writing.
187 indicates writability, use
195 completed successfully
197 is zero) or unsuccessfully
199 is one of the usual error codes listed here,
200 explaining the reason for the failure).
203 The system call was interrupted by a signal that was caught; see
205 .\" For TCP, the connection will complete asynchronously.
206 .\" See http://lkml.org/lkml/2005/7/12/254
209 The socket is already connected.
212 Network is unreachable.
215 The file descriptor is not associated with a socket.
218 Timeout while attempting connection.
219 The server may be too
220 busy to accept new connections.
221 Note that for IP sockets the timeout may
222 be very long when syncookies are enabled on the server.
226 function first appeared in 4.2BSD), POSIX.1-2001.
227 .\" SVr4 documents the additional
228 .\" general error codes
229 .\" .BR EADDRNOTAVAIL ,
231 .\" .BR EAFNOSUPPORT ,
238 .\" documents many additional error conditions not described here.
240 POSIX.1-2001 does not require the inclusion of
242 and this header file is not required on Linux.
243 However, some historical (BSD) implementations required this header
244 file, and portable applications are probably wise to include it.
246 The third argument of
250 (and this is what 4.x BSD and libc4 and libc5 have).
251 Some POSIX confusion resulted in the present
257 An example of the use of
267 .BR path_resolution (7)