Initial import from FreeBSD RELENG_4:
[dragonfly.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 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)connect.2   8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/sys/connect.2,v 1.11.2.8 2003/04/05 16:59:01 ceri Exp $
34 .\"
35 .Dd June 4, 1993
36 .Dt CONNECT 2
37 .Os
38 .Sh NAME
39 .Nm connect
40 .Nd initiate a connection on a socket
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In sys/types.h
45 .In sys/socket.h
46 .Ft int
47 .Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen"
48 .Sh DESCRIPTION
49 The parameter
50 .Fa s
51 is a socket.
52 If it is of type
53 .Dv SOCK_DGRAM ,
54 this call specifies the peer with which the socket is to be associated;
55 this address is that to which datagrams are to be sent,
56 and the only address from which datagrams are to be received.
57 If the socket is of type
58 .Dv SOCK_STREAM ,
59 this call attempts to make a connection to
60 another socket.
61 The other socket is specified by
62 .Fa name ,
63 which is an address in the communications space of the socket.
64 Each communications space interprets the
65 .Fa name
66 parameter in its own way.
67 Generally, stream sockets may successfully
68 .Fn connect
69 only once; datagram sockets may use
70 .Fn connect
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.
74 .Sh RETURN VALUES
75 .Rv -std connect
76 .Sh ERRORS
77 The
78 .Fn connect
79 call fails if:
80 .Bl -tag -width Er
81 .It Bq Er EBADF
82 .Fa s
83 is not a valid descriptor.
84 .It Bq Er ENOTSOCK
85 .Fa s
86 is a descriptor for a file, not a socket.
87 .It Bq Er EADDRNOTAVAIL
88 The specified address is not available on this machine.
89 .It Bq Er EAFNOSUPPORT
90 Addresses in the specified address family cannot be used with this socket.
91 .It Bq Er EISCONN
92 The socket is already connected.
93 .It Bq Er ETIMEDOUT
94 Connection establishment timed out without establishing a connection.
95 .It Bq Er ECONNREFUSED
96 The attempt to connect was forcefully rejected.
97 .It Bq Er ENETUNREACH
98 The network is not reachable from this host.
99 .It Bq Er EHOSTUNREACH
100 The remote host is not reachable from this host.
101 .It Bq Er EADDRINUSE
102 The address is already in use.
103 .It Bq Er EFAULT
104 The
105 .Fa name
106 parameter specifies an area outside
107 the process address space.
108 .It Bq Er EINPROGRESS
109 The socket is non-blocking
110 and the connection cannot
111 be completed immediately.
112 It is possible to
113 .Xr select 2
114 for completion by selecting the socket for writing.
115 .It Bq Er EALREADY
116 The socket is non-blocking
117 and a previous connection attempt
118 has not yet been completed.
119 .El
120 .Pp
121 The following errors are specific to connecting names in the UNIX domain.
122 These errors may not apply in future versions of the UNIX IPC domain.
123 .Bl -tag -width Er
124 .It Bq Er ENOTDIR
125 A component of the path prefix is not a directory.
126 .It Bq Er ENAMETOOLONG
127 A component of a pathname exceeded 255 characters,
128 or an entire path name exceeded 1023 characters.
129 .It Bq Er ENOENT
130 The named socket does not exist.
131 .It Bq Er EACCES
132 Search permission is denied for a component of the path prefix.
133 .It Bq Er EACCES
134 Write access to the named socket is denied.
135 .It Bq Er ELOOP
136 Too many symbolic links were encountered in translating the pathname.
137 .El
138 .Sh SEE ALSO
139 .Xr accept 2 ,
140 .Xr getpeername 2 ,
141 .Xr getsockname 2 ,
142 .Xr select 2 ,
143 .Xr socket 2
144 .Sh HISTORY
145 The
146 .Fn connect
147 function call appeared in
148 .Bx 4.2 .