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