#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <linux/if_ether.h>
#include <net/if.h>
int main()
{
int n;
int fd;
unsigned char buff[2048];
struct sockaddr_ll from;
int socklen;
fd = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
while(1){
n = recvfrom(fd , buff, 2047, 0, (struct sockaddr*)&from, &socklen);
if (n < 0)
perror("recvfrom error!\n");
printf("%d bytes recived\n", n);
}
close(fd);
}