libpcap:哪些平台通过 pcap_set_timeout() 支持数据包缓冲区超时?

libpcap: which platforms support packet buffer timeout via pcap_set_timeout()?

如果在设定的时间段内没有收到任何数据包,我希望 pcap_dispatch() 超时。类似这样 SO question.

pcap(3) manpage中说不是所有平台都支持:

Not all platforms support a packet buffer timeout; on platforms that don't, the packet buffer timeout is ignored. A zero value for the timeout, on platforms that support a packet buffer timeout, will cause a read to wait forever to allow enough packets to arrive, with no timeout. A negative value is invalid; the result of setting the timeout to a negative value is unpredictable.

in this post,用户 862787 说“有些操作系统超时,即使 没有数据包到达,其他人没有

It's considered platform-specific because it is, but it's not considered buggy (trust me, I'm the person who wrote that text in the man page) - the timeout is to keep pcap_dispatch() from waiting forever for a packet buffer to fill, not to keep it from waiting forever for any packets to arrive at all. Some OSes time out even if no packets have arrived, others don't. – user862787 Oct 19 '12 at 20:53

那么我怎么知道哪些平台支持哪些平台不支持呢?我搜索并浏览了 libpcap 来源,但没有找到任何东西。

具体来说,Centos 8.1,内核 4.18.0-147.el8.x86_64,libpcap 1.10 怎么样?

在使用 BPF 捕获机制的系统上 - *BSD、macOS、Solaris 11、AIX - 即使没有数据包到达也会发生超时。

在大多数 Linux 发行版的大多数版本中,它不会。

不要指望它这样做或不这样做;编写你的代码不要依赖于它。

I've searched and gone through the libpcap source but didn't find anything.

您需要查看 libpcap 在特定平台上使用的捕获机制的源代码,而不是 libpcap 源代码。