From 79920cbc5fa679d18f12b71fddba20a119849a3f Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 13 Oct 2021 17:18:50 -0700 Subject: dumpcap: do all packet counting in capture_loop_wrote_one_packet(). We need to update global_ld.inpkts_to_sync_pipe as soon as we've written a packet to the current capture file. If we're writing to multiple files, then, if we delay counting until after we switch to another file, the packet-count message we send to the parent before switching won't include the packet, and the first packet-count message we send to the parent *after* switching *will* include the packet, which could mean the parent will try to read more packets than there are in the new file, in which case it'll get an EOF and, at least in the case of TShark, treat that as an error and stop capturing. This should fix issue #17654. While we're at it, don't send a "we have no packets" packet-count message even for the packet-count message we send just before switching files. --- dumpcap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'dumpcap.c') diff --git a/dumpcap.c b/dumpcap.c index 43d85b63f8..80f66a9d1b 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -3760,9 +3760,11 @@ do_file_switch_or_stop(capture_options *capture_opts) global_ld.next_interval_time = get_next_time_interval(global_ld.interval_s); } fflush(global_ld.pdh); - if (!quiet) - report_packet_count(global_ld.inpkts_to_sync_pipe); - global_ld.inpkts_to_sync_pipe = 0; + if (global_ld.inpkts_to_sync_pipe) { + if (!quiet) + report_packet_count(global_ld.inpkts_to_sync_pipe); + global_ld.inpkts_to_sync_pipe = 0; + } report_new_capture_file(capture_opts->save_file); } else { /* File switch failed: stop here */ @@ -4081,8 +4083,6 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct #endif if (inpkts > 0) { - global_ld.inpkts_to_sync_pipe += inpkts; - if (capture_opts->output_to_pipe) { fflush(global_ld.pdh); } @@ -4161,7 +4161,6 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct if (!dequeued) { break; } - global_ld.inpkts_to_sync_pipe += 1; if (capture_opts->output_to_pipe) { fflush(global_ld.pdh); } @@ -4475,6 +4474,8 @@ static void capture_loop_wrote_one_packet(capture_src *pcap_src) { global_ld.packets_captured++; global_ld.packets_written++; + global_ld.inpkts_to_sync_pipe++; + if (!use_threads) { pcap_src->received++; } -- cgit v1.2.3