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