gpt4 book ai didi

python - 为什么 pcap_dispatch 只返回 1 个数据包?

转载 作者:行者123 更新时间:2023-11-30 15:24:51 24 4
gpt4 key购买 nike

为什么pcap_dispatch(count=10)只返回1个数据包?

如果我不执行任何操作,它会等待,然后显示 1 个数据包,但如果我单击链接,它会立即停止并显示 1 个数据包。

我是否应该有这样的循环?:

for i in range(0,10):
p.dispatch(10, savePacket)

这是Python,但我在C中遇到了同样的问题。

最佳答案

来自手册页:

       pcap_dispatch() processes packets from a live capture or ``savefile'' until       cnt  packets  are processed, the end of the current bufferful of packets is       reached when doing a live capture, the end of the ``savefile''  is  reached       when  reading  from a ``savefile'', pcap_breakloop() is called, or an error       occurs.  Thus, when doing a live capture, cnt  is  the  maximum  number  of       packets  to  process  before  returning,  but is not a minimum number; when       reading a live capture, only one bufferful of packets is read at a time, so       fewer  than cnt packets may be processed. A value of -1 or 0 for cnt causes       all the packets received in one buffer to be processed when reading a  live       capture,  and causes all the packets in the file to be processed when read‐       ing a ``savefile''.

请注意下面的内容:“可以处理的数据包数量少于 cnt - 也就是说,这取决于 pcap 实现的作用。

关于 Python 的注释:我不知道 python 实现的作用是什么,但在 C 中,无论如何都会为每个数据包调用一次回调。

关于python - 为什么 pcap_dispatch 只返回 1 个数据包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28199196/

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