aboutsummaryrefslogtreecommitdiffstats
path: root/tshark.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-07-15 02:10:52 -0700
committerGuy Harris <gharris@sonic.net>2021-07-15 02:10:52 -0700
commit0822e8b3e52013aebceb1fe59fdb11ad69dea40f (patch)
treeae6f2a525a492def7515d81a9cc5591328050d86 /tshark.c
parent2a1ebd1e915278eed7b99ecb678578f683780f23 (diff)
tshark: fix the checks for --capture-comment.
Move those checks out of #ifdef HAVE_LIBPCAP/#endif, as that option is supported even if we don't build with pcap - it's also used when reading one file and writing another. Don't check for pcapng when deciding whether, when reading from an existing capture file, we can write it with added file comments; check whether the specified file type supports file comments and, if it doesn't, report all file formats that do as part of the error.
Diffstat (limited to 'tshark.c')
-rw-r--r--tshark.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/tshark.c b/tshark.c
index 7b8071d54c..7a9af3245e 100644
--- a/tshark.c
+++ b/tshark.c
@@ -746,7 +746,6 @@ main(int argc, char *argv[])
const gchar *volatile tls_session_keys_file = NULL;
exp_pdu_t exp_pdu_tap_data;
const gchar* elastic_mapping_filter = NULL;
- gboolean use_pcapng = TRUE;
/*
* The leading + ensures that getopt_long() does not permute the argv[]
@@ -1508,12 +1507,6 @@ main(int argc, char *argv[])
/* set the default file type to pcapng */
if (out_file_type == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN)
out_file_type = wtap_pcapng_file_type_subtype();
- if (out_file_type == wtap_pcapng_file_type_subtype()) {
- use_pcapng = TRUE;
- }
- else {
- use_pcapng = FALSE;
- }
/*
* Print packet summary information is the default if neither -V or -x
@@ -1720,26 +1713,6 @@ main(int argc, char *argv[])
exit_status = INVALID_OPTION;
goto clean_exit;
}
- if (capture_comments != NULL) {
- if (global_capture_opts.saving_to_file) {
- /* They specified a "-w" flag, so we'll be saving to a capture file.
- * This is fine if they're using pcapng.
- */
- if (!use_pcapng) {
- cmdarg_err("A capture comment can only be written to a pcapng file.");
- exit_status = INVALID_OPTION;
- goto clean_exit;
- }
- }
- else {
- cmdarg_err("A capture comment was specified, but "
- "a capture isn't being done\nand you aren't writing a capture file."
- "\nThere's no support for adding "
- "a capture comment to an existing capture file.");
- exit_status = INVALID_OPTION;
- goto clean_exit;
- }
- }
/* Note: TShark now allows the restriction of a _read_ file by packet count
* and byte count as well as a write file. Other autostop options remain valid
@@ -1755,6 +1728,8 @@ main(int argc, char *argv[])
/*
* "-r" wasn't specified, so we're doing a live capture.
*/
+ gboolean use_pcapng = TRUE;
+
if (perform_two_pass_analysis) {
/* Two-pass analysis doesn't work with live capture since it requires us
* to buffer packets until we've read all of them, but a live capture
@@ -1849,6 +1824,41 @@ main(int argc, char *argv[])
}
#endif
+ /*
+ * If capture comments were specified, -w also has to have been specified.
+ */
+ if (capture_comments != NULL) {
+ if (output_file_name) {
+ /* They specified a "-w" flag, so we'll be saving to a capture file.
+ * This is fine if they're writing in a format that supports
+ * section block comments.
+ */
+ if (wtap_file_type_subtype_supports_option(out_file_type,
+ WTAP_BLOCK_SECTION,
+ OPT_COMMENT) == OPTION_NOT_SUPPORTED) {
+ GArray *writable_type_subtypes;
+
+ cmdarg_err("Capture comments can only be written to files of the following types:");
+ writable_type_subtypes = wtap_get_writable_file_types_subtypes(FT_SORT_BY_NAME);
+ for (guint i = 0; i < writable_type_subtypes->len; i++) {
+ int ft = g_array_index(writable_type_subtypes, int, i);
+
+ if (wtap_file_type_subtype_supports_option(ft, WTAP_BLOCK_SECTION,
+ OPT_COMMENT) != OPTION_NOT_SUPPORTED)
+ cmdarg_err_cont(" %s - %s", wtap_file_type_subtype_name(ft),
+ wtap_file_type_subtype_description(ft));
+ }
+ exit_status = INVALID_OPTION;
+ goto clean_exit;
+ }
+ }
+ else {
+ cmdarg_err("Capture comments were specified, but you aren't writing a capture file.");
+ exit_status = INVALID_OPTION;
+ goto clean_exit;
+ }
+ }
+
err_msg = ws_init_sockets();
if (err_msg != NULL)
{