Commit | Line | Data |
---|---|---|
da268306 KB |
1 | .\" Copyright (c) 1983 The Regents of the University of California. |
2 | .\" All rights reserved. | |
5b41da86 | 3 | .\" |
da268306 KB |
4 | .\" Redistribution and use in source and binary forms are permitted |
5 | .\" provided that the above copyright notice and this paragraph are | |
6 | .\" duplicated in all such forms and that any documentation, | |
7 | .\" advertising materials, and other materials related to such | |
8 | .\" distribution and use acknowledge that the software was developed | |
9 | .\" by the University of California, Berkeley. The name of the | |
10 | .\" University may not be used to endorse or promote products derived | |
11 | .\" from this software without specific prior written permission. | |
12 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
13 | .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
14 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
15 | .\" | |
16 | .\" @(#)connect.2 6.7 (Berkeley) %G% | |
5b41da86 | 17 | .\" |
bf25b211 | 18 | .TH CONNECT 2 "" |
5b41da86 KM |
19 | .UC 5 |
20 | .SH NAME | |
21 | connect \- initiate a connection on a socket | |
22 | .SH SYNOPSIS | |
23 | .nf | |
24 | .ft B | |
25 | #include <sys/types.h> | |
26 | #include <sys/socket.h> | |
27 | .PP | |
28 | .ft B | |
29 | connect(s, name, namelen) | |
30 | int s; | |
31 | struct sockaddr *name; | |
32 | int namelen; | |
33 | .fi | |
34 | .SH DESCRIPTION | |
35 | The parameter | |
36 | .I s | |
37 | is a socket. | |
38 | If it is of type SOCK_DGRAM, | |
56b0726a MK |
39 | then this call specifies the peer with which the socket is to be associated; |
40 | this address is that to which datagrams are to be sent, | |
41 | and the only address from which datagrams are to be received. | |
42 | If the socket is of type SOCK_STREAM, | |
5b41da86 KM |
43 | then this call attempts to make a connection to |
44 | another socket. | |
45 | The other socket is specified by | |
19914c9b | 46 | .I name, |
5b41da86 KM |
47 | which is an address in the communications space of the socket. |
48 | Each communications space interprets the | |
49 | .I name | |
50 | parameter in its own way. | |
56b0726a MK |
51 | Generally, stream sockets may successfully |
52 | .I connect | |
53 | only once; datagram sockets may use | |
54 | .I connect | |
55 | multiple times to change their association. | |
56 | Datagram sockets may dissolve the association | |
57 | by connecting to an invalid address, such as a null address. | |
5b41da86 KM |
58 | .SH "RETURN VALUE |
59 | If the connection or binding succeeds, then 0 is returned. | |
60 | Otherwise a \-1 is returned, and a more specific error | |
61 | code is stored in \fIerrno\fP. | |
62 | .SH "ERRORS | |
63 | The call fails if: | |
64 | .TP 20 | |
65 | [EBADF] | |
66 | .I S | |
67 | is not a valid descriptor. | |
68 | .TP 20 | |
69 | [ENOTSOCK] | |
70 | .I S | |
71 | is a descriptor for a file, not a socket. | |
72 | .TP 20 | |
73 | [EADDRNOTAVAIL] | |
74 | The specified address is not available on this machine. | |
75 | .TP 20 | |
76 | [EAFNOSUPPORT] | |
77 | Addresses in the specified address family cannot be used with this socket. | |
78 | .TP 20 | |
79 | [EISCONN] | |
80 | The socket is already connected. | |
81 | .TP 20 | |
82 | [ETIMEDOUT] | |
83 | Connection establishment timed out without establishing a connection. | |
84 | .TP 20 | |
85 | [ECONNREFUSED] | |
86 | The attempt to connect was forcefully rejected. | |
87 | .TP 20 | |
88 | [ENETUNREACH] | |
89 | The network isn't reachable from this host. | |
90 | .TP 20 | |
91 | [EADDRINUSE] | |
92 | The address is already in use. | |
93 | .TP 20 | |
94 | [EFAULT] | |
95 | The \fIname\fP parameter specifies an area outside | |
96 | the process address space. | |
97 | .TP 20 | |
0d3f4d7d | 98 | [EINPROGRESS] |
d4bad45b | 99 | The socket is non-blocking |
5b41da86 KM |
100 | and the connection cannot |
101 | be completed immediately. | |
102 | It is possible to | |
103 | .IR select (2) | |
0d3f4d7d | 104 | for completion by selecting the socket for writing. |
56b0726a | 105 | .TP 20 |
0d3f4d7d | 106 | [EALREADY] |
56b0726a MK |
107 | The socket is non-blocking |
108 | and a previous connection attempt | |
d4bad45b | 109 | has not yet been completed. |
b5984ffe KM |
110 | .PP |
111 | The following errors are specific to connecting names in the UNIX domain. | |
56b0726a | 112 | These errors may not apply in future versions of the UNIX IPC domain. |
b5984ffe KM |
113 | .TP 15 |
114 | [ENOTDIR] | |
115 | A component of the path prefix is not a directory. | |
116 | .TP 15 | |
117 | [EINVAL] | |
118 | The pathname contains a character with the high-order bit set. | |
119 | .TP 15 | |
120 | [ENAMETOOLONG] | |
121 | A component of a pathname exceeded 255 characters, | |
122 | or an entire path name exceeded 1023 characters. | |
123 | .TP 15 | |
124 | [ENOENT] | |
125 | The named socket does not exist. | |
126 | .TP 15 | |
127 | [EACCES] | |
128 | Search permission is denied for a component of the path prefix. | |
129 | .TP 15 | |
56b0726a MK |
130 | [EACCES] |
131 | Write access to the named socket is denied. | |
132 | .TP 15 | |
b5984ffe KM |
133 | [ELOOP] |
134 | Too many symbolic links were encountered in translating the pathname. | |
5b41da86 KM |
135 | .SH SEE ALSO |
136 | accept(2), select(2), socket(2), getsockname(2) |