2009-02-15 21:47:57 +00:00
|
|
|
/* dftest.c
|
|
|
|
* Shows display filter byte-code, for debugging dfilter routines.
|
2001-02-01 20:21:25 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-02-01 20:21:25 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2017-11-08 15:43:53 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2001-02-01 20:21:25 +00:00
|
|
|
*/
|
|
|
|
|
2014-08-22 21:13:05 +00:00
|
|
|
#include <config.h>
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2013-12-02 08:30:29 +00:00
|
|
|
#include <epan/epan.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/timestamp.h>
|
2013-12-02 08:30:29 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/dfilter/dfilter.h>
|
|
|
|
|
2014-12-02 04:08:50 +00:00
|
|
|
#ifdef HAVE_PLUGINS
|
2013-12-02 08:30:29 +00:00
|
|
|
#include <wsutil/plugins.h>
|
2014-12-02 04:08:50 +00:00
|
|
|
#endif
|
2013-11-17 02:55:14 +00:00
|
|
|
#include <wsutil/filesystem.h>
|
2008-06-30 17:16:29 +00:00
|
|
|
#include <wsutil/privileges.h>
|
2017-04-08 19:45:19 +00:00
|
|
|
#include <wsutil/report_message.h>
|
2013-12-02 08:30:29 +00:00
|
|
|
|
2017-02-09 03:31:11 +00:00
|
|
|
#include <wiretap/wtap.h>
|
|
|
|
|
2012-02-17 12:30:27 +00:00
|
|
|
#include "ui/util.h"
|
2001-04-02 00:38:36 +00:00
|
|
|
#include "register.h"
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2017-04-08 19:45:19 +00:00
|
|
|
static void failure_warning_message(const char *msg_format, va_list ap);
|
2004-03-23 21:19:58 +00:00
|
|
|
static void open_failure_message(const char *filename, int err,
|
2009-09-09 16:38:09 +00:00
|
|
|
gboolean for_writing);
|
2004-03-23 21:19:58 +00:00
|
|
|
static void read_failure_message(const char *filename, int err);
|
2009-02-15 21:47:57 +00:00
|
|
|
static void write_failure_message(const char *filename, int err);
|
2004-03-23 21:19:58 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2007-05-25 20:03:26 +00:00
|
|
|
char *init_progfile_dir_error;
|
2001-02-01 20:21:25 +00:00
|
|
|
char *text;
|
|
|
|
dfilter_t *df;
|
2015-01-18 10:22:19 +00:00
|
|
|
gchar *err_msg;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
/*
|
2007-05-21 20:31:45 +00:00
|
|
|
* Get credential information for later use.
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
*/
|
2010-09-16 19:20:06 +00:00
|
|
|
init_process_policies();
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
|
2006-02-08 10:22:20 +00:00
|
|
|
/*
|
2016-12-05 04:25:51 +00:00
|
|
|
* Attempt to get the pathname of the directory containing the
|
|
|
|
* executable file.
|
2006-02-08 10:22:20 +00:00
|
|
|
*/
|
2015-12-12 02:34:47 +00:00
|
|
|
init_progfile_dir_error = init_progfile_dir(argv[0], main);
|
2007-05-25 20:03:26 +00:00
|
|
|
if (init_progfile_dir_error != NULL) {
|
2016-12-05 04:25:51 +00:00
|
|
|
fprintf(stderr, "dftest: Can't get pathname of directory containing the dftest program: %s.\n",
|
2009-09-09 16:38:09 +00:00
|
|
|
init_progfile_dir_error);
|
2016-12-05 04:25:51 +00:00
|
|
|
g_free(init_progfile_dir_error);
|
2007-05-25 20:03:26 +00:00
|
|
|
}
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
|
2017-04-08 19:45:19 +00:00
|
|
|
init_report_message(failure_warning_message, failure_warning_message,
|
|
|
|
open_failure_message, read_failure_message,
|
|
|
|
write_failure_message);
|
2013-12-05 09:30:22 +00:00
|
|
|
|
2005-08-25 21:29:54 +00:00
|
|
|
timestamp_set_type(TS_RELATIVE);
|
2010-05-07 06:35:17 +00:00
|
|
|
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
|
2004-03-18 19:04:33 +00:00
|
|
|
|
2016-06-19 09:01:56 +00:00
|
|
|
#ifdef HAVE_PLUGINS
|
|
|
|
/* Register all the plugin types we have. */
|
|
|
|
epan_register_plugin_types(); /* Types known to libwireshark */
|
|
|
|
|
|
|
|
/* Scan for plugins. This does *not* call their registration routines;
|
|
|
|
that's done later. */
|
2016-09-05 23:26:29 +00:00
|
|
|
scan_plugins(REPORT_LOAD_FAILURE);
|
2016-06-19 09:01:56 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-09 03:31:11 +00:00
|
|
|
wtap_init();
|
|
|
|
|
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
|
|
|
/* Register all dissectors; we must do this before checking for the
|
|
|
|
"-g" flag, as the "-g" flag dumps a list of fields registered
|
|
|
|
by the dissectors, and we must do it before we read the preferences,
|
|
|
|
in case any dissectors register preferences. */
|
2015-10-28 00:41:23 +00:00
|
|
|
if (!epan_init(register_all_protocols, register_all_protocol_handoffs,
|
|
|
|
NULL, NULL))
|
|
|
|
return 2;
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
/* set the c-language locale to the native environment. */
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2017-04-09 19:27:57 +00:00
|
|
|
/* Load libwireshark settings from the current profile. */
|
|
|
|
epan_load_settings();
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
/* notify all registered modules that have had any of their preferences
|
|
|
|
changed either from one of the preferences file or from the command
|
|
|
|
line that its preferences have changed. */
|
|
|
|
prefs_apply_all();
|
|
|
|
|
|
|
|
/* Check for filter on command line */
|
|
|
|
if (argc <= 1) {
|
2006-11-21 00:36:35 +00:00
|
|
|
fprintf(stderr, "Usage: dftest <filter>\n");
|
2001-02-01 20:21:25 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get filter text */
|
|
|
|
text = get_args_as_string(argc, argv, 1);
|
|
|
|
|
|
|
|
printf("Filter: \"%s\"\n", text);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Compile it */
|
2015-01-18 10:22:19 +00:00
|
|
|
if (!dfilter_compile(text, &df, &err_msg)) {
|
|
|
|
fprintf(stderr, "dftest: %s\n", err_msg);
|
|
|
|
g_free(err_msg);
|
2001-02-01 20:21:25 +00:00
|
|
|
epan_cleanup();
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2012-07-23 17:10:13 +00:00
|
|
|
printf("\n");
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2006-04-06 20:07:16 +00:00
|
|
|
if (df == NULL)
|
|
|
|
printf("Filter is empty\n");
|
|
|
|
else
|
|
|
|
dfilter_dump(df);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2009-09-09 16:38:09 +00:00
|
|
|
dfilter_free(df);
|
2001-02-01 20:21:25 +00:00
|
|
|
epan_cleanup();
|
|
|
|
exit(0);
|
|
|
|
}
|
2004-02-21 22:00:46 +00:00
|
|
|
|
2004-04-17 01:05:00 +00:00
|
|
|
/*
|
2017-04-08 19:45:19 +00:00
|
|
|
* General errors and warnings are reported with an console message
|
|
|
|
* in "dftest".
|
2004-04-17 01:05:00 +00:00
|
|
|
*/
|
|
|
|
static void
|
2017-04-08 19:45:19 +00:00
|
|
|
failure_warning_message(const char *msg_format, va_list ap)
|
2004-04-17 01:05:00 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "dftest: ");
|
|
|
|
vfprintf(stderr, msg_format, ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2004-02-21 22:00:46 +00:00
|
|
|
/*
|
|
|
|
* Open/create errors are reported with an console message in "dftest".
|
|
|
|
*/
|
2004-03-23 21:19:58 +00:00
|
|
|
static void
|
|
|
|
open_failure_message(const char *filename, int err, gboolean for_writing)
|
2004-02-21 22:00:46 +00:00
|
|
|
{
|
2004-04-17 01:05:00 +00:00
|
|
|
fprintf(stderr, "dftest: ");
|
|
|
|
fprintf(stderr, file_open_error_message(err, for_writing), filename);
|
|
|
|
fprintf(stderr, "\n");
|
2004-02-21 22:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read errors are reported with an console message in "dftest".
|
|
|
|
*/
|
2004-03-23 21:19:58 +00:00
|
|
|
static void
|
|
|
|
read_failure_message(const char *filename, int err)
|
2004-02-21 22:00:46 +00:00
|
|
|
{
|
2004-04-17 01:05:00 +00:00
|
|
|
fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n",
|
2011-06-28 09:00:11 +00:00
|
|
|
filename, g_strerror(err));
|
2004-02-21 22:00:46 +00:00
|
|
|
}
|
2009-02-15 21:47:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write errors are reported with an console message in "dftest".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
write_failure_message(const char *filename, int err)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "dftest: An error occurred while writing to the file \"%s\": %s.\n",
|
2011-06-28 09:00:11 +00:00
|
|
|
filename, g_strerror(err));
|
2009-02-15 21:47:57 +00:00
|
|
|
}
|
2014-10-12 18:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|