Linux Netzwerk Programmierung

Aus Primatenwiki
Zur Navigation springen Zur Suche springen

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.

Source: http://www.faqs.org/docs/ethernet/Ethernet-HOWTO-2.html


GNU Common C++

GNU Common C++ ist ein Framework, welches Multithreading- und Socketprogrammierung unterstützt.


Links