本代码编写环境:Fedora 17 gcc
编译命令 #gcc get_ethernet.c -o get_ethernet -lpcap
1 #include <pcap.h>
2 #define BUFSIZE 1024
3 struct ether_header
4 {
5 u_int8_t ether_dhost[6];
6 u_int8_t ether_shost[6];
7 u_int16_t ether_type;
8 };
9 void main()
10 {
11 char err_content[PCAP_ERRBUF_SIZE];
12 pcap_t* pcap_handle;
13 const u_char* packet_content;
14 u_char* mac_string;
15 u_short ethernet_type;
16 bpf_u_int32 net_mask;
17 bpf_u_int32 net_ip;
18 char* net_interface;
19 struct pcap_pkthdr pcap_header;
20 struct ether_header* ethernet_protocol;
21 struct bpf_program bpf_filter;
22 char bpf_filter_string[]="ip or arp or rarp";
23 net_interface=pcap_loo