Reputation: 2028
I want to receive ethernet packets from socket in Linux, but only those, which have one of two custom Ethtype values. As I know, if only 1 ethtype should be received, it's possible to specify this value while creating socket like this
int socket = socket(PF_PACKET, SOCK_RAW, htons(ETHERTYPE_CUSTOM_1);
But what if I have 2 different ethtypes? Should I use 2 sockets or write some custom filter? Or is there some any simple way?
Upvotes: 0
Views: 531
Reputation: 780655
Create two sockets, one for each ethertype. Then you can use select()
or epoll()
to wait for packets on either socket at the same time.
Upvotes: 1
Reputation: 35
I think you should use libpcap library. You need to access bpf packer filter. This is easy one. Or you can use iptables rules an netfilter library. You need to set prerouting iptables rules to forward all packet to specific port and your application binding this port as listening mode and you can receive full packet.
Upvotes: 0