]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - lib/libc/sys/connect.2
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / lib / libc / sys / connect.2
1 .\" Copyright (c) 1983, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 4. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)connect.2   8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd September 29, 2014
32 .Dt CONNECT 2
33 .Os
34 .Sh NAME
35 .Nm connect
36 .Nd initiate a connection on a socket
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/types.h
41 .In sys/socket.h
42 .Ft int
43 .Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen"
44 .Sh DESCRIPTION
45 The
46 .Fa s
47 argument
48 is a socket.
49 If it is of type
50 .Dv SOCK_DGRAM ,
51 this call specifies the peer with which the socket is to be associated;
52 this address is that to which datagrams are to be sent,
53 and the only address from which datagrams are to be received.
54 If the socket is of type
55 .Dv SOCK_STREAM ,
56 this call attempts to make a connection to
57 another socket.
58 The other socket is specified by
59 .Fa name ,
60 which is an address in the communications space of the socket.
61 Each communications space interprets the
62 .Fa name
63 argument in its own way.
64 Generally, stream sockets may successfully
65 .Fn connect
66 only once; datagram sockets may use
67 .Fn connect
68 multiple times to change their association.
69 Datagram sockets may dissolve the association
70 by connecting to an invalid address, such as a null address.
71 .Sh RETURN VALUES
72 .Rv -std connect
73 .Sh ERRORS
74 The
75 .Fn connect
76 system call fails if:
77 .Bl -tag -width Er
78 .It Bq Er EBADF
79 The
80 .Fa s
81 argument
82 is not a valid descriptor.
83 .It Bq Er EINVAL
84 The
85 .Fa namelen
86 argument is not a valid length for the address family.
87 .It Bq Er ENOTSOCK
88 The
89 .Fa s
90 argument
91 is a descriptor for a file, not a socket.
92 .It Bq Er EADDRNOTAVAIL
93 The specified address is not available on this machine.
94 .It Bq Er EAFNOSUPPORT
95 Addresses in the specified address family cannot be used with this socket.
96 .It Bq Er EISCONN
97 The socket is already connected.
98 .It Bq Er ETIMEDOUT
99 Connection establishment timed out without establishing a connection.
100 .It Bq Er ECONNREFUSED
101 The attempt to connect was forcefully rejected.
102 .It Bq Er ECONNRESET
103 The connection was reset by the remote host.
104 .It Bq Er ENETUNREACH
105 The network is not reachable from this host.
106 .It Bq Er EHOSTUNREACH
107 The remote host is not reachable from this host.
108 .It Bq Er EADDRINUSE
109 The address is already in use.
110 .It Bq Er EFAULT
111 The
112 .Fa name
113 argument specifies an area outside
114 the process address space.
115 .It Bq Er EINPROGRESS
116 The socket is non-blocking
117 and the connection cannot
118 be completed immediately.
119 It is possible to
120 .Xr select 2
121 for completion by selecting the socket for writing.
122 .It Bq Er EINTR
123 The connection attempt was interrupted by the delivery of a signal.
124 The connection will be established in the background,
125 as in the case of
126 .Er EINPROGRESS .
127 .It Bq Er EALREADY
128 A previous connection attempt has not yet been completed.
129 .It Bq Er EACCES
130 An attempt is made to connect to a broadcast address (obtained through the
131 .Dv INADDR_BROADCAST
132 constant or the
133 .Dv INADDR_NONE
134 return value) through a socket that does not provide broadcast functionality.
135 .It Bq Er EAGAIN
136 An auto-assigned port number was requested but no auto-assigned ports
137 are available.
138 Increasing the port range specified by
139 .Xr sysctl 3
140 MIB variables
141 .Va net.inet.ip.portrange.first
142 and
143 .Va net.inet.ip.portrange.last
144 may alleviate the problem.
145 .El
146 .Pp
147 The following errors are specific to connecting names in the UNIX domain.
148 These errors may not apply in future versions of the UNIX IPC domain.
149 .Bl -tag -width Er
150 .It Bq Er ENOTDIR
151 A component of the path prefix is not a directory.
152 .It Bq Er ENAMETOOLONG
153 A component of a pathname exceeded 255 characters,
154 or an entire path name exceeded 1023 characters.
155 .It Bq Er ENOENT
156 The named socket does not exist.
157 .It Bq Er EACCES
158 Search permission is denied for a component of the path prefix.
159 .It Bq Er EACCES
160 Write access to the named socket is denied.
161 .It Bq Er ELOOP
162 Too many symbolic links were encountered in translating the pathname.
163 .It Bq Er EPERM
164 Write access to the named socket is denied.
165 .El
166 .Sh SEE ALSO
167 .Xr accept 2 ,
168 .Xr getpeername 2 ,
169 .Xr getsockname 2 ,
170 .Xr select 2 ,
171 .Xr socket 2 ,
172 .Xr sysctl 3 ,
173 .Xr sysctl 8
174 .Sh HISTORY
175 The
176 .Fn connect
177 system call appeared in
178 .Bx 4.2 .