forked from osmocom/wireshark
Allow/Create an option to use "capture filter" labels defined in wireshark GUI from CLI
Move ui/filters.[ch] to filter_files.[ch] because dumpcap is using functionality. Bug: 8091 Change-Id: I195c82fc023f97d6f331b8718c45a2d83d30faea Reviewed-on: https://code.wireshark.org/review/5925 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
parent
5225100609
commit
ef752689da
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
10
tshark.c
10
tshark.c
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <epan/dfilter/dfilter.h>
|
||||
|
||||
#include <ui/filters.h>
|
||||
#include <filter_files.h>
|
||||
|
||||
#include <wsutil/utf8_entities.h>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <glib.h>
|
||||
|
||||
#include <ui/filters.h>
|
||||
#include <filter_files.h>
|
||||
|
||||
#include <wsutil/filesystem.h>
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue