1.libpcap的模式
 
- 有线环境: 使用
混杂模式promisous,完成监听 - 无线环境: 使用
监听模式monitor,完成监听 
 
2.交叉编译libpcap
 
- 设置好交叉编译工具链后
 - 下载libpcap源码
 - 使用configure进行构建:–disable-shared 构建静态库,–host 、–with-linux
 - 构建
 - 参考海思 tcpdump 移植开发详解
 
 
3.去掉pcap文件里每帧的fcs
 
- 利用libpcap库,读入待处理的pcap文件,然后去掉每帧尾部的4字节fcs,再写入新的pcap文件
 
 
#include <stdio.h>
#include <pcap.h>int main() {char errbuf[PCAP_ERRBUF_SIZE];pcap_t *handle;pcap_t *handle2;const u_char *packet;struct pcap_pkthdr header;int i;pcap_dumper_t *dumper;handle = pcap_open_offline("1.pcap", errbuf);if (handle == NULL) {printf("Error opening pcap file: %s\n", errbuf);return 1;}handle2 = pcap_open_dead(DLT_EN10MB, 65535);dumper = pcap_dump_open(handle2, "2.pcap");if (dumper == NULL) {printf("Error creating pcap file\n");return 1;}while ((packet = pcap_next(handle, &header)) != NULL) {header.len -= 4;header.caplen -= 4;pcap_dump((u_char *)dumper, &header, packet);}pcap_dump_close(dumper);pcap_close(handle2);pcap_close(handle);return 0;
}