diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2014-10-01 13:42:12 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2014-10-01 13:42:12 +0200 |
commit | 07fa58ff28b700cf4bceb9f67db6af504f61a354 (patch) | |
tree | 7af88fef5b071218525aeb8a06b188827308d329 /netsniff-ng.c | |
parent | ac2c2cf23573e400e014628af22467ca43573c21 (diff) |
netsniff-ng: Combine redundant pcap file rotation logic into function
The code to create the next pcap dump file is duplicated for the
HAVE_TPACKET3 and !HAVE_TPACKET3 case. Consolidate the functionality
into a function to reduce code duplication.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'netsniff-ng.c')
-rw-r--r-- | netsniff-ng.c | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c index 47edbcd..427b5e9 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -798,6 +798,28 @@ static void print_pcap_file_stats(int sock, struct ctx *ctx) } } +static void update_pcap_next_dump(struct ctx *ctx, unsigned long snaplen, int *fd, int sock) +{ + if (!dump_to_pcap(ctx)) + return; + + if (ctx->dump_mode == DUMP_INTERVAL_SIZE) { + interval += snaplen; + if (interval > ctx->dump_interval) { + next_dump = true; + interval = 0; + } + } + + if (next_dump) { + *fd = next_multi_pcap_file(ctx, *fd); + next_dump = false; + + if (ctx->verbose) + print_pcap_file_stats(sock, ctx); + } +} + #ifdef HAVE_TPACKET3 static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, int sock, int *fd, unsigned long *frame_count) @@ -846,23 +868,7 @@ next: } } - if (dump_to_pcap(ctx)) { - if (ctx->dump_mode == DUMP_INTERVAL_SIZE) { - interval += hdr->tp_snaplen; - if (interval > ctx->dump_interval) { - next_dump = true; - interval = 0; - } - } - - if (next_dump) { - *fd = next_multi_pcap_file(ctx, *fd); - next_dump = false; - - if (unlikely(ctx->verbose)) - print_pcap_file_stats(sock, ctx); - } - } + update_pcap_next_dump(ctx, hdr->tp_snaplen, fd, sock); } } #endif /* HAVE_TPACKET3 */ @@ -1007,23 +1013,7 @@ next: if (unlikely(sigint == 1)) break; - if (dump_to_pcap(ctx)) { - if (ctx->dump_mode == DUMP_INTERVAL_SIZE) { - interval += hdr->tp_h.tp_snaplen; - if (interval > ctx->dump_interval) { - next_dump = true; - interval = 0; - } - } - - if (next_dump) { - fd = next_multi_pcap_file(ctx, fd); - next_dump = false; - - if (unlikely(ctx->verbose)) - print_pcap_file_stats(sock, ctx); - } - } + update_pcap_next_dump(ctx, hdr->tp_h.tp_snaplen, &fd, sock); } #endif /* HAVE_TPACKET3 */ |