aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-10-13 17:18:50 -0700
committerGuy Harris <gharris@sonic.net>2021-10-13 17:18:50 -0700
commit79920cbc5fa679d18f12b71fddba20a119849a3f (patch)
treeadf5a378f1a6510cf2b09c110125e6d5c081dfc2 /dumpcap.c
parent74747c4d2ffef25c20d950525aa316bb5e2a0700 (diff)
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.
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c13
1 files changed, 7 insertions, 6 deletions
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++;
}