Socket 是代表通訊通道其中一個端點的檔案描述元。
程式會以 socket(2) 建立 Socket,接著通常對它進行繫結或連線,並使用
read(2)/write(2) 或 send(2)/recv(2)。
c
int sockfd = socket(int domain, int type, int protocol);domain 選取位址系列,例如 AF_INET、AF_INET6、AF_UNIX 或
AF_NETLINK。type 選取語意,例如 SOCK_STREAM、SOCK_DGRAM 或
SOCK_SEQPACKET;protocol 通常會在該組合中選取具體協定,或由 0 選取預設值。
常見 Socket 系列 #
| 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 |
評論
在 GitHub 上閱讀或評論(發表評論需要登入)