2011-02-06 14 views

Odpowiedz

15

Instrukcja opisuje to zdumiewająco dobrze (mówię to z prostą twarzą, obietnicą). Od 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''. 

wiem, że tak naprawdę nie chce się czytać i zrozumieć to wszystko, więc niech to rozbicie go.

Obie funkcje:

  • przetwarza pakiety z wychwytywania żywej lub „zbiorze składowania” przez każdą z tych warunków:
    • określona liczba osiągnięciu
    • koniec „zbiorze składowania "zostaje osiągnięty
    • pcap_breakloop() nazywa się
    • pojawia się błąd
  • Należy wziąć pod uwagę wartość -1 lub 0, aby w istocie oznaczać "przetwarzanie nieskończonej liczby pakietów" - to znaczy, dopóki nie wystąpi inny warunek końcowy. (-1 jest zalecany do współdziałania ze starszymi wersjami, w dalszej części instrukcji)

pcap_dispatch() sam

  • zwraca także po zakończeniu bieżącego bufferful pakietów zostanie osiągnięty, gdy robi przechwytywanie na żywo (innymi słowy, można częściej zwracać, ponieważ określona liczba nie jest minimalna)