Have a pseudo-header for Ethernet packets, giving the size of the FCS -
[obnox/wireshark/wip.git] / dftest.c
1 /* dftest.c.c
2  *
3  * $Id: dftest.c,v 1.6 2003/08/18 18:35:21 guy Exp $
4  *
5  * Ethereal - Network traffic analyzer
6  * By Gerald Combs <gerald@ethereal.com>
7  * Copyright 1998 Gerald Combs
8  *
9  * Shows display filter byte-code, for debugging dfilter routines.
10  *
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.
15  *
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.
20  *
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.
24  *
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <locale.h>
34 #include <string.h>
35 #include <errno.h>
36
37 #ifdef NEED_STRERROR_H
38 #include "strerror.h"
39 #endif
40
41 #include <glib.h>
42 #include <epan/epan.h>
43
44 #if 0
45 #include "globals.h"
46 #include <epan/packet.h>
47 #include "file.h"
48 #include "column.h"
49 #include "print.h"
50 #include <epan/resolv.h>
51 #include <epan/conversation.h>
52 #endif
53 #include <epan/timestamp.h>
54 #include <epan/plugins.h>
55 #include "prefs.h"
56 #include "util.h"
57 #include "epan/dfilter/dfilter.h"
58 #include "register.h"
59
60 packet_info     pi;
61 ts_type         timestamp_type = RELATIVE;
62
63 int
64 main(int argc, char **argv)
65 {
66         char            *text;
67         char            *gpf_path, *pf_path;
68         int             gpf_open_errno, gpf_read_errno;
69         int             pf_open_errno, pf_read_errno;
70         e_prefs         *prefs;
71         dfilter_t       *df;
72
73         /* register all dissectors; we must do this before checking for the
74         "-g" flag, as the "-g" flag dumps a list of fields registered
75         by the dissectors, and we must do it before we read the preferences,
76         in case any dissectors register preferences. */
77         epan_init(PLUGIN_DIR,register_all_protocols,
78                   register_all_protocol_handoffs);
79
80         /* now register the preferences for any non-dissector modules.
81         we must do that before we read the preferences as well. */
82         prefs_register_modules();
83
84         /* set the c-language locale to the native environment. */
85         setlocale(LC_ALL, "");
86
87         prefs = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
88             &pf_open_errno, &pf_read_errno, &pf_path);
89         if (gpf_path != NULL) {
90                 if (gpf_open_errno != 0) {
91                         fprintf(stderr,
92                             "can't open global preferences file \"%s\": %s.\n",
93                             pf_path, strerror(gpf_open_errno));
94                 }
95                 if (gpf_read_errno != 0) {
96                         fprintf(stderr,
97                             "I/O error reading global preferences file \"%s\": %s.\n",
98                             pf_path, strerror(gpf_read_errno));
99                 }
100         }
101         if (pf_path != NULL) {
102                 if (pf_open_errno != 0) {
103                         fprintf(stderr,
104                             "can't open your preferences file \"%s\": %s.\n",
105                             pf_path, strerror(pf_open_errno));
106                 }
107                 if (pf_read_errno != 0) {
108                         fprintf(stderr,
109                             "I/O error reading your preferences file \"%s\": %s.\n",
110                             pf_path, strerror(pf_read_errno));
111                 }
112         }
113
114         /* notify all registered modules that have had any of their preferences
115         changed either from one of the preferences file or from the command
116         line that its preferences have changed. */
117         prefs_apply_all();
118
119         /* Check for filter on command line */
120         if (argc <= 1) {
121                 fprintf(stderr, "Usage: dftest filter\n");
122                 exit(1);
123         }
124
125         /* Get filter text */
126         text = get_args_as_string(argc, argv, 1);
127
128         printf("Filter: \"%s\"\n", text);
129
130         /* Compile it */
131         if (!dfilter_compile(text, &df)) {
132                 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
133                 epan_cleanup();
134                 exit(2);
135         }
136         printf("dfilter ptr = 0x%08x\n", (unsigned int) df);
137
138         printf("\n\n");
139
140         dfilter_dump(df);
141
142         epan_cleanup();
143         exit(0);
144 }