diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-10-30 14:07:33 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-10-30 22:57:16 +0000 |
commit | 03c6937e62b9b35960b65d573399d64b7a8fd147 (patch) | |
tree | 1be6af646ca3e97004344962a5225cd18e3f11d5 | |
parent | e3b2b2fdc3e6f2c4f1fd659bc6d045f237527036 (diff) |
Have routines for parsing options that affect dissection.
Have them handle -d, -t, --disable-protocol, --disable-heuristic, and
--enable-heuristic for TShark and both flavors of Wireshark.
Change-Id: I612c276b1f9df8a2092202d23ab3d48be7857e85
Reviewed-on: https://code.wireshark.org/review/18583
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | capture_opts.h | 16 | ||||
-rw-r--r-- | tshark.c | 93 | ||||
-rw-r--r-- | ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ui/Makefile.am | 2 | ||||
-rw-r--r-- | ui/commandline.c | 57 | ||||
-rw-r--r-- | ui/commandline.h | 4 | ||||
-rw-r--r-- | ui/dissect_opts.c | 125 | ||||
-rw-r--r-- | ui/dissect_opts.h | 106 | ||||
-rw-r--r-- | ui/gtk/main.c | 13 | ||||
-rw-r--r-- | ui/gtk/main_menubar.c | 9 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 12 | ||||
-rw-r--r-- | wireshark-qt.cpp | 13 |
12 files changed, 297 insertions, 154 deletions
diff --git a/capture_opts.h b/capture_opts.h index 944a5c1d3c..9a85526f45 100644 --- a/capture_opts.h +++ b/capture_opts.h @@ -50,8 +50,8 @@ extern "C" { * component of the entry for the long option, and have a case for that * option in the switch statement. * - * We also pick values <= 65535, so as to leave values > 65535 for - * options specific to a program. + * We also pick values < 4096, so as to leave values >= 4096 for + * other long options. * * NOTE: * for tshark, we're using a leading - in the optstring to prevent getopt() @@ -63,15 +63,6 @@ extern "C" { #define LONGOPT_NUM_CAP_COMMENT 128 /* - * Non-capture long-only options should start here, to avoid collision - * with capture options. - */ -#define MIN_NON_CAPTURE_LONGOPT 129 -#define LONGOPT_DISABLE_PROTOCOL 130 -#define LONGOPT_ENABLE_HEURISTIC 131 -#define LONGOPT_DISABLE_HEURISTIC 132 - -/* * Options for capturing common to all capturing programs. */ #ifdef HAVE_PCAP_REMOTE @@ -109,9 +100,6 @@ extern "C" { {"no-promiscuous-mode", no_argument, NULL, 'p'}, \ {"snapshot-length", required_argument, NULL, 's'}, \ {"linktype", required_argument, NULL, 'y'}, \ - {"disable-protocol", required_argument, NULL, LONGOPT_DISABLE_PROTOCOL }, \ - {"enable-heuristic", required_argument, NULL, LONGOPT_ENABLE_HEURISTIC }, \ - {"disable-heuristic", required_argument, NULL, LONGOPT_DISABLE_HEURISTIC }, \ #define OPTSTRING_CAPTURE_COMMON \ "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:" @@ -86,6 +86,7 @@ #include "ui/decode_as_utils.h" #include "ui/cli/tshark-tap.h" #include "ui/tap_export_pdu.h" +#include "ui/dissect_opts.h" #include "register.h" #include "filter_files.h" #include <epan/epan_dissect.h> @@ -541,6 +542,7 @@ main(int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, LONGOPT_CAPTURE_COMMON + LONGOPT_DISSECT_COMMON {0, 0, 0, 0 } }; gboolean arg_error = FALSE; @@ -589,9 +591,6 @@ main(int argc, char *argv[]) char badopt; int log_flags; gchar *output_only = NULL; - GSList *disable_protocol_slist = NULL; - GSList *enable_heur_slist = NULL; - GSList *disable_heur_slist = NULL; gchar *volatile pdu_export_arg = NULL; exp_pdu_t exp_pdu_tap_data; @@ -614,7 +613,7 @@ main(int argc, char *argv[]) * We do *not* use a leading - because the behavior of a leading - is * platform-dependent. */ -#define OPTSTRING "+2" OPTSTRING_CAPTURE_COMMON "C:d:e:E:F:gG:hH:j:" "K:lnN:o:O:PqQr:R:S:t:T:u:U:vVw:W:xX:Y:z:" +#define OPTSTRING "+2" OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:e:E:F:gG:hH:j:" "K:lnN:o:O:PqQr:R:S:T:u:U:vVw:W:xX:Y:z:" static const char optstring[] = OPTSTRING; @@ -1028,10 +1027,6 @@ main(int argc, char *argv[]) case 'C': /* already processed; just ignore it now */ break; - case 'd': /* Decode as rule */ - if (!decode_as_command_option(optarg)) - return 1; - break; #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS) case 'K': /* Kerberos keytab file */ read_keytab_file(optarg); @@ -1184,42 +1179,6 @@ main(int argc, char *argv[]) case 'S': /* Set the line Separator to be printed between packets */ separator = optarg; break; - case 't': /* Time stamp type */ - if (strcmp(optarg, "r") == 0) - timestamp_set_type(TS_RELATIVE); - else if (strcmp(optarg, "a") == 0) - timestamp_set_type(TS_ABSOLUTE); - else if (strcmp(optarg, "ad") == 0) - timestamp_set_type(TS_ABSOLUTE_WITH_YMD); - else if (strcmp(optarg, "adoy") == 0) - timestamp_set_type(TS_ABSOLUTE_WITH_YDOY); - else if (strcmp(optarg, "d") == 0) - timestamp_set_type(TS_DELTA); - else if (strcmp(optarg, "dd") == 0) - timestamp_set_type(TS_DELTA_DIS); - else if (strcmp(optarg, "e") == 0) - timestamp_set_type(TS_EPOCH); - else if (strcmp(optarg, "u") == 0) - timestamp_set_type(TS_UTC); - else if (strcmp(optarg, "ud") == 0) - timestamp_set_type(TS_UTC_WITH_YMD); - else if (strcmp(optarg, "udoy") == 0) - timestamp_set_type(TS_UTC_WITH_YDOY); - else { - cmdarg_err("Invalid time stamp type \"%s\"; it must be one of:", optarg); - cmdarg_err_cont("\t\"a\" for absolute\n" - "\t\"ad\" for absolute with YYYY-MM-DD date\n" - "\t\"adoy\" for absolute with YYYY/DOY date\n" - "\t\"d\" for delta\n" - "\t\"dd\" for delta displayed\n" - "\t\"e\" for epoch\n" - "\t\"r\" for relative\n" - "\t\"u\" for absolute UTC\n" - "\t\"ud\" for absolute UTC with YYYY-MM-DD date\n" - "\t\"udoy\" for absolute UTC with YYYY/DOY date"); - return 1; - } - break; case 'T': /* printing Type */ print_packet_info = TRUE; if (strcmp(optarg, "text") == 0) { @@ -1351,14 +1310,12 @@ main(int argc, char *argv[]) return 1; } break; + case 'd': /* Decode as rule */ + case 't': /* Time stamp type */ case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */ - disable_protocol_slist = g_slist_append(disable_protocol_slist, optarg); - break; case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */ - enable_heur_slist = g_slist_append(enable_heur_slist, optarg); - break; case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */ - disable_heur_slist = g_slist_append(disable_heur_slist, optarg); + dissect_opts_add_opt(opt, optarg); break; default: @@ -1693,34 +1650,36 @@ main(int argc, char *argv[]) } } + timestamp_set_type(global_dissect_options.time_format); + /* disabled protocols as per configuration file */ if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); set_disabled_heur_dissector_list(); } - if(disable_protocol_slist) { - GSList *proto_disable; - for (proto_disable = disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) - { - proto_disable_proto_by_name((char*)proto_disable->data); - } + if(global_dissect_options.disable_protocol_slist) { + GSList *proto_disable; + for (proto_disable = global_dissect_options.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) + { + proto_disable_proto_by_name((char*)proto_disable->data); + } } - if(enable_heur_slist) { - GSList *heur_enable; - for (heur_enable = enable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) - { - proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE); - } + if(global_dissect_options.disable_heur_slist) { + GSList *heur_enable; + for (heur_enable = global_dissect_options.disable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) + { + proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE); + } } - if(disable_heur_slist) { - GSList *heur_disable; - for (heur_disable = disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) - { - proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE); - } + if(global_dissect_options.disable_heur_slist) { + GSList *heur_disable; + for (heur_disable = global_dissect_options.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) + { + proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE); + } } /* Build the column format array */ diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 334e5f3257..13a3df18c9 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -27,6 +27,7 @@ set(COMMON_UI_SRC commandline.c console.c decode_as_utils.c + dissect_opts.c export_object.c export_object_dicom.c export_object_http.c diff --git a/ui/Makefile.am b/ui/Makefile.am index 91f189bd05..5a252e32cd 100644 --- a/ui/Makefile.am +++ b/ui/Makefile.am @@ -54,6 +54,7 @@ WIRESHARK_UI_SRC = \ commandline.c \ console.c \ decode_as_utils.c \ + dissect_opts.c \ export_object.c \ export_object_dicom.c \ export_object_http.c \ @@ -99,6 +100,7 @@ WIRESHARK_UI_INCLUDES = \ commandline.h \ console.h \ decode_as_utils.h \ + dissect_opts.h \ export_object.h \ export_pdu_ui_utils.h \ last_open_dir.h \ diff --git a/ui/commandline.c b/ui/commandline.c index d67a5ca16f..39f0da54e2 100644 --- a/ui/commandline.c +++ b/ui/commandline.c @@ -48,7 +48,6 @@ #include <epan/proto.h> #include <epan/prefs.h> #include <epan/prefs-int.h> -#include <epan/timestamp.h> #include <epan/stat_tap_ui.h> #include "capture_opts.h" @@ -65,6 +64,8 @@ #include "../file.h" +#include "ui/dissect_opts.h" + #include "ui/commandline.h" commandline_param_info_t global_commandline_info; @@ -189,12 +190,12 @@ commandline_print_usage(gboolean for_help_option) { * component of the entry for the long option, and have a case for that * option in the switch statement. * - * We also pick values > 65535, so as to leave values from 128 to 65535 - * for capture options. + * We also pick values >= 65536, so as to leave values from 128 to 65535 + * for capture and dissection options. */ #define LONGOPT_FULL_SCREEN 65536 -#define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:d:g:Hh" "jJ:kK:lm:nN:o:P:r:R:St:u:vw:X:Y:z:" +#define OPTSTRING OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:g:Hh" "jJ:kK:lm:nN:o:P:r:R:Su:vw:X:Y:z:" static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"read-file", required_argument, NULL, 'r' }, @@ -203,6 +204,7 @@ static const struct option long_options[] = { {"version", no_argument, NULL, 'v'}, {"fullscreen", no_argument, NULL, LONGOPT_FULL_SCREEN }, LONGOPT_CAPTURE_COMMON + LONGOPT_DISSECT_COMMON {0, 0, 0, 0 } }; static const char optstring[] = OPTSTRING; @@ -400,15 +402,11 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset) global_commandline_info.cf_name = NULL; global_commandline_info.rfilter = NULL; global_commandline_info.dfilter = NULL; - global_commandline_info.time_format = TS_NOT_SET; #ifdef HAVE_LIBPCAP global_commandline_info.start_capture = FALSE; global_commandline_info.list_link_layer_types = FALSE; global_commandline_info.quit_after_cap = getenv("WIRESHARK_QUIT_AFTER_CAPTURE") ? TRUE : FALSE; #endif - global_commandline_info.disable_protocol_slist = NULL; - global_commandline_info.enable_heur_slist = NULL; - global_commandline_info.disable_heur_slist = NULL; global_commandline_info.full_screen = FALSE; while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { @@ -457,10 +455,6 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset) case 'C': /* Configuration profile settings were already processed just ignore them this time*/ break; - case 'd': /* Decode as rule */ - if (!decode_as_command_option(optarg)) - exit(1); - break; case 'j': /* Search backwards for a matching packet from filter in option J */ global_commandline_info.jump_backwards = SD_BACKWARD; break; @@ -546,37 +540,6 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset) case 'R': /* Read file filter */ global_commandline_info.rfilter = optarg; break; - case 't': /* Time stamp type */ - if (strcmp(optarg, "r") == 0) - global_commandline_info.time_format = TS_RELATIVE; - else if (strcmp(optarg, "a") == 0) - global_commandline_info.time_format = TS_ABSOLUTE; - else if (strcmp(optarg, "ad") == 0) - global_commandline_info.time_format = TS_ABSOLUTE_WITH_YMD; - else if (strcmp(optarg, "adoy") == 0) - global_commandline_info.time_format = TS_ABSOLUTE_WITH_YDOY; - else if (strcmp(optarg, "d") == 0) - global_commandline_info.time_format = TS_DELTA; - else if (strcmp(optarg, "dd") == 0) - global_commandline_info.time_format = TS_DELTA_DIS; - else if (strcmp(optarg, "e") == 0) - global_commandline_info.time_format = TS_EPOCH; - else if (strcmp(optarg, "u") == 0) - global_commandline_info.time_format = TS_UTC; - else if (strcmp(optarg, "ud") == 0) - global_commandline_info.time_format = TS_UTC_WITH_YMD; - else if (strcmp(optarg, "udoy") == 0) - global_commandline_info.time_format = TS_UTC_WITH_YDOY; - else { - cmdarg_err("Invalid time stamp type \"%s\"", optarg); - cmdarg_err_cont("It must be \"a\" for absolute, \"ad\" for absolute with YYYY-MM-DD date,"); - cmdarg_err_cont("\"adoy\" for absolute with YYYY/DOY date, \"d\" for delta,"); - cmdarg_err_cont("\"dd\" for delta displayed, \"e\" for epoch, \"r\" for relative,"); - cmdarg_err_cont("\"u\" for absolute UTC, \"ud\" for absolute UTC with YYYY-MM-DD date,"); - cmdarg_err_cont("or \"udoy\" for absolute UTC with YYYY/DOY date."); - exit(1); - } - break; case 'u': /* Seconds type */ if (strcmp(optarg, "s") == 0) timestamp_set_seconds_type(TS_SECONDS_DEFAULT); @@ -612,14 +575,12 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset) exit(1); } break; + case 'd': /* Decode as rule */ + case 't': /* time stamp type */ case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */ - global_commandline_info.disable_protocol_slist = g_slist_append(global_commandline_info.disable_protocol_slist, optarg); - break; case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */ - global_commandline_info.enable_heur_slist = g_slist_append(global_commandline_info.enable_heur_slist, optarg); - break; case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */ - global_commandline_info.disable_heur_slist = g_slist_append(global_commandline_info.disable_heur_slist, optarg); + dissect_opts_add_opt(opt, optarg); break; case LONGOPT_FULL_SCREEN: global_commandline_info.full_screen = TRUE; diff --git a/ui/commandline.h b/ui/commandline.h index a72280446d..85ba97c0c5 100644 --- a/ui/commandline.h +++ b/ui/commandline.h @@ -47,10 +47,6 @@ typedef struct commandline_param_info gchar* cf_name; gchar* rfilter; gchar* dfilter; - ts_type time_format; - GSList *disable_protocol_slist; - GSList *enable_heur_slist; - GSList *disable_heur_slist; gboolean full_screen; } commandline_param_info_t; diff --git a/ui/dissect_opts.c b/ui/dissect_opts.c new file mode 100644 index 0000000000..aa9691f58f --- /dev/null +++ b/ui/dissect_opts.c @@ -0,0 +1,125 @@ +/* dissect_opts.c + * Routines for dissection options setting + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> + +#include <string.h> + +#include <errno.h> + +#include <glib.h> + +#include <epan/timestamp.h> + +#include "ui/decode_as_utils.h" + +#include <wsutil/clopts_common.h> +#include <wsutil/cmdarg_err.h> +#include <wsutil/file_util.h> + +#include "ui/dissect_opts.h" + +dissect_options global_dissect_options; + +void +dissect_opts_init(void) +{ + global_dissect_options.time_format = TS_NOT_SET; + global_dissect_options.disable_protocol_slist = NULL; + global_dissect_options.enable_heur_slist = NULL; + global_dissect_options.disable_heur_slist = NULL; +} + +void +dissect_opts_add_opt(int opt, char *optarg_str_p) +{ + switch(opt) { + case 'd': /* Decode as rule */ + if (!decode_as_command_option(optarg_str_p)) + exit(1); + break; + case 't': /* Time stamp type */ + if (strcmp(optarg_str_p, "r") == 0) + global_dissect_options.time_format = TS_RELATIVE; + else if (strcmp(optarg_str_p, "a") == 0) + global_dissect_options.time_format = TS_ABSOLUTE; + else if (strcmp(optarg_str_p, "ad") == 0) + global_dissect_options.time_format = TS_ABSOLUTE_WITH_YMD; + else if (strcmp(optarg_str_p, "adoy") == 0) + global_dissect_options.time_format = TS_ABSOLUTE_WITH_YDOY; + else if (strcmp(optarg_str_p, "d") == 0) + global_dissect_options.time_format = TS_DELTA; + else if (strcmp(optarg_str_p, "dd") == 0) + global_dissect_options.time_format = TS_DELTA_DIS; + else if (strcmp(optarg_str_p, "e") == 0) + global_dissect_options.time_format = TS_EPOCH; + else if (strcmp(optarg_str_p, "u") == 0) + global_dissect_options.time_format = TS_UTC; + else if (strcmp(optarg_str_p, "ud") == 0) + global_dissect_options.time_format = TS_UTC_WITH_YMD; + else if (strcmp(optarg_str_p, "udoy") == 0) + global_dissect_options.time_format = TS_UTC_WITH_YDOY; + else { + cmdarg_err("Invalid time stamp type \"%s\"; it must be one of:", optarg_str_p); + cmdarg_err_cont("\t\"a\" for absolute\n" + "\t\"ad\" for absolute with YYYY-MM-DD date\n" + "\t\"adoy\" for absolute with YYYY/DOY date\n" + "\t\"d\" for delta\n" + "\t\"dd\" for delta displayed\n" + "\t\"e\" for epoch\n" + "\t\"r\" for relative\n" + "\t\"u\" for absolute UTC\n" + "\t\"ud\" for absolute UTC with YYYY-MM-DD date\n" + "\t\"udoy\" for absolute UTC with YYYY/DOY date"); + exit(1); + } + break; + case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */ + global_dissect_options.disable_protocol_slist = g_slist_append(global_dissect_options.disable_protocol_slist, optarg_str_p); + break; + case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */ + global_dissect_options.enable_heur_slist = g_slist_append(global_dissect_options.enable_heur_slist, optarg_str_p); + break; + case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */ + global_dissect_options.disable_heur_slist = g_slist_append(global_dissect_options.disable_heur_slist, optarg_str_p); + break; + default: + /* the caller is responsible to send us only the right opt's */ + g_assert_not_reached(); + } +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/dissect_opts.h b/ui/dissect_opts.h new file mode 100644 index 0000000000..ad049b8160 --- /dev/null +++ b/ui/dissect_opts.h @@ -0,0 +1,106 @@ +/* dissect_opts.h + * Dissection options (parameters that affect dissection) + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +/** @file + * + * Dissection options (parameters that affect dissection) + * + */ + +#ifndef __DISSECT_OPTS_H__ +#define __DISSECT_OPTS_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Long options. + * We do not currently have long options corresponding to all short + * options; we should probably pick appropriate option names for them. + * + * For long options with no corresponding short options, we define values + * outside the range of ASCII graphic characters, make that the last + * component of the entry for the long option, and have a case for that + * option in the switch statement. + * + * We also pick values >= 4096, so as not to collide with capture options, + * and <= 65535, so as to leave values > 65535 for options specific to a + * program. + */ + +/* + * Non-capture long-only options should start here, to avoid collision + * with capture options. + */ +#define LONGOPT_DISABLE_PROTOCOL 4096 +#define LONGOPT_ENABLE_HEURISTIC 4097 +#define LONGOPT_DISABLE_HEURISTIC 4098 + +/* + * Options for dissecting common to all dissecting programs. + */ +#define LONGOPT_DISSECT_COMMON \ + {"disable-protocol", required_argument, NULL, LONGOPT_DISABLE_PROTOCOL }, \ + {"enable-heuristic", required_argument, NULL, LONGOPT_ENABLE_HEURISTIC }, \ + {"disable-heuristic", required_argument, NULL, LONGOPT_DISABLE_HEURISTIC }, \ + +#define OPTSTRING_DISSECT_COMMON \ + "d:t:" + +/** Capture options coming from user interface */ +typedef struct dissect_options_tag { + ts_type time_format; + GSList *disable_protocol_slist; + GSList *enable_heur_slist; + GSList *disable_heur_slist; +} dissect_options; + +extern dissect_options global_dissect_options; + +/* initialize the dissect_options with some reasonable values */ +extern void +dissect_opts_init(void); + +/* set a command line option value */ +extern void +dissect_opts_add_opt(int opt, char *optarg_str_p); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* dissect_opts.h */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 94b1b623e8..f42f98dbb8 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -110,6 +110,7 @@ #include "ui/software_update.h" #include "ui/ui_util.h" #include "ui/util.h" +#include "ui/dissect_opts.h" #include "ui/commandline.h" #ifdef HAVE_LIBPCAP @@ -2462,25 +2463,25 @@ main(int argc, char *argv[]) set_disabled_heur_dissector_list(); } - if(global_commandline_info.disable_protocol_slist) { + if(global_dissect_options.disable_protocol_slist) { GSList *proto_disable; - for (proto_disable = global_commandline_info.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) + for (proto_disable = global_dissect_options.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) { proto_disable_proto_by_name((char*)proto_disable->data); } } - if(global_commandline_info.enable_heur_slist) { + if(global_dissect_options.disable_heur_slist) { GSList *heur_enable; - for (heur_enable = global_commandline_info.enable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) + for (heur_enable = global_dissect_options.disable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) { proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE); } } - if(global_commandline_info.disable_heur_slist) { + if(global_dissect_options.disable_heur_slist) { GSList *heur_disable; - for (heur_disable = global_commandline_info.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) + for (heur_disable = global_dissect_options.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) { proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE); } diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c index 3b6035e519..0b8aeacc60 100644 --- a/ui/gtk/main_menubar.c +++ b/ui/gtk/main_menubar.c @@ -39,6 +39,7 @@ #include <epan/color_filters.h> #include "ui/commandline.h" +#include "ui/dissect_opts.h" #include "ui/main_statusbar.h" #include "ui/preference_utils.h" #include "ui/recent.h" @@ -3174,8 +3175,8 @@ menus_init(void) G_N_ELEMENTS(main_menu_bar_toggle_action_entries), /* the number of entries */ NULL); /* data to pass to the action callbacks */ - if (global_commandline_info.time_format != TS_NOT_SET) { - recent.gui_time_format = global_commandline_info.time_format; + if (global_dissect_options.time_format != TS_NOT_SET) { + recent.gui_time_format = global_dissect_options.time_format; } gtk_action_group_add_radio_actions (main_menu_bar_action_group, /* the action group */ main_menu_bar_radio_view_time_entries, /* an array of radio action descriptions */ @@ -4253,8 +4254,8 @@ menu_recent_read_finished(void) main_widgets_rearrange(); /* Update the time format if we had a command line value. */ - if (global_commandline_info.time_format != TS_NOT_SET) { - recent.gui_time_format = global_commandline_info.time_format; + if (global_dissect_options.time_format != TS_NOT_SET) { + recent.gui_time_format = global_dissect_options.time_format; } /* XXX Fix me */ diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 388ab77ab4..7597ab9503 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -34,12 +34,14 @@ #include <windows.h> #endif -#include "ui/commandline.h" +#include "ui/dissect_opts.h" #ifdef HAVE_LIBPCAP #include "ui/capture.h" #endif +#include "ui/commandline.h" + #include "epan/color_filters.h" #include "wsutil/file_util.h" @@ -1384,12 +1386,12 @@ void MainWindow::startInterfaceCapture(bool valid, const QString capture_filter) void MainWindow::applyGlobalCommandLineOptions() { - if (global_commandline_info.time_format != TS_NOT_SET) { + if (global_dissect_options.time_format != TS_NOT_SET) { foreach (QAction* tda, td_actions.keys()) { - if (global_commandline_info.time_format == td_actions[tda]) { + if (global_dissect_options.time_format == td_actions[tda]) { tda->setChecked(true); - recent.gui_time_format = global_commandline_info.time_format; - timestamp_set_type(global_commandline_info.time_format); + recent.gui_time_format = global_dissect_options.time_format; + timestamp_set_type(global_dissect_options.time_format); break; } } diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index e86b83a1aa..d2c045acde 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -87,6 +87,7 @@ #include "ui/recent.h" #include "ui/simple_dialog.h" #include "ui/util.h" +#include "ui/dissect_opts.h" #include "ui/commandline.h" #include "ui/capture_ui_utils.h" @@ -715,25 +716,25 @@ int main(int argc, char *qt_argv[]) set_disabled_heur_dissector_list(); } - if(global_commandline_info.disable_protocol_slist) { + if(global_dissect_options.disable_protocol_slist) { GSList *proto_disable; - for (proto_disable = global_commandline_info.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) + for (proto_disable = global_dissect_options.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) { proto_disable_proto_by_name((char*)proto_disable->data); } } - if(global_commandline_info.enable_heur_slist) { + if(global_dissect_options.enable_heur_slist) { GSList *heur_enable; - for (heur_enable = global_commandline_info.enable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) + for (heur_enable = global_dissect_options.enable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) { proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE); } } - if(global_commandline_info.disable_heur_slist) { + if(global_dissect_options.disable_heur_slist) { GSList *heur_disable; - for (heur_disable = global_commandline_info.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) + for (heur_disable = global_dissect_options.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) { proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE); } |