I am writing code to send raw Ethernet frames between two Linux boxes. To test this, I just want to get a simple client-send and server-receive.
I have a client that creates packages correctly (I see them using the packet sniffer).
On the server side, I initialize the socket as follows:
fd = socket(PF_PACKET, SOCK_RAW, htons(MY_ETH_PROTOCOL));
where MY_ETH_PROTOCOL is a 2-byte constant, I use ethertype as a type, so I donβt hear extraneous network traffic.
when I bind this socket to my interface, I must pass the protocol to it again in the socket_addr structure: socket_address.sll_protocol = htons(MY_ETH_PROTOCOL);
If I compile and run such code, then it fails. My server does not see the package. However, if I changed the code like this:
socket_address.sll_protocol = htons(ETH_P_ALL);
Then the server can see the packet sent from the client (like many other packets), so I have to do some packet checking to see if it matches MY_ETH_PROTOCOL .
But I do not want my server to hear traffic that is not sent over the specified protocol, so this is not a solution. How to do it?
linux sockets ethernet
dschatz
source share