aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-07-14 22:16:30 -0700
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-07-15 05:43:36 +0000
commit0a9ef601d201f87ff3effb8aca62c61184fd6146 (patch)
treece64e2ddc50cdf76bbc4dc785e069a50a820c7b4 /ui
parent94ac641efabc9830bc91db1c793bf0ba42f1e46c (diff)
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's available only if we're being built with capture support, and --capture-comment can be used in TShark when reading a capture file and writing another capture file, with no live capture taking place. This means we don't handle that option in capture_opts_add_opt(); handle it in the programs that support it. Support writing multiple comments in dumpcap when capturing. These changes also fix builds without pcap, and makes --capture-comment work in Wireshark when a capture is started from the command line with -k. Update the help messages to indicate that --capture-comment adds a capture comment, it doesn't change any comment (much less "the" comment, as there isn't necessarily a single comment). Update the man pages: - not to presume that only pcapng files support file comments (even if that's true now, it might not be true in the future); - to note that multiple instances of --capture-comment are supported, and that multiple comments will be written, whether capturing or reading one file and writing another; - clarify that Wireshark doesn't *discard* SHB comments other than the first one, even though it only displays the first one;
Diffstat (limited to 'ui')
-rw-r--r--ui/capture.c7
-rw-r--r--ui/capture.h6
-rw-r--r--ui/commandline.c18
-rw-r--r--ui/commandline.h7
-rw-r--r--ui/qt/main.cpp4
-rw-r--r--ui/qt/main_window_slots.cpp3
6 files changed, 39 insertions, 6 deletions
diff --git a/ui/capture.c b/ui/capture.c
index b88c86efdd..cff9d4ae6f 100644
--- a/ui/capture.c
+++ b/ui/capture.c
@@ -117,7 +117,9 @@ capture_callback_remove(capture_callback_t func, gpointer user_data)
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
gboolean
-capture_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void(*update_cb)(void))
+capture_start(capture_options *capture_opts, GPtrArray *capture_comments,
+ capture_session *cap_session, info_data_t* cap_data,
+ void(*update_cb)(void))
{
GString *source;
@@ -128,7 +130,8 @@ capture_start(capture_options *capture_opts, capture_session *cap_session, info_
cf_set_tempfile_source((capture_file *)cap_session->cf, source->str);
g_string_free(source, TRUE);
/* try to start the capture child process */
- if (!sync_pipe_start(capture_opts, cap_session, cap_data, update_cb)) {
+ if (!sync_pipe_start(capture_opts, capture_comments, cap_session,
+ cap_data, update_cb)) {
/* We failed to start the capture child. */
if(capture_opts->save_file != NULL) {
g_free(capture_opts->save_file);
diff --git a/ui/capture.h b/ui/capture.h
index 6589dfc8e7..f02e18ed92 100644
--- a/ui/capture.h
+++ b/ui/capture.h
@@ -60,13 +60,17 @@ capture_input_init(capture_session *cap_session, capture_file *cf);
* Start a capture session.
*
* @param capture_opts the numerous capture options
+ * @param capture_comments if not NULL, a GPtrArray * to a set of comments
+ * to put in the capture file's Section Header Block if it's a pcapng file
* @param cap_session the handle for the capture session
* @param cap_data a struct with capture info data
* @param update_cb update screen
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
extern gboolean
-capture_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void(*update_cb)(void));
+capture_start(capture_options *capture_opts, GPtrArray *capture_comments,
+ capture_session *cap_session, info_data_t* cap_data,
+ void(*update_cb)(void));
/** Stop a capture session (usually from a menu item). */
extern void
diff --git a/ui/commandline.c b/ui/commandline.c
index 66a82493ab..66f7ebe111 100644
--- a/ui/commandline.c
+++ b/ui/commandline.c
@@ -173,8 +173,10 @@ commandline_print_usage(gboolean for_help_option) {
fprintf(output, "\n");
fprintf(output, "Output:\n");
fprintf(output, " -w <outfile|-> set the output filename (or '-' for stdout)\n");
+#ifdef HAVE_LIBPCAP
fprintf(output, " --capture-comment <comment>\n");
- fprintf(output, " set the capture file comment, if supported\n");
+ fprintf(output, " add a capture file comment, if supported\n");
+#endif
ws_log_print_usage(output);
@@ -197,6 +199,7 @@ commandline_print_usage(gboolean for_help_option) {
}
#define LONGOPT_FULL_SCREEN LONGOPT_BASE_GUI+1
+#define LONGOPT_CAPTURE_COMMENT LONGOPT_BASE_GUI+2
#define OPTSTRING OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:g:HhjJ:klm:o:P:r:R:Svw:X:Y:z:"
static const struct option long_options[] = {
@@ -206,6 +209,7 @@ static const struct option long_options[] = {
{"display-filter", required_argument, NULL, 'Y' },
{"version", no_argument, NULL, 'v'},
{"fullscreen", no_argument, NULL, LONGOPT_FULL_SCREEN },
+ {"capture-comment", required_argument, NULL, LONGOPT_CAPTURE_COMMENT},
LONGOPT_CAPTURE_COMMON
LONGOPT_DISSECT_COMMON
{0, 0, 0, 0 }
@@ -407,6 +411,7 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
global_commandline_info.list_link_layer_types = FALSE;
global_commandline_info.list_timestamp_types = FALSE;
global_commandline_info.quit_after_cap = getenv("WIRESHARK_QUIT_AFTER_CAPTURE") ? TRUE : FALSE;
+ global_commandline_info.capture_comments = NULL;
#endif
global_commandline_info.full_screen = FALSE;
@@ -587,6 +592,17 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
case LONGOPT_FULL_SCREEN:
global_commandline_info.full_screen = TRUE;
break;
+#ifdef HAVE_LIBPCAP
+ case LONGOPT_CAPTURE_COMMENT: /* capture comment */
+ if (global_commandline_info.capture_comments == NULL) {
+ global_commandline_info.capture_comments = g_ptr_array_new_with_free_func(g_free);
+ }
+ g_ptr_array_add(global_commandline_info.capture_comments, g_strdup(optarg));
+#else
+ capture_option_specified = TRUE;
+ arg_error = TRUE;
+#endif
+ break;
default:
case '?': /* Bad flag - print usage message */
arg_error = TRUE;
diff --git a/ui/commandline.h b/ui/commandline.h
index de1ba65528..72eeefc4d7 100644
--- a/ui/commandline.h
+++ b/ui/commandline.h
@@ -27,6 +27,13 @@ typedef struct commandline_param_info
gboolean list_timestamp_types;
gboolean start_capture;
gboolean quit_after_cap;
+
+ /*
+ * We currently don't support this as a way to add file comments
+ * to an existing capture file in Wireshark; we only support it
+ * for adding comments to live captures.
+ */
+ GPtrArray *capture_comments;
#endif
e_prefs *prefs_p;
search_direction jump_backwards;
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index 975c0e21b5..efb55caad6 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -1034,7 +1034,9 @@ int main(int argc, char *qt_argv[])
if (global_capture_opts.ifaces->len == 0)
collect_ifaces(&global_capture_opts);
CaptureFile::globalCapFile()->window = main_w;
- if (capture_start(&global_capture_opts, main_w->captureSession(), main_w->captureInfoData(), main_window_update)) {
+ if (capture_start(&global_capture_opts, global_commandline_info.capture_comments,
+ main_w->captureSession(), main_w->captureInfoData(),
+ main_window_update)) {
/* The capture started. Open stat windows; we do so after creating
the main window, to avoid GTK warnings, and after successfully
opening the capture file, so we know we have something to compute
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index eed66d9ad9..0c18aece0d 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -868,7 +868,8 @@ void MainWindow::startCapture() {
CaptureFile::globalCapFile()->window = this;
info_data_.ui.ui = this;
- if (capture_start(&global_capture_opts, &cap_session_, &info_data_, main_window_update)) {
+ if (capture_start(&global_capture_opts, NULL, &cap_session_, &info_data_,
+ main_window_update)) {
capture_options *capture_opts = cap_session_.capture_opts;
GString *interface_names;