From c5b840ffcaf3eb1e22774bd357c1bcb5cd76a690 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Sat, 16 Mar 2013 14:28:15 +0100 Subject: 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 --- netsniff-ng.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3-54-g00ecf