packet-iwarp-mpa: make use of tcp_dissect_pdus() to reassamble pdus
[wireshark-sm.git] / dftest.c
blobe248b56183904cda82bcd192c02be8f21b191247
1 /* dftest.c
2 * Shows display filter byte-code, for debugging dfilter routines.
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
9 */
11 #include <config.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <locale.h>
16 #include <string.h>
17 #include <errno.h>
19 #include <glib.h>
21 #include <epan/epan.h>
22 #include <epan/timestamp.h>
23 #include <epan/prefs.h>
24 #include <epan/dfilter/dfilter.h>
26 #ifdef HAVE_PLUGINS
27 #include <wsutil/plugins.h>
28 #endif
29 #include <wsutil/filesystem.h>
30 #include <wsutil/privileges.h>
31 #include <wsutil/report_message.h>
33 #include <wiretap/wtap.h>
35 #include "ui/util.h"
36 #include "ui/cmdarg_err.h"
37 #include "ui/failure_message.h"
39 static void dftest_cmdarg_err(const char *fmt, va_list ap);
40 static void dftest_cmdarg_err_cont(const char *fmt, va_list ap);
42 int
43 main(int argc, char **argv)
45 char *init_progfile_dir_error;
46 static const struct report_message_routines dftest_report_routines = {
47 failure_message,
48 failure_message,
49 open_failure_message,
50 read_failure_message,
51 write_failure_message,
52 cfile_open_failure_message,
53 cfile_dump_open_failure_message,
54 cfile_read_failure_message,
55 cfile_write_failure_message,
56 cfile_close_failure_message
58 char *text;
59 dfilter_t *df;
60 gchar *err_msg;
62 cmdarg_err_init(dftest_cmdarg_err, dftest_cmdarg_err_cont);
65 * Get credential information for later use.
67 init_process_policies();
70 * Attempt to get the pathname of the directory containing the
71 * executable file.
73 init_progfile_dir_error = init_progfile_dir(argv[0]);
74 if (init_progfile_dir_error != NULL) {
75 fprintf(stderr, "dftest: Can't get pathname of directory containing the dftest program: %s.\n",
76 init_progfile_dir_error);
77 g_free(init_progfile_dir_error);
80 init_report_message("dftest", &dftest_report_routines);
82 timestamp_set_type(TS_RELATIVE);
83 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
86 * Libwiretap must be initialized before libwireshark is, so that
87 * dissection-time handlers for file-type-dependent blocks can
88 * register using the file type/subtype value for the file type.
90 wtap_init(TRUE);
92 /* Register all dissectors; we must do this before checking for the
93 "-g" flag, as the "-g" flag dumps a list of fields registered
94 by the dissectors, and we must do it before we read the preferences,
95 in case any dissectors register preferences. */
96 if (!epan_init(NULL, NULL, FALSE))
97 return 2;
100 * Set the C-language locale to the native environment and set the
101 * code page to UTF-8 on Windows.
103 #ifdef _WIN32
104 setlocale(LC_ALL, ".UTF-8");
105 #else
106 setlocale(LC_ALL, "");
107 #endif
109 /* Load libwireshark settings from the current profile. */
110 epan_load_settings();
112 /* notify all registered modules that have had any of their preferences
113 changed either from one of the preferences file or from the command
114 line that its preferences have changed. */
115 prefs_apply_all();
117 /* Check for filter on command line */
118 if (argc <= 1) {
119 fprintf(stderr, "Usage: dftest <filter>\n");
120 exit(1);
123 /* Get filter text */
124 text = get_args_as_string(argc, argv, 1);
126 printf("Filter: \"%s\"\n", text);
128 /* Compile it */
129 if (!dfilter_compile(text, &df, &err_msg)) {
130 fprintf(stderr, "dftest: %s\n", err_msg);
131 g_free(err_msg);
132 epan_cleanup();
133 g_free(text);
134 exit(2);
137 printf("\n");
139 if (df == NULL)
140 printf("Filter is empty\n");
141 else
142 dfilter_dump(df);
144 dfilter_free(df);
145 epan_cleanup();
146 g_free(text);
147 exit(0);
151 * Report an error in command-line arguments.
153 static void
154 dftest_cmdarg_err(const char *fmt, va_list ap)
156 fprintf(stderr, "dftest: ");
157 vfprintf(stderr, fmt, ap);
158 fprintf(stderr, "\n");
162 * Report additional information for an error in command-line arguments.
164 static void
165 dftest_cmdarg_err_cont(const char *fmt, va_list ap)
167 vfprintf(stderr, fmt, ap);
168 fprintf(stderr, "\n");
172 * Editor modelines - https://www.wireshark.org/tools/modelines.html
174 * Local variables:
175 * c-basic-offset: 8
176 * tab-width: 8
177 * indent-tabs-mode: t
178 * End:
180 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
181 * :indentSize=8:tabSize=8:noTabs=false: