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
20 #include <epan/prefs.h>
21 #include <epan/timestamp.h>
22 #include <epan/addr_resolv.h>
23 #include <epan/disabled_protos.h>
25 #include "ui/decode_as_utils.h"
27 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
28 #include <epan/dissectors/read_keytab_file.h>
31 #include <wsutil/clopts_common.h>
32 #include <wsutil/strtoi.h>
33 #include <wsutil/cmdarg_err.h>
34 #include <wsutil/file_util.h>
35 #include <wsutil/ws_assert.h>
37 #include "ui/dissect_opts.h"
39 dissect_options global_dissect_options
= {
40 .time_format
= TS_NOT_SET
,
41 .time_precision
= TS_PREC_NOT_SET
45 dissect_opts_handle_opt(int opt
, char *optarg_str_p
)
52 case 'd': /* Decode as rule */
53 if (!decode_as_command_option(optarg_str_p
))
56 case 'K': /* Kerberos keytab file */
57 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
58 read_keytab_file(optarg_str_p
);
60 cmdarg_err("-K specified, but Kerberos keytab file support isn't present");
64 case 'n': /* No name resolution */
65 disable_name_resolution();
67 case 'N': /* Select what types of addresses/port #s to resolve */
68 badopt
= string_to_name_resolve(optarg_str_p
, &gbl_resolv_flags
);
70 cmdarg_err("-N specifies unknown resolving option '%c'; valid options are:",
72 cmdarg_err_cont("\t'd' to enable address resolution from captured DNS packets\n"
73 "\t'g' to enable address geolocation information from MaxMind databases\n"
74 "\t'm' to enable MAC address resolution\n"
75 "\t'n' to enable network address resolution\n"
76 "\t'N' to enable using external resolvers (e.g., DNS)\n"
77 "\t for network address resolution\n"
78 "\t's' to enable address resolution using SNI information found in captured\n"
79 "\t handshake packets\n"
80 "\t't' to enable transport-layer port number resolution\n"
81 "\t'v' to enable VLAN IDs to names resolution");
85 case 't': /* Time stamp type */
86 tsp
= TS_PREC_NOT_SET
;
87 dotp
= strchr(optarg_str_p
, '.');
89 if (strcmp(dotp
+ 1, "") == 0) {
90 /* Nothing specified; use appropriate precision for the file. */
94 * Precision must be a number giving the number of
95 * digits of precision.
99 if (!ws_strtou32(dotp
+ 1, NULL
, &val
) || val
> WS_TSPREC_MAX
) {
100 cmdarg_err("Invalid .N time stamp precision \"%s\"; N must be a value between 0 and %u or absent",
101 dotp
+ 1, WS_TSPREC_MAX
);
106 /* Mask the '.' while checking format. */
109 if (strcmp(optarg_str_p
, "r") == 0)
110 global_dissect_options
.time_format
= TS_RELATIVE
;
111 else if (strcmp(optarg_str_p
, "a") == 0)
112 global_dissect_options
.time_format
= TS_ABSOLUTE
;
113 else if (strcmp(optarg_str_p
, "ad") == 0)
114 global_dissect_options
.time_format
= TS_ABSOLUTE_WITH_YMD
;
115 else if (strcmp(optarg_str_p
, "adoy") == 0)
116 global_dissect_options
.time_format
= TS_ABSOLUTE_WITH_YDOY
;
117 else if (strcmp(optarg_str_p
, "d") == 0)
118 global_dissect_options
.time_format
= TS_DELTA
;
119 else if (strcmp(optarg_str_p
, "dd") == 0)
120 global_dissect_options
.time_format
= TS_DELTA_DIS
;
121 else if (strcmp(optarg_str_p
, "e") == 0)
122 global_dissect_options
.time_format
= TS_EPOCH
;
123 else if (strcmp(optarg_str_p
, "u") == 0)
124 global_dissect_options
.time_format
= TS_UTC
;
125 else if (strcmp(optarg_str_p
, "ud") == 0)
126 global_dissect_options
.time_format
= TS_UTC_WITH_YMD
;
127 else if (strcmp(optarg_str_p
, "udoy") == 0)
128 global_dissect_options
.time_format
= TS_UTC_WITH_YDOY
;
129 else if (optarg_str_p
!= dotp
) {
130 /* If (optarg_str_p == dotp), user only set precision. */
131 cmdarg_err("Invalid time stamp type \"%s\"; it must be one of:", optarg_str_p
);
132 cmdarg_err_cont("\t\"a\" for absolute\n"
133 "\t\"ad\" for absolute with YYYY-MM-DD date\n"
134 "\t\"adoy\" for absolute with YYYY/DOY date\n"
135 "\t\"d\" for delta\n"
136 "\t\"dd\" for delta displayed\n"
137 "\t\"e\" for epoch\n"
138 "\t\"r\" for relative\n"
139 "\t\"u\" for absolute UTC\n"
140 "\t\"ud\" for absolute UTC with YYYY-MM-DD date\n"
141 "\t\"udoy\" for absolute UTC with YYYY/DOY date");
148 global_dissect_options
.time_precision
= tsp
;
151 case 'u': /* Seconds type */
152 if (strcmp(optarg_str_p
, "s") == 0)
153 timestamp_set_seconds_type(TS_SECONDS_DEFAULT
);
154 else if (strcmp(optarg_str_p
, "hms") == 0)
155 timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC
);
157 cmdarg_err("Invalid seconds type \"%s\"; it must be one of:", optarg_str_p
);
158 cmdarg_err_cont("\t\"s\" for seconds\n"
159 "\t\"hms\" for hours, minutes and seconds");
163 case LONGOPT_DISABLE_PROTOCOL
: /* disable dissection of protocol */
164 global_dissect_options
.disable_protocol_slist
= g_slist_append(global_dissect_options
.disable_protocol_slist
, optarg_str_p
);
166 case LONGOPT_ENABLE_HEURISTIC
: /* enable heuristic dissection of protocol */
167 global_dissect_options
.enable_heur_slist
= g_slist_append(global_dissect_options
.enable_heur_slist
, optarg_str_p
);
169 case LONGOPT_DISABLE_HEURISTIC
: /* disable heuristic dissection of protocol */
170 global_dissect_options
.disable_heur_slist
= g_slist_append(global_dissect_options
.disable_heur_slist
, optarg_str_p
);
172 case LONGOPT_ENABLE_PROTOCOL
: /* enable dissection of protocol (that is disabled by default) */
173 global_dissect_options
.enable_protocol_slist
= g_slist_append(global_dissect_options
.enable_protocol_slist
, optarg_str_p
);
175 case LONGOPT_ONLY_PROTOCOLS
: /* enable dissection of these comma separated protocols only */
177 for (char *ps
= strtok (optarg_str_p
, ","); ps
; ps
= strtok(NULL
, ",")){
178 global_dissect_options
.enable_protocol_slist
= g_slist_append(global_dissect_options
.enable_protocol_slist
, ps
);
181 case LONGOPT_DISABLE_ALL_PROTOCOLS
: /* disable dissection of all protocols */
185 /* the caller is responsible to send us only the right opt's */
186 ws_assert_not_reached();
191 typedef bool (proto_set_func
)(const char *);
194 process_enable_disable_list(GSList
*list
, proto_set_func callback
)
202 for (iter
= list
; iter
!= NULL
; iter
= g_slist_next(iter
)) {
203 proto_name
= (char *)iter
->data
;
204 c
= strchr(proto_name
, ',');
206 rv
= callback(proto_name
);
208 cmdarg_err("No such protocol %s", proto_name
);
222 rv
= callback(start
);
224 cmdarg_err("No such protocol %s", start
);
229 start
= (save
== ',' ? c
+1 : c
);
230 c
= strchr(start
, ',');
243 setup_enabled_and_disabled_protocols(void)
247 success
= success
&& process_enable_disable_list(global_dissect_options
.disable_protocol_slist
,
248 proto_disable_proto_by_name
);
249 success
= success
&& process_enable_disable_list(global_dissect_options
.enable_protocol_slist
,
250 proto_enable_proto_by_name
);
251 success
= success
&& process_enable_disable_list(global_dissect_options
.enable_heur_slist
,
252 proto_enable_heuristic_by_name
);
253 success
= success
&& process_enable_disable_list(global_dissect_options
.disable_heur_slist
,
254 proto_disable_heuristic_by_name
);