]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
1 | .\" $NetBSD: connect.2,v 1.8 1995/10/12 15:40:48 jtc Exp $ |
2 | .\" | |
3 | .\" Copyright (c) 1983, 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
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. | |
21 | .\" | |
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 | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)connect.2 8.1 (Berkeley) 6/4/93 | |
35 | .\" | |
36 | .Dd June 4, 1993 | |
37 | .Dt CONNECT 2 | |
38 | .Os BSD 4.2 | |
39 | .Sh NAME | |
40 | .Nm connect | |
41 | .Nd initiate a connection on a socket | |
42 | .Sh SYNOPSIS | |
43 | .Fd #include <sys/types.h> | |
44 | .Fd #include <sys/socket.h> | |
45 | .Ft int | |
91447636 | 46 | .Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen" |
9bccf70c A |
47 | .Sh DESCRIPTION |
48 | The parameter | |
49 | .Fa s | |
50 | is a socket. | |
51 | If it is of type | |
52 | .Dv SOCK_DGRAM , | |
53 | this call specifies the peer with which the socket is to be associated; | |
54 | this address is that to which datagrams are to be sent, | |
55 | and the only address from which datagrams are to be received. | |
56 | If the socket is of type | |
57 | .Dv SOCK_STREAM , | |
58 | this call attempts to make a connection to | |
59 | another socket. | |
60 | The other socket is specified by | |
61 | .Fa name , | |
62 | which is an address in the communications space of the socket. | |
63 | Each communications space interprets the | |
64 | .Fa name | |
65 | parameter in its own way. | |
66 | Generally, stream sockets may successfully | |
67 | .Fn connect | |
68 | only once; datagram sockets may use | |
69 | .Fn connect | |
70 | multiple times to change their association. | |
71 | Datagram sockets may dissolve the association | |
55e303ae A |
72 | by connecting to an invalid address, such as a null address |
73 | or an address with | |
91447636 A |
74 | the address family set to |
75 | .Dv AF_UNSPEC | |
76 | (the error | |
77 | .Dv EAFNOSUPPORT | |
78 | will be harmlessly returned). | |
9bccf70c A |
79 | .Sh RETURN VALUES |
80 | If the connection or binding succeeds, 0 is returned. | |
81 | Otherwise a -1 is returned, and a more specific error | |
82 | code is stored in | |
83 | .Va errno . | |
84 | .Sh ERRORS | |
85 | The | |
86 | .Fn connect | |
87 | call fails if: | |
88 | .Bl -tag -width Er | |
89 | .It Bq Er EBADF | |
90 | .Fa S | |
91 | is not a valid descriptor. | |
92 | .It Bq Er ENOTSOCK | |
93 | .Fa S | |
94 | is a descriptor for a file, not a socket. | |
95 | .It Bq Er EADDRNOTAVAIL | |
96 | The specified address is not available on this machine. | |
97 | .It Bq Er EAFNOSUPPORT | |
98 | Addresses in the specified address family cannot be used with this socket. | |
99 | .It Bq Er EISCONN | |
100 | The socket is already connected. | |
101 | .It Bq Er ETIMEDOUT | |
102 | Connection establishment timed out without establishing a connection. | |
103 | .It Bq Er ECONNREFUSED | |
104 | The attempt to connect was forcefully rejected. | |
105 | .It Bq Er ENETUNREACH | |
106 | The network isn't reachable from this host. | |
107 | .It Bq Er EADDRINUSE | |
108 | The address is already in use. | |
109 | .It Bq Er EFAULT | |
110 | The | |
111 | .Fa name | |
112 | parameter specifies an area outside | |
113 | the process address space. | |
114 | .It Bq Er EINPROGRESS | |
115 | The socket is non-blocking | |
116 | and the connection cannot | |
117 | be completed immediately. | |
118 | It is possible to | |
119 | .Xr select 2 | |
120 | for completion by selecting the socket for writing. | |
121 | .It Bq Er EALREADY | |
122 | The socket is non-blocking | |
123 | and a previous connection attempt | |
124 | has not yet been completed. | |
91447636 A |
125 | .It Bq Er EACCES |
126 | The destination address is a broadcast address and the | |
127 | socket option | |
128 | .Dv SO_BROADCAST | |
129 | is not set. | |
9bccf70c A |
130 | .El |
131 | .Pp | |
132 | The following errors are specific to connecting names in the UNIX domain. | |
133 | These errors may not apply in future versions of the UNIX IPC domain. | |
134 | .Bl -tag -width Er | |
135 | .It Bq Er ENOTDIR | |
136 | A component of the path prefix is not a directory. | |
137 | .It Bq Er ENAMETOOLONG | |
138 | A component of a pathname exceeded | |
139 | .Dv {NAME_MAX} | |
140 | characters, or an entire path name exceeded | |
141 | .Dv {PATH_MAX} | |
142 | characters. | |
143 | .It Bq Er ENOENT | |
144 | The named socket does not exist. | |
145 | .It Bq Er EACCES | |
146 | Search permission is denied for a component of the path prefix. | |
147 | .It Bq Er EACCES | |
148 | Write access to the named socket is denied. | |
149 | .It Bq Er ELOOP | |
150 | Too many symbolic links were encountered in translating the pathname. | |
151 | .El | |
152 | .Sh SEE ALSO | |
153 | .Xr accept 2 , | |
154 | .Xr select 2 , | |
155 | .Xr socket 2 , | |
156 | .Xr getsockname 2 | |
157 | .Sh HISTORY | |
158 | The | |
159 | .Fn connect | |
160 | function call appeared in | |
161 | .Bx 4.2 . |