aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-11-09 13:58:03 -0700
committerGerald Combs <gerald@wireshark.org>2018-11-10 01:59:09 +0000
commit3b68fc9fd4c307008d4bad685cab01889d375080 (patch)
tree152c4aab4fb44f7e1e6edcc7f08712b7c0c4a6f5 /dumpcap.c
parentab68b2c9ce3e0cfbbe585de0119ca2e5b18b6705 (diff)
Dumpcap: Move the "just wrote one packet" logic to one place.
Add capture_loop_wrote_one_packet, which increments the appropriate counters and checks for autostop and ring buffer conditions. Call it when we write a pcap or pcapng packet. This fixes `-b packets:NUM` for pcapng output. Change-Id: Ie2bdd725fbee59c1ae10b05be84ae9a3a6d80111 Reviewed-on: https://code.wireshark.org/review/30561 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 7590338422..ceeca8c82d 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -4154,6 +4154,37 @@ capture_loop_get_errmsg(char *errmsg, size_t errmsglen, char *secondary_errmsg,
}
}
+/*
+ * We wrote one packet. Update some statistics and check if we've met any
+ * autostop or ring buffer conditions.
+ */
+static void
+capture_loop_wrote_one_packet(capture_src *pcap_src) {
+ global_ld.packets_captured++;
+ global_ld.packets_written++;
+ pcap_src->received++;
+
+ /* check -c NUM / -a packets:NUM */
+ if (global_capture_opts.has_autostop_packets && global_ld.packets_captured >= global_capture_opts.autostop_packets) {
+ fflush(global_ld.pdh);
+ global_ld.go = FALSE;
+ return;
+ }
+ /* check -b packets:NUM */
+ if (global_capture_opts.has_file_packets && global_ld.packets_written >= global_capture_opts.file_packets) {
+ do_file_switch_or_stop(&global_capture_opts);
+ return;
+ }
+ /* check -a filesize:NUM */
+ if (global_capture_opts.has_autostop_filesize &&
+ global_capture_opts.autostop_filesize > 0 &&
+ global_ld.bytes_written / 1000 >= global_capture_opts.autostop_filesize) {
+ /* Capture size limit reached, do we have another file? */
+ do_file_switch_or_stop(&global_capture_opts);
+ return;
+ }
+}
+
/* one pcapng block was captured, process it */
static void
capture_loop_write_pcapng_cb(capture_src *pcap_src, const struct pcapng_block_header_s *bh, const u_char *pd)
@@ -4194,15 +4225,7 @@ capture_loop_write_pcapng_cb(capture_src *pcap_src, const struct pcapng_block_he
"Wrote a packet of length %d captured on interface %u.",
bh->block_total_length, pcap_src->interface_id);
#endif
- global_ld.packets_captured++;
- global_ld.packets_written++;
- pcap_src->received++;
-
- /* if the user told us to stop after x packets, do we already have enough? */
- if (global_capture_opts.has_autostop_packets && global_ld.packets_captured >= global_capture_opts.autostop_packets) {
- fflush(global_ld.pdh);
- global_ld.go = FALSE;
- }
+ capture_loop_wrote_one_packet(pcap_src);
}
}
}
@@ -4258,29 +4281,7 @@ capture_loop_write_packet_cb(u_char *pcap_src_p, const struct pcap_pkthdr *phdr,
"Wrote a packet of length %d captured on interface %u.",
phdr->caplen, pcap_src->interface_id);
#endif
- global_ld.packets_captured++;
- global_ld.packets_written++;
- pcap_src->received++;
-
- /* check -c NUM / -a packets:NUM */
- if (global_capture_opts.has_autostop_packets && global_ld.packets_captured >= global_capture_opts.autostop_packets) {
- fflush(global_ld.pdh);
- global_ld.go = FALSE;
- return;
- }
- /* check -b packets:NUM */
- if (global_capture_opts.has_file_packets && global_ld.packets_written >= global_capture_opts.file_packets) {
- do_file_switch_or_stop(&global_capture_opts);
- return;
- }
- /* check -a filesize:NUM */
- if (global_capture_opts.has_autostop_filesize &&
- global_capture_opts.autostop_filesize > 0 &&
- global_ld.bytes_written / 1000 >= global_capture_opts.autostop_filesize) {
- /* Capture size limit reached, do we have another file? */
- do_file_switch_or_stop(&global_capture_opts);
- return;
- }
+ capture_loop_wrote_one_packet(pcap_src);
}
}
}