nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* dftest.c |
2 | * Shows display filter byte-code, for debugging dfilter routines. |
||
3 | * |
||
4 | * Wireshark - Network traffic analyzer |
||
5 | * By Gerald Combs <gerald@wireshark.org> |
||
6 | * Copyright 1998 Gerald Combs |
||
7 | * |
||
8 | * This program is free software; you can redistribute it and/or |
||
9 | * modify it under the terms of the GNU General Public License |
||
10 | * as published by the Free Software Foundation; either version 2 |
||
11 | * of the License, or (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with this program; if not, write to the Free Software |
||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
21 | */ |
||
22 | |||
23 | #include <config.h> |
||
24 | |||
25 | #include <stdlib.h> |
||
26 | #include <stdio.h> |
||
27 | #include <locale.h> |
||
28 | #include <string.h> |
||
29 | #include <errno.h> |
||
30 | |||
31 | #include <glib.h> |
||
32 | |||
33 | #include <epan/epan.h> |
||
34 | #include <epan/timestamp.h> |
||
35 | #include <epan/prefs.h> |
||
36 | #include <epan/dfilter/dfilter.h> |
||
37 | |||
38 | #ifdef HAVE_PLUGINS |
||
39 | #include <wsutil/plugins.h> |
||
40 | #endif |
||
41 | #include <wsutil/filesystem.h> |
||
42 | #include <wsutil/privileges.h> |
||
43 | #include <wsutil/report_err.h> |
||
44 | |||
45 | #include "ui/util.h" |
||
46 | #include "register.h" |
||
47 | |||
48 | static void failure_message(const char *msg_format, va_list ap); |
||
49 | static void open_failure_message(const char *filename, int err, |
||
50 | gboolean for_writing); |
||
51 | static void read_failure_message(const char *filename, int err); |
||
52 | static void write_failure_message(const char *filename, int err); |
||
53 | |||
54 | int |
||
55 | main(int argc, char **argv) |
||
56 | { |
||
57 | char *init_progfile_dir_error; |
||
58 | char *text; |
||
59 | char *gpf_path, *pf_path; |
||
60 | int gpf_open_errno, gpf_read_errno; |
||
61 | int pf_open_errno, pf_read_errno; |
||
62 | dfilter_t *df; |
||
63 | gchar *err_msg; |
||
64 | |||
65 | /* |
||
66 | * Get credential information for later use. |
||
67 | */ |
||
68 | init_process_policies(); |
||
69 | |||
70 | /* |
||
71 | * Attempt to get the pathname of the executable file. |
||
72 | */ |
||
73 | init_progfile_dir_error = init_progfile_dir(argv[0], main); |
||
74 | if (init_progfile_dir_error != NULL) { |
||
75 | fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n", |
||
76 | init_progfile_dir_error); |
||
77 | } |
||
78 | |||
79 | init_report_err(failure_message, open_failure_message, |
||
80 | read_failure_message, write_failure_message); |
||
81 | |||
82 | timestamp_set_type(TS_RELATIVE); |
||
83 | timestamp_set_seconds_type(TS_SECONDS_DEFAULT); |
||
84 | |||
85 | #ifdef HAVE_PLUGINS |
||
86 | /* Register all the plugin types we have. */ |
||
87 | epan_register_plugin_types(); /* Types known to libwireshark */ |
||
88 | |||
89 | /* Scan for plugins. This does *not* call their registration routines; |
||
90 | that's done later. */ |
||
91 | scan_plugins(); |
||
92 | #endif |
||
93 | |||
94 | /* Register all dissectors; we must do this before checking for the |
||
95 | "-g" flag, as the "-g" flag dumps a list of fields registered |
||
96 | by the dissectors, and we must do it before we read the preferences, |
||
97 | in case any dissectors register preferences. */ |
||
98 | if (!epan_init(register_all_protocols, register_all_protocol_handoffs, |
||
99 | NULL, NULL)) |
||
100 | return 2; |
||
101 | |||
102 | /* set the c-language locale to the native environment. */ |
||
103 | setlocale(LC_ALL, ""); |
||
104 | |||
105 | read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path, |
||
106 | &pf_open_errno, &pf_read_errno, &pf_path); |
||
107 | if (gpf_path != NULL) { |
||
108 | if (gpf_open_errno != 0) { |
||
109 | fprintf(stderr, |
||
110 | "can't open global preferences file \"%s\": %s.\n", |
||
111 | pf_path, g_strerror(gpf_open_errno)); |
||
112 | } |
||
113 | if (gpf_read_errno != 0) { |
||
114 | fprintf(stderr, |
||
115 | "I/O error reading global preferences file \"%s\": %s.\n", |
||
116 | pf_path, g_strerror(gpf_read_errno)); |
||
117 | } |
||
118 | } |
||
119 | if (pf_path != NULL) { |
||
120 | if (pf_open_errno != 0) { |
||
121 | fprintf(stderr, |
||
122 | "can't open your preferences file \"%s\": %s.\n", |
||
123 | pf_path, g_strerror(pf_open_errno)); |
||
124 | } |
||
125 | if (pf_read_errno != 0) { |
||
126 | fprintf(stderr, |
||
127 | "I/O error reading your preferences file \"%s\": %s.\n", |
||
128 | pf_path, g_strerror(pf_read_errno)); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | /* notify all registered modules that have had any of their preferences |
||
133 | changed either from one of the preferences file or from the command |
||
134 | line that its preferences have changed. */ |
||
135 | prefs_apply_all(); |
||
136 | |||
137 | /* Check for filter on command line */ |
||
138 | if (argc <= 1) { |
||
139 | fprintf(stderr, "Usage: dftest <filter>\n"); |
||
140 | exit(1); |
||
141 | } |
||
142 | |||
143 | /* Get filter text */ |
||
144 | text = get_args_as_string(argc, argv, 1); |
||
145 | |||
146 | printf("Filter: \"%s\"\n", text); |
||
147 | |||
148 | /* Compile it */ |
||
149 | if (!dfilter_compile(text, &df, &err_msg)) { |
||
150 | fprintf(stderr, "dftest: %s\n", err_msg); |
||
151 | g_free(err_msg); |
||
152 | epan_cleanup(); |
||
153 | exit(2); |
||
154 | } |
||
155 | |||
156 | printf("\n"); |
||
157 | |||
158 | if (df == NULL) |
||
159 | printf("Filter is empty\n"); |
||
160 | else |
||
161 | dfilter_dump(df); |
||
162 | |||
163 | dfilter_free(df); |
||
164 | epan_cleanup(); |
||
165 | exit(0); |
||
166 | } |
||
167 | |||
168 | /* |
||
169 | * General errors are reported with an console message in "dftest". |
||
170 | */ |
||
171 | static void |
||
172 | failure_message(const char *msg_format, va_list ap) |
||
173 | { |
||
174 | fprintf(stderr, "dftest: "); |
||
175 | vfprintf(stderr, msg_format, ap); |
||
176 | fprintf(stderr, "\n"); |
||
177 | } |
||
178 | |||
179 | /* |
||
180 | * Open/create errors are reported with an console message in "dftest". |
||
181 | */ |
||
182 | static void |
||
183 | open_failure_message(const char *filename, int err, gboolean for_writing) |
||
184 | { |
||
185 | fprintf(stderr, "dftest: "); |
||
186 | fprintf(stderr, file_open_error_message(err, for_writing), filename); |
||
187 | fprintf(stderr, "\n"); |
||
188 | } |
||
189 | |||
190 | /* |
||
191 | * Read errors are reported with an console message in "dftest". |
||
192 | */ |
||
193 | static void |
||
194 | read_failure_message(const char *filename, int err) |
||
195 | { |
||
196 | fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n", |
||
197 | filename, g_strerror(err)); |
||
198 | } |
||
199 | |||
200 | /* |
||
201 | * Write errors are reported with an console message in "dftest". |
||
202 | */ |
||
203 | static void |
||
204 | write_failure_message(const char *filename, int err) |
||
205 | { |
||
206 | fprintf(stderr, "dftest: An error occurred while writing to the file \"%s\": %s.\n", |
||
207 | filename, g_strerror(err)); |
||
208 | } |
||
209 | |||
210 | /* |
||
211 | * Editor modelines - http://www.wireshark.org/tools/modelines.html |
||
212 | * |
||
213 | * Local variables: |
||
214 | * c-basic-offset: 8 |
||
215 | * tab-width: 8 |
||
216 | * indent-tabs-mode: t |
||
217 | * End: |
||
218 | * |
||
219 | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
||
220 | * :indentSize=8:tabSize=8:noTabs=false: |
||
221 | */ |