pcap_loop 和 pcap_dispatch 区别

发布于 2024-10-16 13:29:32 字数 41 浏览 7 评论 0原文

pcap_loop 和 pcap_dispatch 到底有什么区别?

What exactly is the difference between pcap_loop and pcap_dispatch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挥剑断情 2024-10-23 13:29:32

该手册对这一点的描述非常好(我是板着脸说的,保证)。来自 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''.

这有点像文字墙,所以让我们将其分解。

两个功能

  • 处理来自实时捕获或“保存文件”的数据包,直到发生以下任何情况:
    • 达到指定计数
    • 已到达“保存文件”末尾
    • 调用 pcap_breakloop()
    • 发生错误
  • 考虑 -1 或 0 本质上意味着“处理无限数量的数据包” - 也就是说,直到另一个结束条件发生。 (建议使用 -1 来实现与旧版本的互操作性,详见手册)

单独使用 pcap_dispatch()

  • 在进行实时捕获时,也会在当前数据包缓冲区结束后返回(换句话说) ,可以更频繁地返回,因为指定的计数不是最小值)

The manual describes this amazingly well (I'm saying that with a straight face, promise). From 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''.

That's a bit of a wall-of-text, so let's break it down.

Both functions:

  • Process packets from a live capture or "savefile" until any of these conditions occur:
    • the specified count is reached
    • the end of the "savefile" is reached
    • pcap_breakloop() is called
    • an error occurs
  • Consider -1 or 0 to essentially mean "process an infinite number of packets" - that is, until another end condition occurs. (-1 is recommended for interoperability with older versions, later in the manual)

pcap_dispatch() alone

  • Also returns after the end of the current bufferful of packets is reached, when doing a live capture (in other words, can return more often, since the specified count is not a minimum)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文