libpcap, 32-bit&64-bit

 情况是这样的,在之前讲过的回播 .pcap 数据的 Velodyne_player 程序中,需要调用 Winpcap (其实就是 libpcap 的 Win挫版) 的 API 解析 .pcap 数据,再通过 UDP 发送出去。我们的 Velodyne_player 是一个 Win32 的程序,显然调用的就是32位的 Winpcap 库的 API; 后来我们也移植了一个 .pcap 采集程序的 Linux 版本,结果,用该 Linux 版本采集程序采集到的 .pcap 数据却没办法用我们 Win 下的 Velodyne_player 回播。后来发现,我们的 Linux 版本的采集程序用的是64位的 libpcap 库(因为系统是64位的 Ubuntu16.04,默认安装的就是64位的 libpcap 库),64位和32位的 libpcap,在时间戳上有很关键的区别,下面是开源的 pcap.h 中的声明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
* Generic per-packet information, as supplied by libpcap.
*
* The time stamp can and should be a "struct timeval", regardless of
* whether your system supports 32-bit tv_sec in "struct timeval",
* 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
* and 64-bit applications. The on-disk format of savefiles uses 32-bit
* tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit
* and 64-bit versions of libpcap, even if they're on the same platform,
* should supply the appropriate version of "struct timeval", even if
* that's not what the underlying packet capture mechanism supplies.
*/
struct pcap_pkthdr {
struct timeval ts; /* time stamp */
bpf_u_int32 caplen; /* length of portion present */
bpf_u_int32 len; /* length this packet (off wire) */
};