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>
38 #include <wsutil/plugins.h>
39 #include <wsutil/filesystem.h>
40 #include <wsutil/privileges.h>
41 #include <wsutil/report_err.h>
46 static void failure_message(const char *msg_format, va_list ap);
47 static void open_failure_message(const char *filename, int err,
48 gboolean for_writing);
49 static void read_failure_message(const char *filename, int err);
50 static void write_failure_message(const char *filename, int err);
53 main(int argc, char **argv)
55 char *init_progfile_dir_error;
57 char *gpf_path, *pf_path;
58 int gpf_open_errno, gpf_read_errno;
59 int pf_open_errno, pf_read_errno;
63 * Get credential information for later use.
65 init_process_policies();
68 * Attempt to get the pathname of the executable file.
70 init_progfile_dir_error = init_progfile_dir(argv[0], main);
71 if (init_progfile_dir_error != NULL) {
72 fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n",
73 init_progfile_dir_error);
76 init_report_err(failure_message, open_failure_message,
77 read_failure_message, write_failure_message);
79 timestamp_set_type(TS_RELATIVE);
80 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
82 /* Register all dissectors; we must do this before checking for the
83 "-g" flag, as the "-g" flag dumps a list of fields registered
84 by the dissectors, and we must do it before we read the preferences,
85 in case any dissectors register preferences. */
86 epan_init(register_all_protocols, register_all_protocol_handoffs,
89 /* set the c-language locale to the native environment. */
90 setlocale(LC_ALL, "");
92 read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
93 &pf_open_errno, &pf_read_errno, &pf_path);
94 if (gpf_path != NULL) {
95 if (gpf_open_errno != 0) {
97 "can't open global preferences file \"%s\": %s.\n",
98 pf_path, g_strerror(gpf_open_errno));
100 if (gpf_read_errno != 0) {
102 "I/O error reading global preferences file \"%s\": %s.\n",
103 pf_path, g_strerror(gpf_read_errno));
106 if (pf_path != NULL) {
107 if (pf_open_errno != 0) {
109 "can't open your preferences file \"%s\": %s.\n",
110 pf_path, g_strerror(pf_open_errno));
112 if (pf_read_errno != 0) {
114 "I/O error reading your preferences file \"%s\": %s.\n",
115 pf_path, g_strerror(pf_read_errno));
119 /* notify all registered modules that have had any of their preferences
120 changed either from one of the preferences file or from the command
121 line that its preferences have changed. */
124 /* Check for filter on command line */
126 fprintf(stderr, "Usage: dftest <filter>\n");
130 /* Get filter text */
131 text = get_args_as_string(argc, argv, 1);
133 printf("Filter: \"%s\"\n", text);
136 if (!dfilter_compile(text, &df)) {
137 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
145 printf("Filter is empty\n");
155 * General errors are reported with an console message in "dftest".
158 failure_message(const char *msg_format, va_list ap)
160 fprintf(stderr, "dftest: ");
161 vfprintf(stderr, msg_format, ap);
162 fprintf(stderr, "\n");
166 * Open/create errors are reported with an console message in "dftest".
169 open_failure_message(const char *filename, int err, gboolean for_writing)
171 fprintf(stderr, "dftest: ");
172 fprintf(stderr, file_open_error_message(err, for_writing), filename);
173 fprintf(stderr, "\n");
177 * Read errors are reported with an console message in "dftest".
180 read_failure_message(const char *filename, int err)
182 fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n",
183 filename, g_strerror(err));
187 * Write errors are reported with an console message in "dftest".
190 write_failure_message(const char *filename, int err)
192 fprintf(stderr, "dftest: An error occurred while writing to the file \"%s\": %s.\n",
193 filename, g_strerror(err));