diff options
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | Makefile.common | 4 | ||||
-rw-r--r-- | capture_opts.c | 69 | ||||
-rw-r--r-- | doc/dumpcap.pod | 4 | ||||
-rw-r--r-- | doc/tshark.pod | 4 | ||||
-rw-r--r-- | doc/wireshark.pod.template | 4 | ||||
-rw-r--r-- | docbook/wsug_src/WSUG_chapter_customize.asciidoc | 3 | ||||
-rw-r--r-- | filter_files.c (renamed from ui/filters.c) | 2 | ||||
-rw-r--r-- | filter_files.h (renamed from ui/filters.h) | 0 | ||||
-rw-r--r-- | tshark.c | 10 | ||||
-rw-r--r-- | ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ui/Makefile.common | 2 | ||||
-rw-r--r-- | ui/gtk/filter_dlg.c | 2 | ||||
-rw-r--r-- | ui/gtk/main.c | 2 | ||||
-rw-r--r-- | ui/qt/Wireshark.pro | 1 | ||||
-rw-r--r-- | ui/qt/capture_filter_edit.cpp | 2 | ||||
-rw-r--r-- | ui/qt/display_filter_edit.cpp | 2 | ||||
-rw-r--r-- | ui/qt/filter_dialog.cpp | 2 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 2 |
19 files changed, 96 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 50d645d183..90fde1e1a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1709,6 +1709,7 @@ if( (BUILD_wireshark AND QT_FOUND) OR (BUILD_wireshark_gtk AND GTK_FOUND) ) capture_opts.c file.c fileset.c + filter_files.c summary.c ${SHARK_COMMON_SRC} ${PLATFORM_UI_SRC} @@ -2066,6 +2067,7 @@ if(BUILD_tshark) ) set(tshark_FILES capture_opts.c + filter_files.c tshark-tap-register.c tshark.c ${TSHARK_TAP_SRC} @@ -2278,6 +2280,7 @@ if(BUILD_dumpcap AND PCAP_FOUND) capture_stop_conditions.c conditions.c dumpcap.c + filter_files.c pcapio.c ringbuffer.c sync_pipe_write.c diff --git a/Makefile.common b/Makefile.common index 9f3c202a94..0f9e7e721b 100644 --- a/Makefile.common +++ b/Makefile.common @@ -65,12 +65,14 @@ WIRESHARK_COMMON_SRC = \ capture_opts.c \ file.c \ fileset.c \ + filter_files.c \ summary.c # corresponding headers WIRESHARK_COMMON_INCLUDES = \ capture_info.h \ capture_opts.h \ + filter_files.h \ globals.h \ log.h \ summary.h \ @@ -80,6 +82,7 @@ WIRESHARK_COMMON_INCLUDES = \ tshark_SOURCES = \ $(SHARK_COMMON_SRC) \ capture_opts.c \ + filter_files.c \ tshark.c # tfshark specifics @@ -165,6 +168,7 @@ dumpcap_SOURCES = \ capture_stop_conditions.c \ conditions.c \ dumpcap.c \ + filter_files.c \ pcapio.c \ ringbuffer.c \ sync_pipe_write.c diff --git a/capture_opts.c b/capture_opts.c index c2c25d1009..38c39b304b 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -43,6 +43,8 @@ #include "caputils/capture_ifinfo.h" #include "caputils/capture-pcap-util.h" +#include "filter_files.h" + static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe); @@ -281,6 +283,60 @@ set_autostop_criterion(capture_options *capture_opts, const char *autostoparg) return TRUE; } +static gboolean get_filter_arguments(capture_options* capture_opts, const char* arg) +{ + char* colonp; + char* val; + char* filter_exp = NULL; + + colonp = strchr(arg, ':'); + if (colonp) { + val = colonp; + *val = '\0'; + val++; + if (strcmp(arg, "predef") == 0) { + GList* filterItem; + + filterItem = get_filter_list_first(CFILTER_LIST); + while (filterItem != NULL) { + filter_def *filterDef; + + filterDef = (filter_def*)filterItem->data; + if (strcmp(val, filterDef->name) == 0) { + filter_exp = g_strdup(filterDef->strval); + break; + } + filterItem = filterItem->next; + } + } + } + + if (filter_exp == NULL) { + /* No filter expression found yet; fallback to previous implemention + and assume the arg contains a filter expression */ + if (colonp) { + *colonp = ':'; /* restore colon */ + } + filter_exp = g_strdup(arg); + } + + if (capture_opts->ifaces->len > 0) { + interface_options interface_opts; + + interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1); + capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1); + g_free(interface_opts.cfilter); + interface_opts.cfilter = filter_exp; + g_array_append_val(capture_opts->ifaces, interface_opts); + return TRUE; + } + else { + g_free(capture_opts->default_options.cfilter); + capture_opts->default_options.cfilter = filter_exp; + return TRUE; + } +} + /* * Given a string of the form "<ring buffer file>:<duration>", as might appear * as an argument to a "-b" option, parse it and set the arguments in @@ -711,18 +767,7 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_ capture_opts->autostop_packets = get_positive_int(optarg_str_p, "packet count"); break; case 'f': /* capture filter */ - if (capture_opts->ifaces->len > 0) { - interface_options interface_opts; - - interface_opts = g_array_index(capture_opts->ifaces, interface_options, capture_opts->ifaces->len - 1); - capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, capture_opts->ifaces->len - 1); - g_free(interface_opts.cfilter); - interface_opts.cfilter = g_strdup(optarg_str_p); - g_array_append_val(capture_opts->ifaces, interface_opts); - } else { - g_free(capture_opts->default_options.cfilter); - capture_opts->default_options.cfilter = g_strdup(optarg_str_p); - } + get_filter_arguments(capture_opts, optarg_str_p); break; case 'g': /* enable group read access on the capture file(s) */ capture_opts->group_read_access = TRUE; diff --git a/doc/dumpcap.pod b/doc/dumpcap.pod index 8ed270f901..b643970fba 100644 --- a/doc/dumpcap.pod +++ b/doc/dumpcap.pod @@ -185,6 +185,10 @@ the interface specified by the last B<-i> option occurring before this option. If the capture filter expression is not set specifically, the default capture filter expression is used if provided. +Pre-defined capture filter names, as shown in the GUI menu item Capture->Capture Filters, +can be used by prefixing the argument with "predef:". +Example: B<-f "predef:MyPredefinedHostOnlyFilter"> + =item -g This option causes the output file(s) to be created with group-read permission diff --git a/doc/tshark.pod b/doc/tshark.pod index 092df16f98..0ba3743461 100644 --- a/doc/tshark.pod +++ b/doc/tshark.pod @@ -342,6 +342,10 @@ the interface specified by the last B<-i> option occurring before this option. If the capture filter expression is not set specifically, the default capture filter expression is used if provided. +Pre-defined capture filter names, as shown in the GUI menu item Capture->Capture Filters, +can be used by prefixing the argument with "predef:". +Example: B<-f "predef:MyPredefinedHostOnlyFilter"> + =item -F E<lt>file formatE<gt> Set the file format of the output capture file written using the B<-w> diff --git a/doc/wireshark.pod.template b/doc/wireshark.pod.template index dd868f87ce..aebb2daf95 100644 --- a/doc/wireshark.pod.template +++ b/doc/wireshark.pod.template @@ -347,6 +347,10 @@ the interface specified by the last B<-i> option occurring before this option. If the capture filter expression is not set specifically, the default capture filter expression is used if provided. +Pre-defined capture filter names, as shown in the GUI menu item Capture->Capture Filters, +can be used by prefixing the argument with "predef:". +Example: B<-f "predef:MyPredefinedHostOnlyFilter"> + =item -g E<lt>packet numberE<gt> After reading in a capture file using the B<-r> flag, go to the given I<packet number>. diff --git a/docbook/wsug_src/WSUG_chapter_customize.asciidoc b/docbook/wsug_src/WSUG_chapter_customize.asciidoc index ae920cdf71..2abcfaab8b 100644 --- a/docbook/wsug_src/WSUG_chapter_customize.asciidoc +++ b/docbook/wsug_src/WSUG_chapter_customize.asciidoc @@ -46,7 +46,8 @@ Usage: wireshark [options] ... [ <infile> ] Capture interface: -i <interface> name or idx of interface (def: first non-loopback) - -f <capture filter> packet filter in libpcap filter syntax + -f <capfilter|predef:> packet filter in libpcap filter syntax or + predef:filtername - predefined filtername from GUI -s <snaplen> packet snapshot length (def: 65535) -p don't capture in promiscuous mode -k start capturing immediately (def: do nothing) diff --git a/ui/filters.c b/filter_files.c index 01014798f4..99a71f54ec 100644 --- a/ui/filters.c +++ b/filter_files.c @@ -31,7 +31,7 @@ #include <wsutil/file_util.h> #include <wsutil/filesystem.h> -#include "ui/filters.h" +#include "filter_files.h" /* * Old filter file name. diff --git a/ui/filters.h b/filter_files.h index b63ddca2ba..b63ddca2ba 100644 --- a/ui/filters.h +++ b/filter_files.h @@ -87,6 +87,7 @@ #include "ui/ui_util.h" #include "ui/cli/tshark-tap.h" #include "register.h" +#include "filter_files.h" #include <epan/epan_dissect.h> #include <epan/tap.h> #include <epan/stat_tap_ui.h> @@ -971,10 +972,12 @@ main(int argc, char *argv[]) char *gpf_path, *pf_path; char *gdp_path, *dp_path; + char *cf_path; int gpf_open_errno, gpf_read_errno; int pf_open_errno, pf_read_errno; int gdp_open_errno, gdp_read_errno; int dp_open_errno, dp_read_errno; + int cf_open_errno; int err; volatile int exit_status = 0; #ifdef HAVE_LIBPCAP @@ -1321,6 +1324,13 @@ main(int argc, char *argv[]) pf_path = NULL; } + read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno); + if (cf_path != NULL) { + cmdarg_err("Could not open your capture filter file\n\"%s\": %s.", + cf_path, g_strerror(cf_open_errno)); + g_free(cf_path); + } + /* Read the disabled protocols file. */ read_disabled_protos_list(&gdp_path, &gdp_open_errno, &gdp_read_errno, &dp_path, &dp_open_errno, &dp_read_errno); diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index d68079062e..cb6d27df79 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -31,7 +31,6 @@ set(COMMON_UI_SRC export_object_http.c export_object_smb.c export_object_tftp.c - filters.c help_url.c iface_lists.c io_graph_item.c diff --git a/ui/Makefile.common b/ui/Makefile.common index 94d33c3029..87d9040d94 100644 --- a/ui/Makefile.common +++ b/ui/Makefile.common @@ -52,7 +52,6 @@ WIRESHARK_UI_SRC = \ export_object_http.c \ export_object_smb.c \ export_object_tftp.c \ - filters.c \ iface_lists.c \ io_graph_item.c \ language.c \ @@ -92,7 +91,6 @@ noinst_HEADERS = \ export_object.h \ last_open_dir.h \ file_dialog.h \ - filters.h \ help_url.h \ packet_list_utils.h \ iface_lists.h \ diff --git a/ui/gtk/filter_dlg.c b/ui/gtk/filter_dlg.c index 36f27b240f..0a360742d1 100644 --- a/ui/gtk/filter_dlg.c +++ b/ui/gtk/filter_dlg.c @@ -30,7 +30,7 @@ #include <epan/prefs.h> #include <epan/column-info.h> -#include "ui/filters.h" +#include "filter_files.h" #include "ui/simple_dialog.h" #include "ui/main_statusbar.h" diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 6e92da071c..7acbd6c2a2 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -107,7 +107,7 @@ #include "ui/alert_box.h" #include "ui/console.h" #include "ui/decode_as_utils.h" -#include "ui/filters.h" +#include "filter_files.h" #include "ui/main_statusbar.h" #include "ui/persfilepath_opt.h" #include "ui/preference_utils.h" diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro index 1fb0f6986a..940c0a48de 100644 --- a/ui/qt/Wireshark.pro +++ b/ui/qt/Wireshark.pro @@ -195,6 +195,7 @@ SOURCES_WS_C = \ ../../extcap_parser.c \ ../../file.c \ ../../fileset.c \ + ../../filter_files.c \ ../../frame_tvbuff.c \ ../../summary.c \ ../../sync_pipe_write.c diff --git a/ui/qt/capture_filter_edit.cpp b/ui/qt/capture_filter_edit.cpp index c122c548f7..ccd17d31b9 100644 --- a/ui/qt/capture_filter_edit.cpp +++ b/ui/qt/capture_filter_edit.cpp @@ -28,7 +28,7 @@ #include "capture_opts.h" #include <ui/capture_globals.h> -#include <ui/filters.h> +#include <filter_files.h> #include <wsutil/utf8_entities.h> #include "capture_filter_edit.h" diff --git a/ui/qt/display_filter_edit.cpp b/ui/qt/display_filter_edit.cpp index d91c8565c6..3d7df3eeb1 100644 --- a/ui/qt/display_filter_edit.cpp +++ b/ui/qt/display_filter_edit.cpp @@ -25,7 +25,7 @@ #include <epan/dfilter/dfilter.h> -#include <ui/filters.h> +#include <filter_files.h> #include <wsutil/utf8_entities.h> diff --git a/ui/qt/filter_dialog.cpp b/ui/qt/filter_dialog.cpp index c19fce8823..30da83d569 100644 --- a/ui/qt/filter_dialog.cpp +++ b/ui/qt/filter_dialog.cpp @@ -25,7 +25,7 @@ #include <glib.h> -#include <ui/filters.h> +#include <filter_files.h> #include <wsutil/filesystem.h> diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 4e1d937812..d02edd225d 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -60,7 +60,7 @@ #endif #include "ui/capture.h" -#include "ui/filters.h" +#include "filter_files.h" #include "ui/capture_globals.h" #include "ui/software_update.h" #include "ui/last_open_dir.h" |