CONNECTSection: Linux Programmer's Manual (2)
Return to Main Contents
NAMEconnect - initiate a connection on a socket
DESCRIPTIONThe file descriptor sockfd must refer to a socket. If the socket is of type SOCK_DGRAM then the serv_addr address is the address to which datagrams are sent by default, and the only address from which datagrams are received. If the socket is of type SOCK_STREAM or SOCK_SEQPACKET, this call attempts to make a connection to another socket. The other socket is specified by serv_addr, which is an address (of length addrlen) in the communications space of the socket. Each communications space interprets the serv_addr parameter in its own way.
Generally, connection-based protocol sockets may successfully connect only once; connectionless protocol sockets may use connect multiple times to change their association. Connectionless sockets may dissolve the association by connecting to an address with the sa_family member of sockaddr set to AF_UNSPEC.
RETURN VALUEIf the connection or binding succeeds, zero is returned. On error, -1 is returned, and errno is set appropriately.
ERRORSThe following are general socket errors only. There may be other domain-specific error codes.
CONFORMING TOSVr4, 4.4BSD (the connect function first appeared in BSD 4.2). SVr4 documents the additional general error codes EADDRNOTAVAIL, EINVAL, EAFNOSUPPORT, EALREADY, EINTR, EPROTOTYPE, and ENOSR. It also documents many additional error conditions not described here.
NOTEThe third argument of connect is in reality an int (and this is what BSD 4.* and libc4 and libc5 have). Some POSIX confusion resulted in the present socklen_t. The draft standard has not been adopted yet, but glibc2 already follows it and also has socklen_t. See also accept(2).
BUGSUnconnecting a socket by calling connect with a AF_UNSPEC address is not yet implemented.
SEE ALSOaccept(2), bind(2), listen(2), socket(2), getsockname(2)
This document was created by man2html, using the manual pages.
Time: 15:59:25 GMT, February 24, 2018