From 278f62a9da99dcca7a7b95f34635b0fcd1a88185 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 25 Jun 2013 12:30:58 +0200 Subject: netsniff-ng: tpacketv3: 'fix' packet accounting output In netsniff-ng, we use tpacketv3 for capturing-only mode. The issue observed lately is that when using f.e. -n10 or capturing a pcap and then quitting, the pcap or actually seen number of packets are less than what the statistics tell us from getsockopt(2). This is due to the fact that tpacketv3 divides its ring buffer into blocks of frames. Meaning, while we are traversing block n, the kernel already fills up block n+1 and following if new packets arrive. While doing so, it increments packet counters. Thus, when we ^C, we haven't seen those blocks, so the stats tell us mostly a slightly higher result. Fix this by adjusting socket stats printing to this fact. Signed-off-by: Daniel Borkmann --- netsniff-ng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'netsniff-ng.c') diff --git a/netsniff-ng.c b/netsniff-ng.c index c5570fc..19d4db3 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -479,7 +479,7 @@ static void receive_to_xmit(struct ctx *ctx) timer_purge(); - sock_rx_net_stats(rx_sock); + sock_rx_net_stats(rx_sock, 0); bpf_release(&bpf_ops); @@ -989,7 +989,7 @@ static void recv_only_or_dump(struct ctx *ctx) timersub(&end, &start, &diff); if (!(ctx->dump_dir && ctx->print_mode == PRINT_NONE)) { - sock_rx_net_stats(sock); + sock_rx_net_stats(sock, frame_count); printf("\r%12lu sec, %lu usec in total\n", diff.tv_sec, diff.tv_usec); -- cgit v1.2.3-54-g00ecf