pcap_loop と pcap_dispatch の違いは何ですか?
10760 次
1 に答える
22
マニュアルはこれを驚くほどよく説明しています(私はそれをまっすぐな顔で言っています、約束します)。差出人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''.
これはちょっとしたテキストの壁なので、分解してみましょう。
両方の機能:
- これらの条件のいずれかが発生するまで、ライブキャプチャまたは「savefile」からのパケットを処理します。
- 指定されたカウントに達しました
- 「savefile」の終わりに到達しました
- pcap_breakloop()が呼び出されます
- エラーが発生します
- -1または0は、本質的に「無限の数のパケットを処理する」ことを意味します。つまり、別の終了条件が発生するまでです。(マニュアルの後半で、古いバージョンとの相互運用性のために-1をお勧めします)
pcap_dispatch()のみ
- また、ライブキャプチャを実行するときに、現在のバッファフルのパケットの終わりに達した後に戻ります(つまり、指定されたカウントが最小ではないため、より頻繁に戻る可能性があります)
于 2011-02-09T08:11:31.653 に答える