3 * $Id: dftest.c,v 1.3 2002/01/21 07:36:31 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.
44 #ifdef HAVE_SYS_TYPES_H
45 #include <sys/types.h>
48 #ifdef HAVE_SYS_STAT_H
58 #ifdef NEED_SNPRINTF_H
59 # include "snprintf.h"
63 #ifdef NEED_STRERROR_H
68 #include <epan/epan.h>
72 #include <epan/packet.h>
76 #include <epan/resolv.h>
77 #include <epan/conversation.h>
79 #include <epan/timestamp.h>
80 #include <epan/plugins.h>
83 #include "epan/dfilter/dfilter.h"
87 ts_type timestamp_type = RELATIVE;
90 main(int argc, char **argv)
93 char *gpf_path, *pf_path;
94 int gpf_open_errno, pf_open_errno;
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 epan_init(PLUGIN_DIR,register_all_protocols,
103 register_all_protocol_handoffs);
105 /* now register the preferences for any non-dissector modules.
106 we must do that before we read the preferences as well. */
107 prefs_register_modules();
109 /* set the c-language locale to the native environment. */
110 setlocale(LC_ALL, "");
112 prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path);
113 if (gpf_path != NULL) {
114 fprintf(stderr, "can't open global preferences file \"%s\": %s.\n",
115 pf_path, strerror(gpf_open_errno));
117 if (pf_path != NULL) {
118 fprintf(stderr, "can't open your preferences file \"%s\": %s.\n",
119 pf_path, strerror(pf_open_errno));
122 /* notify all registered modules that have had any of their preferences
123 changed either from one of the preferences file or from the command
124 line that its preferences have changed. */
127 /* Check for filter on command line */
129 fprintf(stderr, "Usage: dftest filter\n");
133 /* Get filter text */
134 text = get_args_as_string(argc, argv, 1);
136 printf("Filter: \"%s\"\n", text);
139 if (!dfilter_compile(text, &df)) {
140 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
144 printf("dfilter ptr = 0x%08x\n", (unsigned int) df);