static int create_packetfd()
{
int fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
struct sockaddr_ll sll;
memset(&sll, 0, sizeof(sll));
struct sock_filter filters[] = {
/*sudo tcpdump -dd arp*/
{ 0x28, 0, 0, 0x0000000c },
{ 0x15, 11, 0, 0x00000806 },
{ 0x15, 0, 11, 0x00000800 },
{ 0x30, 0, 0, 0x00000017 },
{ 0x15, 0, 9, 0x00000011 },
{ 0x28, 0, 0, 0x00000014 },
{ 0x45, 7, 0, 0x00001fff },
{ 0xb1, 0, 0, 0x0000000e },
{ 0x48, 0, 0, 0x0000000e },
{ 0x15, 0, 4, 0x00000089 },
{ 0x50, 0, 0, 0x00000018 },
{ 0x54, 0, 0, 0x00000080 },
{ 0x15, 0, 1, 0x00000080 },
{ 0x6, 0, 0, 0x000007d0 },
{ 0x6, 0, 0, 0x00000000 },
};
struct sock_fprogfprog = {
.len = sizeof(filters)/sizeof(struct sock_filter),
.filter = filters
};
setsockopt(fd,SOL_SOCKET,SO_ATTACH_FILTER, &fprog, sizeof(struct sock_fprog));
return fd;
}
IPQueue就可以满足需求
页:
1
[2]