diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-11-09 13:58:03 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2018-11-10 01:59:09 +0000 |
commit | 3b68fc9fd4c307008d4bad685cab01889d375080 (patch) | |
tree | 152c4aab4fb44f7e1e6edcc7f08712b7c0c4a6f5 /dumpcap.c | |
parent | ab68b2c9ce3e0cfbbe585de0119ca2e5b18b6705 (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.c | 65 |
1 files changed, 33 insertions, 32 deletions
@@ -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); } } } |