socket(2) System Calls Manual socket(2) socket - C (libc, -lc) #include int socket(int domain, int type, int protocol); socket() , . , . domain : , . . Linux : AF_UNIX unix(7) AF_LOCAL AF_UNIX AF_INET IPv4 ip(7) AF_AX25 . ax25(4) AX.25 AF_IPX Novell IPX AF_APPLETALK AppleTalk ddp(7) AF_X25 ITU-T X.25 / ISO/IEC 8208 protocol x25(7) AF_INET6 IPv6 ipv6(7) AF_DECnet DECet AF_KEY , IPsec AF_NETLINK netlink(7) AF_PACKET packet(7) AF_RDS . . . rds(7) rds-rdma(7) (RDS) AF_PPPOX PPP L2 (L2TP PPPoE) AF_LLC . (IEEE 802.2 LLC) AF_IB . InfiniBand AF_MPLS . AF_CAN . AF_TIPC . << >> TIPC AF_BLUETOOTH . Bluetooth AF_ALG . -API AF_VSOCK . VSOCK vsock(7) ( <>) - AF_KCM . KCM (kernel connection multiplexer) interface AF_XDP . XDP (express data path) , , address_families(7). type, . : SOCK_STREAM , . . SOCK_DGRAM ( ). SOCK_SEQPACKET ; ; . SOCK_RAW . SOCK_RDM , . SOCK_PACKET ; . packet(7). . Linux 2.6.27, type : , socket() : SOCK_NONBLOCK O_NONBLOCK ( open(2)), . fcntl(2) . SOCK_CLOEXEC close-on-exec (FD_CLOEXEC) . O_CLOEXEC open(2) , . protocol , . , , protocol 0. , , . " ", ; . protocols(5). getprotoent(3), , . SOCK_STREAM . . , . connect(2). read(2) write(2) send(2) recv(2). , close(2). , send(2), , recv(2). , SOCK_STREAM, , . , , , . SO_KEEPALIVE, - , . , <<>> , SIGPIPE; , , , . SOCK_SEQPACKET , SOCK_STREAM. , read(2) , . . SOCK_DGRAM SOCK_RAW , sendto(2). recvfrom(2), . SOCK_PACKET ; . packet(7). fcntl(2) F_SETOWN , SIGURG, , SIGPIPE, SOCK_STREAM . , , - SIGIO. F_SETOWN ioctl(2) FIOSETOWN SIOCSPGRP. When the network signals an error condition to the protocol module (e.g., using an ICMP message for IP) the pending error flag is set for the socket. The next operation on this socket will return the error code of the pending error. For some protocols, it is possible to enable a per-socket error queue to retrieve detailed information about the error; see IP_RECVERR in ip(7). options. . setsockopt(2) getsockopt(2) , . On success, a file descriptor for the new socket is returned. On error, -1 is returned, and errno is set to indicate the error. EACCES / . EAFNOSUPPORT . EINVAL . EINVAL type. EMFILE . ENFILE . ENOBUFS ENOMEM . , . EPROTONOSUPPORT . . POSIX.1-2024 specifies SOCK_CLOFORK, but Linux doesn't support it. POSIX.1-2024. POSIX.1-2001, 4.2BSD. It is generally portable to/from non-BSD systems supporting clones of the BSD socket layer (including System V variants). 4.x BSD PF_UNIX, PF_INET, PF_INET . ., AF_UNIX, AF_INET . . . , BSD : <<, >> AF_*. SOCK_NONBLOCK SOCK_CLOEXEC POSIX.1-2024. socket() getaddrinfo(3). accept(2), bind(2), close(2), connect(2), fcntl(2), getpeername(2), getsockname(2), getsockopt(2), ioctl(2), listen(2), read(2), recv(2), select(2), send(2), shutdown(2), socketpair(2), write(2), getprotoent(3), address_families(7), ip(7), socket(7), tcp(7), udp(7), unix(7) "An Introductory 4.3BSD Interprocess Communication Tutorial" and "BSD Interprocess Communication Tutorial", reprinted in UNIX Programmer's Supplementary Documents Volume 1. () Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 29 2025 . socket(2)