Espero que isso lance alguma luz sobre o assunto. Na página de manual :
When tcpdump finishes capturing packets, it will report counts of:
packets captured (this is the number of packets that tcpdump has received and processed);
packets received by filter (the meaning of this depends on the OS on which you're running tcpdump, and possibly on the way the OS was configured - if a filter was specified on the command line, on some OSes it counts packets regardless of whether they were matched by the filter expression and, even if they were matched by the filter expression, regardless of whether tcpdump has read and processed them yet, on other OSes it counts only packets that were matched by the filter expression regardless of whether tcpdump has read and processed them yet, and on other OSes it counts only packets that were matched by the filter expression and were processed by tcpdump);
packets dropped by kernel (this is the number of packets that were dropped, due to a lack of buffer space, by the packet capture mechanism in the OS on which tcpdump is running, if the OS reports that information to applications; if not, it will be reported as 0).
E há uma entrada de uma lista de discussão de 2009 explicando:
The "packets received by filter" number is the
ps_recv
number from a call topcap_stats()
; with BPF, that's thebs_recv
number from theBIOCGSTATS ioctl
. That count includes all packets that were handed to BPF; those packets might still be in a buffer that hasn't yet been read by libpcap (and thus not handed to tcpdump), or might be in a buffer that's been read by libpcap but not yet handed to tcpdump, so it can count packets that aren't reported as "captured".
Talvez o processo seja morto rápido demais? Há também um sinalizador -c N
informando ao tcpdump para sair quando N
dos pacotes foram capturados.
Como o seu problema parece bastante especializado, você também pode usar libpcap
diretamente ou via uma das centenas de ligações de idioma .
Para sua pergunta, já que tudo que você obtém são os pacotes capturados no arquivo capture.cap
, você pode ver as execuções que não estão vazias e examiná-las, isto é, uhm, contar as linhas?
tcpdump -r capture.cap | wc -l
Provavelmente existe uma maneira melhor de usar o libpcap para retornar o número de entradas no arquivo de captura ...