5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@ethereal.com>
7 * Copyright 1998 Gerald Combs
9 * Shows display filter byte-code, for debugging dfilter routines.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #ifdef NEED_STRERROR_H
41 #include <epan/epan.h>
43 #include <epan/timestamp.h>
44 #include <epan/plugins.h>
45 #include <epan/filesystem.h>
46 #include <epan/privileges.h>
47 #include <epan/prefs.h>
49 #include "epan/dfilter/dfilter.h"
54 static void failure_message(const char *msg_format, va_list ap);
55 static void open_failure_message(const char *filename, int err,
56 gboolean for_writing);
57 static void read_failure_message(const char *filename, int err);
60 main(int argc, char **argv)
63 char *gpf_path, *pf_path;
64 int gpf_open_errno, gpf_read_errno;
65 int pf_open_errno, pf_read_errno;
70 * Get credential information for later use.
72 get_credential_info();
74 timestamp_set_type(TS_RELATIVE);
76 /* register all dissectors; we must do this before checking for the
77 "-g" flag, as the "-g" flag dumps a list of fields registered
78 by the dissectors, and we must do it before we read the preferences,
79 in case any dissectors register preferences. */
80 epan_init(PLUGIN_DIR,register_all_protocols,
81 register_all_protocol_handoffs,
82 failure_message, open_failure_message, read_failure_message);
84 /* now register the preferences for any non-dissector modules.
85 we must do that before we read the preferences as well. */
86 prefs_register_modules();
88 /* set the c-language locale to the native environment. */
89 setlocale(LC_ALL, "");
91 prefs = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
92 &pf_open_errno, &pf_read_errno, &pf_path);
93 if (gpf_path != NULL) {
94 if (gpf_open_errno != 0) {
96 "can't open global preferences file \"%s\": %s.\n",
97 pf_path, strerror(gpf_open_errno));
99 if (gpf_read_errno != 0) {
101 "I/O error reading global preferences file \"%s\": %s.\n",
102 pf_path, strerror(gpf_read_errno));
105 if (pf_path != NULL) {
106 if (pf_open_errno != 0) {
108 "can't open your preferences file \"%s\": %s.\n",
109 pf_path, strerror(pf_open_errno));
111 if (pf_read_errno != 0) {
113 "I/O error reading your preferences file \"%s\": %s.\n",
114 pf_path, strerror(pf_read_errno));
118 /* notify all registered modules that have had any of their preferences
119 changed either from one of the preferences file or from the command
120 line that its preferences have changed. */
123 /* Check for filter on command line */
125 fprintf(stderr, "Usage: dftest filter\n");
129 /* Get filter text */
130 text = get_args_as_string(argc, argv, 1);
132 printf("Filter: \"%s\"\n", text);
135 if (!dfilter_compile(text, &df)) {
136 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
140 printf("dfilter ptr = 0x%08x\n", GPOINTER_TO_INT(df));
145 printf("Filter is empty\n");
154 * General errors are reported with an console message in "dftest".
157 failure_message(const char *msg_format, va_list ap)
159 fprintf(stderr, "dftest: ");
160 vfprintf(stderr, msg_format, ap);
161 fprintf(stderr, "\n");
165 * Open/create errors are reported with an console message in "dftest".
168 open_failure_message(const char *filename, int err, gboolean for_writing)
170 fprintf(stderr, "dftest: ");
171 fprintf(stderr, file_open_error_message(err, for_writing), filename);
172 fprintf(stderr, "\n");
176 * Read errors are reported with an console message in "dftest".
179 read_failure_message(const char *filename, int err)
181 fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n",
182 filename, strerror(err));