Ethernet-HOWTO
... 3.7.16. Access to the raw Ethernet Device
How do I get access to the raw ethernet device in linux, without going through TCP/IP and friends?
______________________________________________________________________ int s=socket(AF_INET,SOCK_PACKET,htons(ETH_P_ALL)); ______________________________________________________________________
This gives you a socket receiving every protocol type. Do recvfrom() calls to it and it will fill the sockaddr with device type in sa_family and the device name in the sa_data array. I don't know who originally invented SOCK_PACKET for Linux (its been in for ages) but its superb stuff. You can use it to send stuff raw too via sendto() calls. You have to have root access to do either of course. ...
|