diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-03-16 14:28:15 +0100 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-03-16 14:28:15 +0100 |
commit | c5b840ffcaf3eb1e22774bd357c1bcb5cd76a690 (patch) | |
tree | 205ef0b9d81ba3f88675ba5f52215238e682a6a2 | |
parent | d040e1715d0afb74a474bcf1552e250cbceb8966 (diff) |
netsniff-ng: if we cannot get intermediate pcap statistics, panic
Before we do calculations on statistics, check if we really got them.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r-- | netsniff-ng.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c index 6f7c4c2..0f97acd 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -767,12 +767,16 @@ static int begin_single_pcap_file(struct ctx *ctx) static void print_pcap_file_stats(int sock, struct ctx *ctx, unsigned long skipped) { + int ret; unsigned long good, bad; struct tpacket_stats kstats; socklen_t slen = sizeof(kstats); fmemset(&kstats, 0, sizeof(kstats)); - getsockopt(sock, SOL_PACKET, PACKET_STATISTICS, &kstats, &slen); + + ret = getsockopt(sock, SOL_PACKET, PACKET_STATISTICS, &kstats, &slen); + if (unlikely(ret)) + panic("Cannot get packet statistics!\n"); if (ctx->print_mode == PRINT_NONE) { good = kstats.tp_packets - kstats.tp_drops - skipped; |