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 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/epan.h>
34 #include <epan/timestamp.h>
35 #include <epan/prefs.h>
36 #include <epan/dfilter/dfilter.h>
39 #include <wsutil/plugins.h>
41 #include <wsutil/filesystem.h>
42 #include <wsutil/privileges.h>
43 #include <wsutil/report_message.h>
45 #include <wiretap/wtap.h>
50 static void failure_warning_message(const char *msg_format, va_list ap);
51 static void open_failure_message(const char *filename, int err,
52 gboolean for_writing);
53 static void read_failure_message(const char *filename, int err);
54 static void write_failure_message(const char *filename, int err);
57 main(int argc, char **argv)
59 char *init_progfile_dir_error;
65 * Get credential information for later use.
67 init_process_policies();
70 * Attempt to get the pathname of the directory containing the
73 init_progfile_dir_error = init_progfile_dir(argv[0], main);
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(failure_warning_message, failure_warning_message,
81 open_failure_message, read_failure_message,
82 write_failure_message);
84 timestamp_set_type(TS_RELATIVE);
85 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
88 /* Register all the plugin types we have. */
89 epan_register_plugin_types(); /* Types known to libwireshark */
91 /* Scan for plugins. This does *not* call their registration routines;
93 scan_plugins(REPORT_LOAD_FAILURE);
98 /* Register all dissectors; we must do this before checking for the
99 "-g" flag, as the "-g" flag dumps a list of fields registered
100 by the dissectors, and we must do it before we read the preferences,
101 in case any dissectors register preferences. */
102 if (!epan_init(register_all_protocols, register_all_protocol_handoffs,
106 /* set the c-language locale to the native environment. */
107 setlocale(LC_ALL, "");
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. */
117 /* Check for filter on command line */
119 fprintf(stderr, "Usage: dftest <filter>\n");
123 /* Get filter text */
124 text = get_args_as_string(argc, argv, 1);
126 printf("Filter: \"%s\"\n", text);
129 if (!dfilter_compile(text, &df, &err_msg)) {
130 fprintf(stderr, "dftest: %s\n", err_msg);
139 printf("Filter is empty\n");
149 * General errors and warnings are reported with an console message
153 failure_warning_message(const char *msg_format, va_list ap)
155 fprintf(stderr, "dftest: ");
156 vfprintf(stderr, msg_format, ap);
157 fprintf(stderr, "\n");
161 * Open/create errors are reported with an console message in "dftest".
164 open_failure_message(const char *filename, int err, gboolean for_writing)
166 fprintf(stderr, "dftest: ");
167 fprintf(stderr, file_open_error_message(err, for_writing), filename);
168 fprintf(stderr, "\n");
172 * Read errors are reported with an console message in "dftest".
175 read_failure_message(const char *filename, int err)
177 fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n",
178 filename, g_strerror(err));
182 * Write errors are reported with an console message in "dftest".
185 write_failure_message(const char *filename, int err)
187 fprintf(stderr, "dftest: An error occurred while writing to the file \"%s\": %s.\n",
188 filename, g_strerror(err));
192 * Editor modelines - http://www.wireshark.org/tools/modelines.html
197 * indent-tabs-mode: t
200 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
201 * :indentSize=8:tabSize=8:noTabs=false: