From f0187ac5c6b9ee8d600521a88e4c8a482744171c Mon Sep 17 00:00:00 2001 From: Clément Péron Date: Thu, 17 Feb 2022 18:38:59 +0100 Subject: netsniff-ng: dump stats on stderr when fdo is stdout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the output of netsniff-ng is configured as stdout, there is no more stats outputed. Let's output them on stderr. Signed-off-by: Clément Péron --- netsniff-ng.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/netsniff-ng.c b/netsniff-ng.c index aff569d..263078d 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -238,16 +238,21 @@ static void dump_rx_stats(struct ctx *ctx, int sock, bool is_v3) if (update_rx_stats(ctx, sock, is_v3)) return; - printf("\r%12"PRIu64" packets incoming (%"PRIu64" unread on exit)\n", + FILE *fd = stdout; + // In case the out device is stdout redirect to stderr + if (ctx->device_out && !strncmp("-", ctx->device_out, strlen("-"))) + fd = stderr; + + fprintf(fd, "\r%12"PRIu64" packets incoming (%"PRIu64" unread on exit)\n", is_v3 ? ctx->pkts_seen : ctx->pkts_recvd, is_v3 ? ctx->pkts_recvd - ctx->pkts_seen : 0); - printf("\r%12"PRIu64" packets passed filter\n", + fprintf(fd, "\r%12"PRIu64" packets passed filter\n", ctx->pkts_recvd - ctx->pkts_drops); - printf("\r%12"PRIu64" packets failed filter (out of space)\n", + fprintf(fd, "\r%12"PRIu64" packets failed filter (out of space)\n", ctx->pkts_drops); if (ctx->pkts_recvd > 0) - printf("\r%12.4lf%% packet droprate\n", + fprintf(fd, "\r%12.4lf%% packet droprate\n", (1.0 * ctx->pkts_drops / ctx->pkts_recvd) * 100.0); } -- cgit v1.2.3-54-g00ecf