两个套接字都接收到了带有 vlan 标记 10 和 20 的数据包。为什么我收到了 4 个数据包,而只发送了 2 个数据包,并且所有收到的数据包都未标记(没有 vlan 标记)?可能是什么问题?
以下是相关代码:创建:sock = socket(AF_PACKET, SOCK_RAW, htons(MY_ETHTYPE));
memset(&if_opts, 0, sizeof(if_opts));
strncpy(if_opts.ifr_name, "eth1.10", IFNAMSIZ - 1);
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (void *)&if_opts, sizeof(if_opts);
ioctl(sock, SIOCGIFFLAGS, &if_opts);
if_opts.ifr_flags |= IFF_PROMISC;
ioctl(sock, SIOCSIFFLAGS, &if_opts);
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE,
"eth1.10",
sizeof("eth1.10"));
Recv:size = recvfrom(sock, buf,BUF_SIZE,MSG_DONTWAIT,NULL,NULL);