Commit | Line | Data |
---|---|---|
5b41da86 KM |
1 | .\" Copyright (c) 1983 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
19914c9b | 5 | .\" @(#)connect.2 6.3 (Berkeley) %G% |
5b41da86 | 6 | .\" |
bf25b211 | 7 | .TH CONNECT 2 "" |
5b41da86 KM |
8 | .UC 5 |
9 | .SH NAME | |
10 | connect \- initiate a connection on a socket | |
11 | .SH SYNOPSIS | |
12 | .nf | |
13 | .ft B | |
14 | #include <sys/types.h> | |
15 | #include <sys/socket.h> | |
16 | .PP | |
17 | .ft B | |
18 | connect(s, name, namelen) | |
19 | int s; | |
20 | struct sockaddr *name; | |
21 | int namelen; | |
22 | .fi | |
23 | .SH DESCRIPTION | |
24 | The parameter | |
25 | .I s | |
26 | is a socket. | |
27 | If it is of type SOCK_DGRAM, | |
28 | then this call permanently specifies the peer to which | |
29 | datagrams are to be sent; | |
30 | if it is of type SOCK_STREAM, | |
31 | then this call attempts to make a connection to | |
32 | another socket. | |
33 | The other socket is specified by | |
19914c9b | 34 | .I name, |
5b41da86 KM |
35 | which is an address in the communications space of the socket. |
36 | Each communications space interprets the | |
37 | .I name | |
38 | parameter in its own way. | |
39 | .SH "RETURN VALUE | |
40 | If the connection or binding succeeds, then 0 is returned. | |
41 | Otherwise a \-1 is returned, and a more specific error | |
42 | code is stored in \fIerrno\fP. | |
43 | .SH "ERRORS | |
44 | The call fails if: | |
45 | .TP 20 | |
46 | [EBADF] | |
47 | .I S | |
48 | is not a valid descriptor. | |
49 | .TP 20 | |
50 | [ENOTSOCK] | |
51 | .I S | |
52 | is a descriptor for a file, not a socket. | |
53 | .TP 20 | |
54 | [EADDRNOTAVAIL] | |
55 | The specified address is not available on this machine. | |
56 | .TP 20 | |
57 | [EAFNOSUPPORT] | |
58 | Addresses in the specified address family cannot be used with this socket. | |
59 | .TP 20 | |
60 | [EISCONN] | |
61 | The socket is already connected. | |
62 | .TP 20 | |
63 | [ETIMEDOUT] | |
64 | Connection establishment timed out without establishing a connection. | |
65 | .TP 20 | |
66 | [ECONNREFUSED] | |
67 | The attempt to connect was forcefully rejected. | |
68 | .TP 20 | |
69 | [ENETUNREACH] | |
70 | The network isn't reachable from this host. | |
71 | .TP 20 | |
72 | [EADDRINUSE] | |
73 | The address is already in use. | |
74 | .TP 20 | |
75 | [EFAULT] | |
76 | The \fIname\fP parameter specifies an area outside | |
77 | the process address space. | |
78 | .TP 20 | |
79 | [EWOULDBLOCK] | |
80 | The socket is non-blocking and the | |
81 | and the connection cannot | |
82 | be completed immediately. | |
83 | It is possible to | |
84 | .IR select (2) | |
85 | the socket while it is connecting by selecting it for writing. | |
b5984ffe KM |
86 | .PP |
87 | .PP | |
88 | The following errors are specific to connecting names in the UNIX domain. | |
89 | These errors may not apply in future versions of the UNIX ipc domain. | |
90 | .TP 15 | |
91 | [ENOTDIR] | |
92 | A component of the path prefix is not a directory. | |
93 | .TP 15 | |
94 | [EINVAL] | |
95 | The pathname contains a character with the high-order bit set. | |
96 | .TP 15 | |
97 | [ENAMETOOLONG] | |
98 | A component of a pathname exceeded 255 characters, | |
99 | or an entire path name exceeded 1023 characters. | |
100 | .TP 15 | |
101 | [ENOENT] | |
102 | The named socket does not exist. | |
103 | .TP 15 | |
104 | [EACCES] | |
105 | Search permission is denied for a component of the path prefix. | |
106 | .TP 15 | |
107 | [ELOOP] | |
108 | Too many symbolic links were encountered in translating the pathname. | |
5b41da86 KM |
109 | .SH SEE ALSO |
110 | accept(2), select(2), socket(2), getsockname(2) |