diff options
author | Clément Péron <peron.clem@gmail.com> | 2022-02-17 18:38:59 +0100 |
---|---|---|
committer | Tobias Klauser <tobias.klauser@gmail.com> | 2022-02-18 12:04:51 +0100 |
commit | f0187ac5c6b9ee8d600521a88e4c8a482744171c (patch) | |
tree | c8f15fc45c03335d9303e573beefdd33fbe18b0e | |
parent | 7c1f4598217c1ae2987a83756cfeaac04650d8d9 (diff) |
netsniff-ng: dump stats on stderr when fdo is stdout
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 <peron.clem@gmail.com>
-rw-r--r-- | netsniff-ng.c | 13 |
1 files 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); } |