Fix PktSrc::Statistics returning bogus stats.

When reading from trace files, 'dropped' and 'link' fields are now
just zeroed.

When reading from an interface, the values filled in by pcap_stats()
are now only used when that function indicates success.

Closes #500.
This commit is contained in:
Jon Siwek 2011-08-01 16:25:27 -05:00
parent c0c8b515f9
commit d6d34f3a1f
3 changed files with 23 additions and 8 deletions

View file

@ -393,21 +393,27 @@ void PktSrc::AddSecondaryTablePrograms()
void PktSrc::Statistics(Stats* s)
{
struct pcap_stat pstat;
if ( reading_traces )
s->received = s->dropped = s->link = 0;
else if ( pcap_stats(pd, &pstat) < 0 )
else
{
reporter->Error("problem getting packet filter statistics: %s",
ErrorMsg());
s->received = s->dropped = s->link = 0;
struct pcap_stat pstat;
if ( pcap_stats(pd, &pstat) < 0 )
{
reporter->Error("problem getting packet filter statistics: %s",
ErrorMsg());
s->received = s->dropped = s->link = 0;
}
else
{
s->dropped = pstat.ps_drop;
s->link = pstat.ps_recv;
}
}
s->received = stats.received;
s->dropped = pstat.ps_drop;
s->link = pstat.ps_recv;
if ( pseudo_realtime )
s->dropped = 0;

View file

@ -0,0 +1 @@
[pkts_recvd=131, pkts_dropped=0, pkts_link=0]

View file

@ -0,0 +1,8 @@
# Checks that accurate stats are returned when reading from a trace file.
# @TEST-EXEC: bro -r $TRACES/wikipedia.trace >output %INPUT
# @TEST-EXEC: btest-diff output
event bro_done()
{
print net_stats();
}