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