2 * Routines for dissection options setting
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later*/
21 #include <epan/prefs.h>
22 #include <epan/timestamp.h>
23 #include <epan/addr_resolv.h>
24 #include <epan/disabled_protos.h>
26 #include "ui/decode_as_utils.h"
28 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
29 #include <epan/dissectors/read_keytab_file.h>
32 #include <wsutil/clopts_common.h>
33 #include <wsutil/cmdarg_err.h>
34 #include <wsutil/file_util.h>
36 #include "ui/dissect_opts.h"
38 dissect_options global_dissect_options;
41 dissect_opts_init(void)
43 global_dissect_options.time_format = TS_NOT_SET;
44 global_dissect_options.disable_protocol_slist = NULL;
45 global_dissect_options.enable_protocol_slist = NULL;
46 global_dissect_options.enable_heur_slist = NULL;
47 global_dissect_options.disable_heur_slist = NULL;
51 dissect_opts_handle_opt(int opt, char *optarg_str_p)
56 case 'd': /* Decode as rule */
57 if (!decode_as_command_option(optarg_str_p))
60 case 'K': /* Kerberos keytab file */
61 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
62 read_keytab_file(optarg_str_p);
64 cmdarg_err("-K specified, but Kerberos keytab file support isn't present");
68 case 'n': /* No name resolution */
69 disable_name_resolution();
71 case 'N': /* Select what types of addresses/port #s to resolve */
72 badopt = string_to_name_resolve(optarg_str_p, &gbl_resolv_flags);
74 cmdarg_err("-N specifies unknown resolving option '%c'; valid options are:",
76 cmdarg_err_cont("\t'd' to enable address resolution from captured DNS packets\n"
77 "\t'm' to enable MAC address resolution\n"
78 "\t'n' to enable network address resolution\n"
79 "\t'N' to enable using external resolvers (e.g., DNS)\n"
80 "\t for network address resolution\n"
81 "\t't' to enable transport-layer port number resolution");
85 case 't': /* Time stamp type */
86 if (strcmp(optarg_str_p, "r") == 0)
87 global_dissect_options.time_format = TS_RELATIVE;
88 else if (strcmp(optarg_str_p, "a") == 0)
89 global_dissect_options.time_format = TS_ABSOLUTE;
90 else if (strcmp(optarg_str_p, "ad") == 0)
91 global_dissect_options.time_format = TS_ABSOLUTE_WITH_YMD;
92 else if (strcmp(optarg_str_p, "adoy") == 0)
93 global_dissect_options.time_format = TS_ABSOLUTE_WITH_YDOY;
94 else if (strcmp(optarg_str_p, "d") == 0)
95 global_dissect_options.time_format = TS_DELTA;
96 else if (strcmp(optarg_str_p, "dd") == 0)
97 global_dissect_options.time_format = TS_DELTA_DIS;
98 else if (strcmp(optarg_str_p, "e") == 0)
99 global_dissect_options.time_format = TS_EPOCH;
100 else if (strcmp(optarg_str_p, "u") == 0)
101 global_dissect_options.time_format = TS_UTC;
102 else if (strcmp(optarg_str_p, "ud") == 0)
103 global_dissect_options.time_format = TS_UTC_WITH_YMD;
104 else if (strcmp(optarg_str_p, "udoy") == 0)
105 global_dissect_options.time_format = TS_UTC_WITH_YDOY;
107 cmdarg_err("Invalid time stamp type \"%s\"; it must be one of:", optarg_str_p);
108 cmdarg_err_cont("\t\"a\" for absolute\n"
109 "\t\"ad\" for absolute with YYYY-MM-DD date\n"
110 "\t\"adoy\" for absolute with YYYY/DOY date\n"
111 "\t\"d\" for delta\n"
112 "\t\"dd\" for delta displayed\n"
113 "\t\"e\" for epoch\n"
114 "\t\"r\" for relative\n"
115 "\t\"u\" for absolute UTC\n"
116 "\t\"ud\" for absolute UTC with YYYY-MM-DD date\n"
117 "\t\"udoy\" for absolute UTC with YYYY/DOY date");
121 case 'u': /* Seconds type */
122 if (strcmp(optarg_str_p, "s") == 0)
123 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
124 else if (strcmp(optarg_str_p, "hms") == 0)
125 timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
127 cmdarg_err("Invalid seconds type \"%s\"; it must be one of:", optarg_str_p);
128 cmdarg_err_cont("\t\"s\" for seconds\n"
129 "\t\"hms\" for hours, minutes and seconds");
133 case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */
134 global_dissect_options.disable_protocol_slist = g_slist_append(global_dissect_options.disable_protocol_slist, optarg_str_p);
136 case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
137 global_dissect_options.enable_heur_slist = g_slist_append(global_dissect_options.enable_heur_slist, optarg_str_p);
139 case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
140 global_dissect_options.disable_heur_slist = g_slist_append(global_dissect_options.disable_heur_slist, optarg_str_p);
142 case LONGOPT_ENABLE_PROTOCOL: /* enable dissection of protocol (that is disableed by default) */
143 global_dissect_options.enable_protocol_slist = g_slist_append(global_dissect_options.enable_protocol_slist, optarg_str_p);
146 /* the caller is responsible to send us only the right opt's */
147 g_assert_not_reached();
153 setup_enabled_and_disabled_protocols(void)
155 gboolean success = TRUE;
157 if (global_dissect_options.disable_protocol_slist) {
158 GSList *proto_disable;
160 for (proto_disable = global_dissect_options.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable))
161 proto_disable_proto_by_name((char*)proto_disable->data);
164 if (global_dissect_options.enable_protocol_slist) {
165 GSList *proto_enable;
167 for (proto_enable = global_dissect_options.enable_protocol_slist; proto_enable != NULL; proto_enable = g_slist_next(proto_enable))
168 proto_enable_proto_by_name((char*)proto_enable->data);
171 if (global_dissect_options.enable_heur_slist) {
174 for (heur_enable = global_dissect_options.enable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) {
175 if (!proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE)) {
176 cmdarg_err("No such protocol %s, can't enable", (char*)heur_enable->data);
182 if (global_dissect_options.disable_heur_slist) {
183 GSList *heur_disable;
185 for (heur_disable = global_dissect_options.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) {
186 if (!proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE)) {
187 cmdarg_err("No such protocol %s, can't disable", (char*)heur_disable->data);
196 * Editor modelines - http://www.wireshark.org/tools/modelines.html
201 * indent-tabs-mode: nil
204 * vi: set shiftwidth=4 tabstop=8 expandtab:
205 * :indentSize=4:tabSize=8:noTabs=true: