A socket is a file descriptor representing one endpoint of a communications channel.
Programs create one with socket(2), then usually bind or connect it and use
read(2)/write(2) or send(2)/recv(2).
c
int sockfd = socket(int domain, int type, int protocol);The domain selects an address family such as AF_INET, AF_INET6, AF_UNIX, or
AF_NETLINK. The type selects a semantic such as SOCK_STREAM, SOCK_DGRAM, or
SOCK_SEQPACKET; the protocol normally selects a concrete protocol within that
combination, or 0 selects the default.
Common Socket Families #
| Family | Address | Common Uses |
|---|---|---|
AF_UNIX | Pathname or abstract name | Local IPC |
AF_INET | IPv4 address and port | TCP, UDP, raw IP |
AF_INET6 | IPv6 address and port | TCP, UDP, raw IPv6 |
AF_NETLINK | Kernel protocol and port ID | Kernel configuration APIs |
AF_PACKET | Interface and Ethernet protocol | Link-layer packet access |
AF_VSOCK | VM CID and port | Host/guest communication |
Comments
Read or comment on GitHub (sign-in required to comment)