2 * Shows display filter byte-code, for debugging dfilter routines.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
21 #include <epan/epan.h>
22 #include <epan/timestamp.h>
23 #include <epan/prefs.h>
24 #include <epan/dfilter/dfilter.h>
27 #include <wsutil/plugins.h>
29 #include <wsutil/filesystem.h>
30 #include <wsutil/privileges.h>
31 #include <wsutil/report_message.h>
33 #include <wiretap/wtap.h>
36 #include "ui/cmdarg_err.h"
37 #include "ui/failure_message.h"
39 static void dftest_cmdarg_err(const char *fmt
, va_list ap
);
40 static void dftest_cmdarg_err_cont(const char *fmt
, va_list ap
);
43 main(int argc
, char **argv
)
45 char *init_progfile_dir_error
;
46 static const struct report_message_routines dftest_report_routines
= {
51 write_failure_message
,
52 cfile_open_failure_message
,
53 cfile_dump_open_failure_message
,
54 cfile_read_failure_message
,
55 cfile_write_failure_message
,
56 cfile_close_failure_message
62 cmdarg_err_init(dftest_cmdarg_err
, dftest_cmdarg_err_cont
);
65 * Get credential information for later use.
67 init_process_policies();
70 * Attempt to get the pathname of the directory containing the
73 init_progfile_dir_error
= init_progfile_dir(argv
[0]);
74 if (init_progfile_dir_error
!= NULL
) {
75 fprintf(stderr
, "dftest: Can't get pathname of directory containing the dftest program: %s.\n",
76 init_progfile_dir_error
);
77 g_free(init_progfile_dir_error
);
80 init_report_message("dftest", &dftest_report_routines
);
82 timestamp_set_type(TS_RELATIVE
);
83 timestamp_set_seconds_type(TS_SECONDS_DEFAULT
);
86 * Libwiretap must be initialized before libwireshark is, so that
87 * dissection-time handlers for file-type-dependent blocks can
88 * register using the file type/subtype value for the file type.
92 /* Register all dissectors; we must do this before checking for the
93 "-g" flag, as the "-g" flag dumps a list of fields registered
94 by the dissectors, and we must do it before we read the preferences,
95 in case any dissectors register preferences. */
96 if (!epan_init(NULL
, NULL
, FALSE
))
100 * Set the C-language locale to the native environment and set the
101 * code page to UTF-8 on Windows.
104 setlocale(LC_ALL
, ".UTF-8");
106 setlocale(LC_ALL
, "");
109 /* Load libwireshark settings from the current profile. */
110 epan_load_settings();
112 /* notify all registered modules that have had any of their preferences
113 changed either from one of the preferences file or from the command
114 line that its preferences have changed. */
117 /* Check for filter on command line */
119 fprintf(stderr
, "Usage: dftest <filter>\n");
123 /* Get filter text */
124 text
= get_args_as_string(argc
, argv
, 1);
126 printf("Filter: \"%s\"\n", text
);
129 if (!dfilter_compile(text
, &df
, &err_msg
)) {
130 fprintf(stderr
, "dftest: %s\n", err_msg
);
140 printf("Filter is empty\n");
151 * Report an error in command-line arguments.
154 dftest_cmdarg_err(const char *fmt
, va_list ap
)
156 fprintf(stderr
, "dftest: ");
157 vfprintf(stderr
, fmt
, ap
);
158 fprintf(stderr
, "\n");
162 * Report additional information for an error in command-line arguments.
165 dftest_cmdarg_err_cont(const char *fmt
, va_list ap
)
167 vfprintf(stderr
, fmt
, ap
);
168 fprintf(stderr
, "\n");
172 * Editor modelines - https://www.wireshark.org/tools/modelines.html
177 * indent-tabs-mode: t
180 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
181 * :indentSize=8:tabSize=8:noTabs=false: