Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Linux 中打开一个 RAW 套接字并读取所有消息。
recvmsg(mysock, &msg, 0);
我正在遍历那个 msg 缓冲区上的所有 cmsg,但我只得到一个。
for (c = CMSG_FIRSTHDR(&msg); c; c = CMSG_NXTHDR(&msg, c)) {
如何提取它收到的 ifindex ?
找到了。我必须先设置 IP_PKTINFO 标志:
setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &hold, sizeof(hold));