connect(2) System Calls Manual connect(2) connect - LIBRARY Standard C library (libc, -lc) #include int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); connect() , sockfd, addr. addrlen addr. addr sockfd; socket(2). sockfd SOCK_DGRAM, addr , , , . SOCK_STREAM SOCK_SEQPACKET, , addr. Some protocol sockets (e.g., UNIX domain stream sockets) may successfully connect() only once. Some protocol sockets (e.g., datagram sockets in the UNIX and Internet domains) may use connect() multiple times to change their association. Some protocol sockets (e.g., TCP sockets as well as datagram sockets in the UNIX and Internet domains) may dissolve the association by connecting to an address with the sa_family member of sockaddr set to AF_UNSPEC; thereafter, the socket can be connected to another address. (AF_UNSPEC is supported since Linux 2.2.) If the connection or binding succeeds, zero is returned. On error, -1 is returned, and errno is set to indicate the error. . , . EACCES UNIX, : , . (. path_resolution(7).) EACCES EPERM , - . EACCES It can also be returned if an SELinux policy denied a connection (for example, if there is a policy saying that an HTTP proxy can only connect to ports associated with HTTP servers, and the proxy tries to connect to a different port). EADDRINUSE . EADDRNOTAVAIL ( ) , sockfd, , , . /proc/sys/net/ipv4/ip_local_port_range ip(7). EAFNOSUPPORT sa_family. EAGAIN UNIX . . EALREADY , . EBADF sockfd . ECONNREFUSED connect() . EFAULT . EINPROGRESS , ( UNIX EAGAIN). select(2) poll(2), , . , select(2) , getsockopt(2), SO_ERROR SOL_SOCKET, , connect() ( SO_ERROR ) ( SO_ERROR , , ). EINTR ; . signal(7). EISCONN . ENETUNREACH . ENOTSOCK sockfd . EPROTOTYPE . UNIX . ETIMEDOUT - . , , . , IP- - , syncookies. POSIX.1-2008. POSIX.1-2001, SVr4, 4.4BSD, (connect() first appeared in 4.2BSD). connect() , . . connect() getaddrinfo(3). . accept(2), bind(2), getsockname(2), listen(2), socket(2), path_resolution(7), selinux(8) Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 1 2023 . connect(2)