connect(2) System Calls Manual connect(2) connect - C (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. (, UNIX) connect() . (, UNIX ) connect() . 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() 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 , Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 2 2024 . connect(2)