gpt4 book ai didi

c - 为什么 pcap_loop() 和获取数据包之间有很长的延迟?

转载 作者:IT王子 更新时间:2023-10-29 01:21:35 25 4
gpt4 key购买 nike

我正在使用 libpcap 编写嗅探器。我的问题是在调用 pcap_loop() 或 pcap_next() 和实际获取数据包(调用回调函数)之间有 7-10 秒的延迟。但是,如果我在同一台设备上使用带有相同过滤器的 wireshark,则在我点击“开始”按钮后就不会出现这种延迟。为什么我的程序有延迟,有没有办法解决这个问题?

我正在研究 atheros wifi 芯片。使用

将设备设置为监控模式
airmon-ng start wlan0

我确信有很多流量可以监听,因为我可以在 wireshark 中看到这些包。谢谢。

最佳答案

I'm using 10000

pcap_open_live()pcap_set_timeout()to_ms 参数以毫秒为单位。

10000 毫秒是 10 秒。

尝试使用 1000,这是 tcpdump 使用的值 - 这会将延迟减少到 1 秒 - 或者使用 100,这是 Wireshark 使用的值 - 这会将延迟减少到 1/10 秒。

I read on a tutorial about this field: " on at least some platforms, this means that you may wait until a sufficient number of packets arrive before seeing any packets, so you should use a non-zero timeout"

有问题的教程是the tcpdump.org "How to use libpcap" tutorial ,并且有问题的段落已添加到此 CVS 提交中:

revision 1.8
date: 2005/08/27 23:58:39; author: guy; state: Exp; lines: +34 -31
Use a non-zero timeout in pcap_open_live(), so you don't wait for a
bufferful of packets before any are processed.

Correctly explain the difference between pcap_loop() and
pcap_dispatch().

In sniffex.c, don't print the payload if there isn't any.

所以我对它很熟悉。 :-)

我不得不花一些时间(再次)查看 Linux 内核代码,以了解超时值为 0 会对较新的内核产生什么影响。但是,在编写使用 libpcap/WinPcap 进行实时捕获的代码时,您应该始终表现得好像您正在为此类平台编写代码;如果零超时的行为发生变化,您的代码将更易于移植到其他平台并且不会中断。

关于c - 为什么 pcap_loop() 和获取数据包之间有很长的延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com