Objective: Gain familiarity with raw packet sockets, and parsing network packets, by writing a simple program.
Deliverables: The source code to your program, as well as a screenshot of the output, in hard copy.
Teams: You should write your code individually, although you may of course discuss with classmates.
Grading: 10 points, as described below.
In this assignment, you are to write a basic traffic sniffer, that listens for packets, and prints out their Ethernet and IP headers. The program must use raw packet sockets (
SOCK_RAW). Your program should be written in C or C++. You will have to use Mininet to test your program (this socket type needs root access). Specifically your programs must do the following:
int s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));(1 point)
sockaddr_ll, and set the
sll_ifindexmembers appropraitely. The family should be
AF_PACKET, the protocol should be
htons(ETH_P_ALL), and the interface index should be the index for whatever interface you want to listen on. The index can be obtained from the interface name using
if_nametoindex. (1 point)
bindto bind the socket you created to the address (1 point)
recvfrom, with a
sockaddr_llas the address. (1 point)
sll_pkttypein the address is
/usr/include/net/ethernet.h. (3 points)
/usr/include/netinet/ip.h). (2 points)
All printing should be done in the expected format for the information (IP addresses should look like the standard text format for IP addresses, etc).