2 * Shows display filter byte-code, for debugging dfilter routines.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef NEED_STRERROR_H
36 #include "wsutil/strerror.h"
40 #include <epan/epan.h>
42 #include <epan/timestamp.h>
43 #include <epan/plugins.h>
44 #include <epan/filesystem.h>
45 #include <wsutil/privileges.h>
46 #include <epan/prefs.h>
48 #include "epan/dfilter/dfilter.h"
51 static void failure_message(const char *msg_format, va_list ap);
52 static void open_failure_message(const char *filename, int err,
53 gboolean for_writing);
54 static void read_failure_message(const char *filename, int err);
55 static void write_failure_message(const char *filename, int err);
58 main(int argc, char **argv)
60 char *init_progfile_dir_error;
62 char *gpf_path, *pf_path;
63 int gpf_open_errno, gpf_read_errno;
64 int pf_open_errno, pf_read_errno;
69 * Get credential information for later use.
71 init_process_policies();
74 * Attempt to get the pathname of the executable file.
76 init_progfile_dir_error = init_progfile_dir(argv[0], main);
77 if (init_progfile_dir_error != NULL) {
78 fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n",
79 init_progfile_dir_error);
82 timestamp_set_type(TS_RELATIVE);
83 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
85 /* Register all dissectors; we must do this before checking for the
86 "-g" flag, as the "-g" flag dumps a list of fields registered
87 by the dissectors, and we must do it before we read the preferences,
88 in case any dissectors register preferences. */
89 epan_init(register_all_protocols,
90 register_all_protocol_handoffs, NULL, NULL,
91 failure_message, open_failure_message, read_failure_message,
92 write_failure_message);
94 /* now register the preferences for any non-dissector modules.
95 we must do that before we read the preferences as well. */
96 prefs_register_modules();
98 /* set the c-language locale to the native environment. */
99 setlocale(LC_ALL, "");
101 prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
102 &pf_open_errno, &pf_read_errno, &pf_path);
103 if (gpf_path != NULL) {
104 if (gpf_open_errno != 0) {
106 "can't open global preferences file \"%s\": %s.\n",
107 pf_path, strerror(gpf_open_errno));
109 if (gpf_read_errno != 0) {
111 "I/O error reading global preferences file \"%s\": %s.\n",
112 pf_path, strerror(gpf_read_errno));
115 if (pf_path != NULL) {
116 if (pf_open_errno != 0) {
118 "can't open your preferences file \"%s\": %s.\n",
119 pf_path, strerror(pf_open_errno));
121 if (pf_read_errno != 0) {
123 "I/O error reading your preferences file \"%s\": %s.\n",
124 pf_path, strerror(pf_read_errno));
128 /* notify all registered modules that have had any of their preferences
129 changed either from one of the preferences file or from the command
130 line that its preferences have changed. */
133 /* Check for filter on command line */
135 fprintf(stderr, "Usage: dftest <filter>\n");
139 /* Get filter text */
140 text = get_args_as_string(argc, argv, 1);
142 printf("Filter: \"%s\"\n", text);
145 if (!dfilter_compile(text, &df)) {
146 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
150 printf("dfilter ptr = 0x%08x\n", GPOINTER_TO_INT(df));
155 printf("Filter is empty\n");
165 * General errors are reported with an console message in "dftest".
168 failure_message(const char *msg_format, va_list ap)
170 fprintf(stderr, "dftest: ");
171 vfprintf(stderr, msg_format, ap);
172 fprintf(stderr, "\n");
176 * Open/create errors are reported with an console message in "dftest".
179 open_failure_message(const char *filename, int err, gboolean for_writing)
181 fprintf(stderr, "dftest: ");
182 fprintf(stderr, file_open_error_message(err, for_writing), filename);
183 fprintf(stderr, "\n");
187 * Read errors are reported with an console message in "dftest".
190 read_failure_message(const char *filename, int err)
192 fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n",
193 filename, strerror(err));
197 * Write errors are reported with an console message in "dftest".
200 write_failure_message(const char *filename, int err)
202 fprintf(stderr, "dftest: An error occurred while writing to the file \"%s\": %s.\n",
203 filename, strerror(err));