3 * $Id: dftest.c,v 1.8 2004/02/21 22:00:46 guy Exp $
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>
48 #include "epan/dfilter/dfilter.h"
52 ts_type timestamp_type = TS_RELATIVE;
55 main(int argc, char **argv)
58 char *gpf_path, *pf_path;
59 int gpf_open_errno, gpf_read_errno;
60 int pf_open_errno, pf_read_errno;
64 /* register all dissectors; we must do this before checking for the
65 "-g" flag, as the "-g" flag dumps a list of fields registered
66 by the dissectors, and we must do it before we read the preferences,
67 in case any dissectors register preferences. */
68 epan_init(PLUGIN_DIR,register_all_protocols,
69 register_all_protocol_handoffs);
71 /* now register the preferences for any non-dissector modules.
72 we must do that before we read the preferences as well. */
73 prefs_register_modules();
75 /* set the c-language locale to the native environment. */
76 setlocale(LC_ALL, "");
78 prefs = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
79 &pf_open_errno, &pf_read_errno, &pf_path);
80 if (gpf_path != NULL) {
81 if (gpf_open_errno != 0) {
83 "can't open global preferences file \"%s\": %s.\n",
84 pf_path, strerror(gpf_open_errno));
86 if (gpf_read_errno != 0) {
88 "I/O error reading global preferences file \"%s\": %s.\n",
89 pf_path, strerror(gpf_read_errno));
92 if (pf_path != NULL) {
93 if (pf_open_errno != 0) {
95 "can't open your preferences file \"%s\": %s.\n",
96 pf_path, strerror(pf_open_errno));
98 if (pf_read_errno != 0) {
100 "I/O error reading your preferences file \"%s\": %s.\n",
101 pf_path, strerror(pf_read_errno));
105 /* notify all registered modules that have had any of their preferences
106 changed either from one of the preferences file or from the command
107 line that its preferences have changed. */
110 /* Check for filter on command line */
112 fprintf(stderr, "Usage: dftest filter\n");
116 /* Get filter text */
117 text = get_args_as_string(argc, argv, 1);
119 printf("Filter: \"%s\"\n", text);
122 if (!dfilter_compile(text, &df)) {
123 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
127 printf("dfilter ptr = 0x%08x\n", (unsigned int) df);
138 * Open/create errors are reported with an console message in "dftest".
141 report_open_failure(const char *filename, int err, gboolean for_writing)
145 errmsg = g_strdup_printf(file_open_error_message(err, for_writing), filename);
146 fprintf(stderr, "dftest: %s\n", errmsg);
151 * Read errors are reported with an console message in "dftest".
154 report_read_failure(const char *filename, int err)
156 fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.",
157 filename, strerror(err));