Linux Socket 系統

最後更新: 2022-05-18 17:00:37 +0800 +0800
原文以英文撰寫。您正在閱讀AI翻譯版本。

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 系列 #

FamilyAddressCommon Uses
AF_UNIXPathname or abstract nameLocal IPC
AF_INETIPv4 address and portTCP, UDP, raw IP
AF_INET6IPv6 address and portTCP, UDP, raw IPv6
AF_NETLINKKernel protocol and port IDKernel configuration APIs
AF_PACKETInterface and Ethernet protocolLink-layer packet access
AF_VSOCKVM CID and portHost/guest communication

評論

在 GitHub 上閱讀或評論(發表評論需要登入)