本人在fedora17下编写、测试正常运行,代码如下:
2 #include <string.h>
3 #include <stdlib.h>
4
5 //ARP Header,(assuming Ethernet + ip4)
6
7 #define ARP_REQUEST 1
8 #define ARP_REPLY 2
9
10 struct arphdr{
11 u_int16_t htype; //hardware type
12 u_int16_t ptype; //protocol type
13 u_char hlen; //hardware address length
14 u_char plen; //protocol address length
15 u_int16_t oper; //operation code
16 u_char sha[6]; //sendHardware address
17 u_char spa[4]; //sender ip address
18 u_char tha[6]; //target hardware address
19 u_char tpa[4]; //target ip address
20 };
21
22 #define MAXBYTES2CAPTURE 2048
23 int pcap_dloff(pcap_t *pd)
24 {
25 int offset = -1;
26 switch (pcap_datalink(pd))
27 {
28 case DLT_EN10MB:
29 offset = 14;
30 &nb