pcap_loop 和 pcap_dispatch 到底有什么区别?
该手册对这一点的描述非常好(我是板着脸说的,保证)。从man pcap_loop
:
pcap_loop() processes packets from a live capture or ``savefile''
until cnt packets are processed, the end of the ``savefile'' is
reached when reading from a ``savefile'', pcap_breakloop() is called,
or an error occurs. It does not return when live read timeouts
occur. A value of -1 or 0 for cnt is equivalent to infinity, so that
packets are processed until another ending condition occurs.
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 ``save‐
file'' 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 pro‐
cessed. 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 reading a ``save‐
file''.
这有点像文字墙,所以让我们把它分解一下。
两种功能:
- Process packets from a live capture or "savefile" until any of these conditions occur:
- 达到指定计数
- 已到达“保存文件”末尾
- pcap_breakloop() 被调用
- 发生错误
- 考虑 -1 或 0 本质上意味着“处理无限数量的数据包”——也就是说,直到另一个结束条件发生。 (建议使用 -1 来实现与旧版本的互操作性,稍后将在手册中介绍)
单独 pcap_dispatch()
- 在进行实时捕获时,也会在达到当前数据包缓冲区的末尾后返回(换句话说,可以更频繁地返回,因为指定的计数不是最小值)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)