|
|
1.1 root 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: .\"
5: .\" @(#)connect.2 6.6 (Berkeley) 5/22/86
6: .\"
7: .TH CONNECT 2 "May 22, 1986"
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 specifies the peer with which the socket is to be associated;
29: this address is that to which datagrams are to be sent,
30: and the only address from which datagrams are to be received.
31: If the socket is of type SOCK_STREAM,
32: then this call attempts to make a connection to
33: another socket.
34: The other socket is specified by
35: .I name,
36: which is an address in the communications space of the socket.
37: Each communications space interprets the
38: .I name
39: parameter in its own way.
40: Generally, stream sockets may successfully
41: .I connect
42: only once; datagram sockets may use
43: .I connect
44: multiple times to change their association.
45: Datagram sockets may dissolve the association
46: by connecting to an invalid address, such as a null address.
47: .SH "RETURN VALUE
48: If the connection or binding succeeds, then 0 is returned.
49: Otherwise a \-1 is returned, and a more specific error
50: code is stored in \fIerrno\fP.
51: .SH "ERRORS
52: The call fails if:
53: .TP 20
54: [EBADF]
55: .I S
56: is not a valid descriptor.
57: .TP 20
58: [ENOTSOCK]
59: .I S
60: is a descriptor for a file, not a socket.
61: .TP 20
62: [EADDRNOTAVAIL]
63: The specified address is not available on this machine.
64: .TP 20
65: [EAFNOSUPPORT]
66: Addresses in the specified address family cannot be used with this socket.
67: .TP 20
68: [EISCONN]
69: The socket is already connected.
70: .TP 20
71: [ETIMEDOUT]
72: Connection establishment timed out without establishing a connection.
73: .TP 20
74: [ECONNREFUSED]
75: The attempt to connect was forcefully rejected.
76: .TP 20
77: [ENETUNREACH]
78: The network isn't reachable from this host.
79: .TP 20
80: [EADDRINUSE]
81: The address is already in use.
82: .TP 20
83: [EFAULT]
84: The \fIname\fP parameter specifies an area outside
85: the process address space.
86: .TP 20
87: [EINPROGRESS]
88: The socket is non-blocking
89: and the connection cannot
90: be completed immediately.
91: It is possible to
92: .IR select (2)
93: for completion by selecting the socket for writing.
94: .TP 20
95: [EALREADY]
96: The socket is non-blocking
97: and a previous connection attempt
98: has not yet been completed.
99: .PP
100: The following errors are specific to connecting names in the UNIX domain.
101: These errors may not apply in future versions of the UNIX IPC domain.
102: .TP 15
103: [ENOTDIR]
104: A component of the path prefix is not a directory.
105: .TP 15
106: [EINVAL]
107: The pathname contains a character with the high-order bit set.
108: .TP 15
109: [ENAMETOOLONG]
110: A component of a pathname exceeded 255 characters,
111: or an entire path name exceeded 1023 characters.
112: .TP 15
113: [ENOENT]
114: The named socket does not exist.
115: .TP 15
116: [EACCES]
117: Search permission is denied for a component of the path prefix.
118: .TP 15
119: [EACCES]
120: Write access to the named socket is denied.
121: .TP 15
122: [ELOOP]
123: Too many symbolic links were encountered in translating the pathname.
124: .SH SEE ALSO
125: accept(2), select(2), socket(2), getsockname(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.