Commit | Line | Data |
---|---|---|
da268306 KB |
1 | .\" Copyright (c) 1983 The Regents of the University of California. |
2 | .\" All rights reserved. | |
5b41da86 | 3 | .\" |
af359dea C |
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. | |
da268306 | 19 | .\" |
af359dea C |
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. | |
5b41da86 | 31 | .\" |
af359dea C |
32 | .\" @(#)connect.2 6.9 (Berkeley) 3/10/91 |
33 | .\" | |
34 | .Dd March 10, 1991 | |
931b8415 CL |
35 | .Dt CONNECT 2 |
36 | .Os BSD 4.2 | |
37 | .Sh NAME | |
38 | .Nm connect | |
39 | .Nd initiate a connection on a socket | |
40 | .Sh SYNOPSIS | |
41 | .Fd #include <sys/types.h> | |
42 | .Fd #include <sys/socket.h> | |
43 | .Ft int | |
44 | .Fn connect "int s" "struct sockaddr *name" "int namelen" | |
45 | .Sh DESCRIPTION | |
5b41da86 | 46 | The parameter |
931b8415 | 47 | .Fa s |
5b41da86 | 48 | is a socket. |
931b8415 CL |
49 | If it is of type |
50 | .Dv SOCK_DGRAM , | |
51 | this call specifies the peer with which the socket is to be associated; | |
56b0726a MK |
52 | this address is that to which datagrams are to be sent, |
53 | and the only address from which datagrams are to be received. | |
931b8415 CL |
54 | If the socket is of type |
55 | .Dv SOCK_STREAM , | |
56 | this call attempts to make a connection to | |
5b41da86 KM |
57 | another socket. |
58 | The other socket is specified by | |
931b8415 | 59 | .Fa name , |
5b41da86 KM |
60 | which is an address in the communications space of the socket. |
61 | Each communications space interprets the | |
931b8415 | 62 | .Fa name |
5b41da86 | 63 | parameter in its own way. |
56b0726a | 64 | Generally, stream sockets may successfully |
931b8415 | 65 | .Fn connect |
56b0726a | 66 | only once; datagram sockets may use |
931b8415 | 67 | .Fn connect |
56b0726a MK |
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. | |
931b8415 CL |
71 | .Sh RETURN VALUES |
72 | If the connection or binding succeeds, 0 is returned. | |
73 | Otherwise a -1 is returned, and a more specific error | |
74 | code is stored in | |
75 | .Va errno . | |
76 | .Sh ERRORS | |
77 | The | |
78 | .Fn connect | |
79 | call fails if: | |
80 | .Bl -tag -width EADDRNOTAVAILABB | |
81 | .It Bq Er EBADF | |
82 | .Fa S | |
5b41da86 | 83 | is not a valid descriptor. |
931b8415 CL |
84 | .It Bq Er ENOTSOCK |
85 | .Fa S | |
5b41da86 | 86 | is a descriptor for a file, not a socket. |
931b8415 | 87 | .It Bq Er EADDRNOTAVAIL |
5b41da86 | 88 | The specified address is not available on this machine. |
931b8415 | 89 | .It Bq Er EAFNOSUPPORT |
5b41da86 | 90 | Addresses in the specified address family cannot be used with this socket. |
931b8415 | 91 | .It Bq Er EISCONN |
5b41da86 | 92 | The socket is already connected. |
931b8415 | 93 | .It Bq Er ETIMEDOUT |
5b41da86 | 94 | Connection establishment timed out without establishing a connection. |
931b8415 | 95 | .It Bq Er ECONNREFUSED |
5b41da86 | 96 | The attempt to connect was forcefully rejected. |
931b8415 | 97 | .It Bq Er ENETUNREACH |
5b41da86 | 98 | The network isn't reachable from this host. |
931b8415 | 99 | .It Bq Er EADDRINUSE |
5b41da86 | 100 | The address is already in use. |
931b8415 CL |
101 | .It Bq Er EFAULT |
102 | The | |
103 | .Fa name | |
104 | parameter specifies an area outside | |
5b41da86 | 105 | the process address space. |
931b8415 | 106 | .It Bq Er EINPROGRESS |
d4bad45b | 107 | The socket is non-blocking |
5b41da86 KM |
108 | and the connection cannot |
109 | be completed immediately. | |
110 | It is possible to | |
931b8415 | 111 | .Xr select 2 |
0d3f4d7d | 112 | for completion by selecting the socket for writing. |
931b8415 | 113 | .It Bq Er EALREADY |
56b0726a MK |
114 | The socket is non-blocking |
115 | and a previous connection attempt | |
d4bad45b | 116 | has not yet been completed. |
931b8415 CL |
117 | .El |
118 | .Pp | |
b5984ffe | 119 | The following errors are specific to connecting names in the UNIX domain. |
56b0726a | 120 | These errors may not apply in future versions of the UNIX IPC domain. |
931b8415 CL |
121 | .Bl -tag -width EADDRNOTAVAILABB |
122 | .It Bq Er ENOTDIR | |
b5984ffe | 123 | A component of the path prefix is not a directory. |
931b8415 | 124 | .It Bq Er EINVAL |
b5984ffe | 125 | The pathname contains a character with the high-order bit set. |
931b8415 | 126 | .It Bq Er ENAMETOOLONG |
b5984ffe KM |
127 | A component of a pathname exceeded 255 characters, |
128 | or an entire path name exceeded 1023 characters. | |
931b8415 | 129 | .It Bq Er ENOENT |
b5984ffe | 130 | The named socket does not exist. |
931b8415 | 131 | .It Bq Er EACCES |
b5984ffe | 132 | Search permission is denied for a component of the path prefix. |
931b8415 | 133 | .It Bq Er EACCES |
56b0726a | 134 | Write access to the named socket is denied. |
931b8415 | 135 | .It Bq Er ELOOP |
b5984ffe | 136 | Too many symbolic links were encountered in translating the pathname. |
931b8415 CL |
137 | .El |
138 | .Sh SEE ALSO | |
139 | .Xr accept 2 , | |
140 | .Xr select 2 , | |
141 | .Xr socket 2 , | |
142 | .Xr getsockname 2 | |
143 | .Sh HISTORY | |
144 | The | |
145 | .Nm | |
146 | function call appeared in | |
147 | .Bx 4.2 . |