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