.\" Modified 1998, 1999 by Andi Kleen
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
.\"
-.TH CONNECT 2 2014-09-06 "Linux" "Linux Programmer's Manual"
+.TH CONNECT 2 2019-03-06 "Linux" "Linux Programmer's Manual"
.SH NAME
connect \- initiate a connection on a socket
.SH SYNOPSIS
.BR "#include <sys/types.h>" " /* See NOTES */"
.br
.B #include <sys/socket.h>
-.sp
+.PP
.BI "int connect(int " sockfd ", const struct sockaddr *" addr ,
.BI " socklen_t " addrlen );
.fi
see
.BR socket (2)
for further details.
-
+.PP
If the socket
.I sockfd
is of type
field.
.TP
.B EAGAIN
-Insufficient entries in the routing cache.
+For nonblocking UNIX domain sockets, the socket is nonblocking, and the
+connection cannot be completed immediately.
+For other socket families, there are insufficient entries in the routing cache.
.TP
.B EALREADY
The socket is nonblocking and a previous connection attempt has not yet
been completed.
.TP
.B EBADF
-The file descriptor is not a valid index in the descriptor table.
+.I sockfd
+is not a valid open file descriptor.
.TP
.B ECONNREFUSED
-No-one listening on the remote address.
+A
+.BR connect ()
+on a stream socket found no one listening on the remote address.
.TP
.B EFAULT
The socket structure address is outside the user's address space.
.TP
.B EINPROGRESS
-The socket is nonblocking and the connection cannot be completed
-immediately.
+The socket is nonblocking and the connection cannot be completed immediately.
+(UNIX domain sockets failed with
+.BR EAGAIN
+instead.)
It is possible to
.BR select (2)
or
Network is unreachable.
.TP
.B ENOTSOCK
-The file descriptor is not associated with a socket.
+The file descriptor
+.I sockfd
+does not refer to a socket.
.TP
.B EPROTOTYPE
The socket type does not support the requested communications protocol.
Note that for IP sockets the timeout may
be very long when syncookies are enabled on the server.
.SH CONFORMING TO
-SVr4, 4.4BSD, (the
-.BR connect ()
-function first appeared in 4.2BSD), POSIX.1-2001.
+POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD,
+.RB (connect ()
+first appeared in 4.2BSD).
.\" SVr4 documents the additional
.\" general error codes
.\" .BR EADDRNOTAVAIL ,
.\" It also
.\" documents many additional error conditions not described here.
.SH NOTES
-POSIX.1-2001 does not require the inclusion of
+POSIX.1 does not require the inclusion of
.IR <sys/types.h> ,
and this header file is not required on Linux.
However, some historical (BSD) implementations required this header
file, and portable applications are probably wise to include it.
-
-The third argument of
-.BR connect ()
-is in reality an
-.I int
-(and this is what 4.x BSD and libc4 and libc5 have).
-Some POSIX confusion resulted in the present
-.IR socklen_t ,
-also used by glibc.
-See also
+.PP
+For background on the
+.I socklen_t
+type, see
.BR accept (2).
-
+.PP
If
.BR connect ()
fails, consider the state of the socket as unspecified.