2016-06-19 02:33:13 -04:00
|
|
|
/* commandline.c
|
2016-06-18 16:49:23 -04:00
|
|
|
* Common command line handling between GUIs
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-04-30 09:47:58 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-06-18 16:49:23 -04:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2023-06-28 18:39:11 -04:00
|
|
|
#include <errno.h>
|
2016-06-18 16:49:23 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-02-06 22:16:37 +00:00
|
|
|
#include <ws_exit_codes.h>
|
2021-07-26 17:22:36 +01:00
|
|
|
#include <wsutil/ws_getopt.h>
|
2016-06-18 16:49:23 -04:00
|
|
|
|
2023-02-06 21:57:51 +00:00
|
|
|
#include <wsutil/version_info.h>
|
2016-06-18 16:49:23 -04:00
|
|
|
|
2024-11-21 09:45:22 -08:00
|
|
|
#include <wsutil/application_flavor.h>
|
2023-02-06 22:50:32 +00:00
|
|
|
#include <wsutil/clopts_common.h>
|
2023-02-06 22:46:45 +00:00
|
|
|
#include <wsutil/cmdarg_err.h>
|
2016-06-18 16:49:23 -04:00
|
|
|
#include <wsutil/filesystem.h>
|
2021-06-18 19:21:42 +01:00
|
|
|
#include <wsutil/ws_assert.h>
|
2022-10-06 06:43:30 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <wsutil/console_win32.h>
|
|
|
|
#endif
|
2016-06-18 16:49:23 -04:00
|
|
|
|
|
|
|
#include <epan/ex-opt.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/proto.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/prefs-int.h>
|
|
|
|
#include <epan/stat_tap_ui.h>
|
|
|
|
|
|
|
|
#include "persfilepath_opt.h"
|
|
|
|
#include "preference_utils.h"
|
|
|
|
#include "recent.h"
|
2016-06-19 02:33:13 -04:00
|
|
|
#include "decode_as_utils.h"
|
2016-06-18 16:49:23 -04:00
|
|
|
|
|
|
|
#include "../file.h"
|
|
|
|
|
2024-11-30 15:39:04 -08:00
|
|
|
#include "ui/capture_opts.h"
|
2016-10-30 14:07:33 -07:00
|
|
|
#include "ui/dissect_opts.h"
|
2016-06-18 16:49:23 -04:00
|
|
|
#include "ui/commandline.h"
|
|
|
|
|
2025-02-18 13:21:59 -08:00
|
|
|
#include <wsutil/application_flavor.h>
|
|
|
|
|
2025-05-16 06:36:13 -04:00
|
|
|
|
|
|
|
/* Command-line options that don't have direct API calls to handle the data */
|
|
|
|
typedef struct commandline_param_info
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
bool list_link_layer_types;
|
|
|
|
bool list_timestamp_types;
|
|
|
|
bool start_capture;
|
|
|
|
bool quit_after_cap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We currently don't support this as a way to add file comments
|
|
|
|
* to an existing capture file in Wireshark; we only support it
|
|
|
|
* for adding comments to live captures.
|
|
|
|
*/
|
|
|
|
GPtrArray* capture_comments;
|
|
|
|
#endif
|
|
|
|
search_direction jump_backwards;
|
|
|
|
uint32_t go_to_packet;
|
|
|
|
char* jfilter;
|
|
|
|
char* cf_name;
|
|
|
|
char* rfilter;
|
|
|
|
char* dfilter;
|
|
|
|
bool full_screen;
|
|
|
|
GSList* user_opts;
|
|
|
|
|
|
|
|
} commandline_param_info_t;
|
|
|
|
|
|
|
|
static commandline_param_info_t commandline_info;
|
2016-06-27 19:58:21 -07:00
|
|
|
|
2016-06-18 16:49:23 -04:00
|
|
|
capture_options global_capture_opts;
|
|
|
|
|
2024-11-17 02:52:07 -08:00
|
|
|
static void
|
2024-03-29 18:08:09 -07:00
|
|
|
commandline_print_usage(bool for_help_option) {
|
2016-06-18 16:49:23 -04:00
|
|
|
FILE *output;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
create_console();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (for_help_option) {
|
2025-02-18 13:21:59 -08:00
|
|
|
if (application_flavor_is_wireshark()) {
|
|
|
|
show_help_header("Interactively dump and analyze network traffic.");
|
|
|
|
} else {
|
|
|
|
show_help_header("Interactively dump and analyze system calls and log messages.");
|
|
|
|
}
|
2016-06-18 16:49:23 -04:00
|
|
|
output = stdout;
|
|
|
|
} else {
|
|
|
|
output = stderr;
|
|
|
|
}
|
|
|
|
fprintf(output, "\n");
|
2024-11-28 23:07:03 -08:00
|
|
|
fprintf(output, "Usage: %s [options] ... [ <infile> ]\n", g_get_prgname());
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, "\n");
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-02-18 13:21:59 -08:00
|
|
|
if (application_flavor_is_wireshark()) {
|
|
|
|
fprintf(output, "Capture interface:\n");
|
|
|
|
fprintf(output, " -i <interface>, --interface <interface>\n");
|
|
|
|
fprintf(output, " name or idx of interface (def: first non-loopback)\n");
|
|
|
|
fprintf(output, " -f <capture filter> packet filter in libpcap filter syntax\n");
|
|
|
|
} else {
|
|
|
|
fprintf(output, "Capture source:\n");
|
|
|
|
fprintf(output, " -i <source>, --source <source>\n");
|
|
|
|
fprintf(output, " name or idx of source (def: first source listed by -D or --list-sources)\n");
|
|
|
|
fprintf(output, " -f <capture filter> filter in libsinsp/libscap filter syntax\n");
|
|
|
|
}
|
|
|
|
if (application_flavor_is_wireshark()) {
|
|
|
|
fprintf(output, " -s <snaplen>, --snapshot-length <snaplen>\n");
|
|
|
|
fprintf(output, " packet snapshot length (def: appropriate maximum)\n");
|
|
|
|
fprintf(output, " -p, --no-promiscuous-mode\n");
|
|
|
|
fprintf(output, " don't capture in promiscuous mode\n");
|
|
|
|
fprintf(output, " -I, --monitor-mode capture in monitor mode, if available\n");
|
|
|
|
fprintf(output, " -B <buffer size>, --buffer-size <buffer size>\n");
|
|
|
|
fprintf(output, " size of kernel buffer in MiB (def: %dMiB)\n", DEFAULT_CAPTURE_BUFFER_SIZE);
|
|
|
|
}
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -y <link type>, --linktype <link type>\n");
|
|
|
|
fprintf(output, " link layer type (def: first appropriate)\n");
|
2017-08-07 16:38:52 +02:00
|
|
|
fprintf(output, " --time-stamp-type <type> timestamp method for interface\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
if (application_flavor_is_wireshark()) {
|
|
|
|
fprintf(output, " -D, --list-interfaces print list of interfaces and exit\n");
|
|
|
|
} else {
|
|
|
|
fprintf(output, " -D, --list-sources print list of sources and exit\n");
|
|
|
|
}
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -L, --list-data-link-types\n");
|
|
|
|
fprintf(output, " print list of link-layer types of iface and exit\n");
|
2017-08-07 16:38:52 +02:00
|
|
|
fprintf(output, " --list-time-stamp-types print list of timestamp types for iface and exit\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, "\n");
|
2023-03-08 22:15:21 -05:00
|
|
|
fprintf(output, "Capture display:\n");
|
|
|
|
fprintf(output, " -k start capturing immediately (def: do nothing)\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " -S update display when new items are captured\n");
|
2023-03-08 22:15:21 -05:00
|
|
|
fprintf(output, " -l turn on automatic scrolling while -S is in use\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " --update-interval interval between updates with new items, in milliseconds (def: %dms)\n", DEFAULT_UPDATE_INTERVAL);
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, "Capture stop conditions:\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " -c <item count> stop after n items (def: infinite)\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -a <autostop cond.> ..., --autostop <autostop cond.> ...\n");
|
|
|
|
fprintf(output, " duration:NUM - stop after NUM seconds\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " filesize:NUM - stop this file after NUM KB\n");
|
|
|
|
fprintf(output, " files:NUM - stop after NUM files\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
if (application_flavor_is_wireshark()) {
|
|
|
|
fprintf(output, " packets:NUM - stop after NUM packets\n");
|
|
|
|
} else {
|
|
|
|
fprintf(output, " events:NUM - stop after NUM packets\n");
|
|
|
|
}
|
2016-06-18 16:49:23 -04:00
|
|
|
/*fprintf(output, "\n");*/
|
2025-02-18 13:21:59 -08:00
|
|
|
// XXX libscap and libsinsp don't support this, so we should probably omit this if our flavor is Stratoshark.
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, "Capture output:\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -b <ringbuffer opt.> ..., --ring-buffer <ringbuffer opt.>\n");
|
|
|
|
fprintf(output, " duration:NUM - switch to next file after NUM secs\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " filesize:NUM - switch to next file after NUM KB\n");
|
|
|
|
fprintf(output, " files:NUM - ringbuffer: replace after NUM files\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
if (application_flavor_is_wireshark()) {
|
|
|
|
fprintf(output, " packets:NUM - switch to next file after NUM packets\n");
|
|
|
|
} else {
|
|
|
|
fprintf(output, " events:NUM - switch to next file after NUM events\n");
|
|
|
|
}
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " interval:NUM - switch to next file when the time is\n");
|
|
|
|
fprintf(output, " an exact multiple of NUM secs\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif /* HAVE_LIBPCAP */
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
fprintf(output, "RPCAP options:\n");
|
|
|
|
fprintf(output, " -A <user>:<password> use RPCAP password authentication\n");
|
|
|
|
#endif
|
|
|
|
/*fprintf(output, "\n");*/
|
|
|
|
fprintf(output, "Input file:\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -r <infile>, --read-file <infile>\n");
|
|
|
|
fprintf(output, " set the filename to read from (no pipes or stdin!)\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
|
|
|
|
fprintf(output, "\n");
|
|
|
|
fprintf(output, "Processing:\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -R <read filter>, --read-filter <read filter>\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " filter in display filter (wireshark-filter(4)) syntax\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " -n disable all name resolutions (def: all enabled)\n");
|
2024-06-10 23:43:43 +00:00
|
|
|
// Note: the order of the flags here matches the options in the settings dialog e.g. "dsN" only have an effect if "n" is set
|
|
|
|
fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mtndsNvg\"\n");
|
2016-06-19 02:33:13 -04:00
|
|
|
fprintf(output, " -d %s ...\n", DECODE_AS_ARG_TEMPLATE);
|
|
|
|
fprintf(output, " \"Decode As\", see the man page for details\n");
|
|
|
|
fprintf(output, " Example: tcp.port==8888,http\n");
|
2017-04-16 20:47:34 -07:00
|
|
|
fprintf(output, " --enable-protocol <proto_name>\n");
|
|
|
|
fprintf(output, " enable dissection of proto_name\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " --disable-protocol <proto_name>\n");
|
|
|
|
fprintf(output, " disable dissection of proto_name\n");
|
2024-11-29 14:44:46 -08:00
|
|
|
fprintf(output, " --only-protocols <protocols>\n");
|
Add --only-protocols and --disable-all-protocols to tshark and rawshark.
--disable-all-protocols will mark all protocols as disabled by default,
and then disable them. Certain protocols can then be enabled one by one
by using --enable-protocol.
--only-protocols is a helper option to make it easier to enable only
certain protocols It's equivalent to passing --disable-all-protocols and
then several --enable-protocol options. It accepts a comma separated
list of protocols. First all protocols will be disabled, and then all
protocols included in the list will be enabled one by one.
Side-note, it wouldn't make much sense to enable only "tcp" for example
without enabling the protocols in the lower layers (e.g: eth, sll, ip,
ipv6). In this case, something like --only-protocols eth,sll,ip,ipv6,tcp
will generally be needed in order to make sure that TCP is decoded.
Signed-off-by: Juanma Sanchez <juasanch@redhat.com>
2023-05-30 14:38:23 +02:00
|
|
|
fprintf(output, " Only enable dissection of these protocols, comma\n");
|
|
|
|
fprintf(output, " separated. Disable everything else\n");
|
|
|
|
fprintf(output, " --disable-all-protocols\n");
|
|
|
|
fprintf(output, " Disable dissection of all protocols\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " --enable-heuristic <short_name>\n");
|
|
|
|
fprintf(output, " enable dissection of heuristic protocol\n");
|
|
|
|
fprintf(output, " --disable-heuristic <short_name>\n");
|
|
|
|
fprintf(output, " disable dissection of heuristic protocol\n");
|
|
|
|
|
|
|
|
fprintf(output, "\n");
|
|
|
|
fprintf(output, "User interface:\n");
|
|
|
|
fprintf(output, " -C <config profile> start with specified configuration profile\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " -H hide the capture info dialog during capture\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -Y <display filter>, --display-filter <display filter>\n");
|
2019-11-05 13:49:17 +00:00
|
|
|
fprintf(output, " start with the given display filter\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " -g <item number> go to specified item number after \"-r\"\n");
|
|
|
|
fprintf(output, " -J <jump filter> jump to the first item matching the display\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " filter\n");
|
2025-02-18 13:21:59 -08:00
|
|
|
fprintf(output, " -j search backwards for a matching item after \"-J\"\n");
|
2023-03-10 19:58:17 +01:00
|
|
|
fprintf(output, " -t (a|ad|adoy|d|dd|e|r|u|ud|udoy)[.[N]]|.[N]\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " format of time stamps (def: r: rel. to first)\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " -u s|hms output format of seconds (def: s: seconds)\n");
|
|
|
|
fprintf(output, " -X <key>:<value> eXtension options, see man page for details\n");
|
|
|
|
fprintf(output, " -z <statistics> show various statistics, see man page for details\n");
|
|
|
|
|
|
|
|
fprintf(output, "\n");
|
|
|
|
fprintf(output, "Output:\n");
|
|
|
|
fprintf(output, " -w <outfile|-> set the output filename (or '-' for stdout)\n");
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2024-06-06 10:56:10 -04:00
|
|
|
fprintf(output, " -F <capture type> set the output file type; default is pcapng.\n");
|
|
|
|
fprintf(output, " an empty \"-F\" option will list the file types.\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " --capture-comment <comment>\n");
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
fprintf(output, " add a capture file comment, if supported\n");
|
|
|
|
#endif
|
2022-02-09 14:32:28 +00:00
|
|
|
fprintf(output, " --temp-dir <directory> write temporary files to this directory\n");
|
|
|
|
fprintf(output, " (default: %s)\n", g_get_tmp_dir());
|
|
|
|
fprintf(output, "\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
|
2021-06-15 22:50:46 +01:00
|
|
|
ws_log_print_usage(output);
|
|
|
|
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, "\n");
|
|
|
|
fprintf(output, "Miscellaneous:\n");
|
2019-11-10 23:33:52 +01:00
|
|
|
fprintf(output, " -h, --help display this help and exit\n");
|
|
|
|
fprintf(output, " -v, --version display version info and exit\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
fprintf(output, " -P <key>:<path> persconf:path - personal configuration files\n");
|
|
|
|
fprintf(output, " persdata:path - personal data files\n");
|
|
|
|
fprintf(output, " -o <name>:<value> ... override preference or recent setting\n");
|
|
|
|
fprintf(output, " -K <keytab> keytab file to use for kerberos decryption\n");
|
|
|
|
#ifndef _WIN32
|
2019-11-05 13:49:17 +00:00
|
|
|
fprintf(output, " --display <X display> X display to use\n");
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif
|
2024-11-21 09:45:22 -08:00
|
|
|
fprintf(output, " --fullscreen start %s in full screen\n", application_flavor_name_proper());
|
2016-06-18 16:49:23 -04:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
destroy_console();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-12-15 14:15:34 +01:00
|
|
|
#define LONGOPT_FULL_SCREEN LONGOPT_BASE_GUI+1
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
#define LONGOPT_CAPTURE_COMMENT LONGOPT_BASE_GUI+2
|
2016-10-24 02:19:50 -07:00
|
|
|
|
2023-10-12 09:23:53 -04:00
|
|
|
#define OPTSTRING OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON OPTSTRING_READ_CAPTURE_COMMON "C:g:HhjJ:klm:o:P:Svw:X:z:"
|
2021-09-29 18:32:28 +01:00
|
|
|
static const struct ws_option long_options[] = {
|
|
|
|
{"help", ws_no_argument, NULL, 'h'},
|
|
|
|
{"version", ws_no_argument, NULL, 'v'},
|
|
|
|
{"fullscreen", ws_no_argument, NULL, LONGOPT_FULL_SCREEN },
|
|
|
|
{"capture-comment", ws_required_argument, NULL, LONGOPT_CAPTURE_COMMENT},
|
2016-06-18 16:49:23 -04:00
|
|
|
LONGOPT_CAPTURE_COMMON
|
2016-10-30 14:07:33 -07:00
|
|
|
LONGOPT_DISSECT_COMMON
|
2023-10-12 09:23:53 -04:00
|
|
|
LONGOPT_READ_CAPTURE_COMMON
|
2025-04-28 13:30:46 +00:00
|
|
|
LONGOPT_WSLOG
|
2016-06-18 16:49:23 -04:00
|
|
|
{0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
static const char optstring[] = OPTSTRING;
|
|
|
|
|
2025-04-28 13:30:46 +00:00
|
|
|
|
|
|
|
const struct ws_option* commandline_long_options(void)
|
|
|
|
{
|
|
|
|
return long_options;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* commandline_optstring(void)
|
|
|
|
{
|
|
|
|
return optstring;
|
|
|
|
}
|
|
|
|
|
2016-06-19 13:21:17 -07:00
|
|
|
#ifndef HAVE_LIBPCAP
|
|
|
|
static void print_no_capture_support_error(void)
|
|
|
|
{
|
2024-11-21 09:45:22 -08:00
|
|
|
cmdarg_err("This version of %s was not built with support for capturing packets.", application_flavor_name_proper());
|
2016-06-19 13:21:17 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2025-04-21 12:10:32 -04:00
|
|
|
int commandline_early_options(int argc, char *argv[])
|
2016-06-18 16:49:23 -04:00
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2016-06-19 00:49:42 -07:00
|
|
|
int err;
|
2016-06-18 16:49:23 -04:00
|
|
|
GList *if_list;
|
2024-03-29 18:08:09 -07:00
|
|
|
char *err_str;
|
2023-08-27 14:31:36 -07:00
|
|
|
int exit_status;
|
2016-06-19 13:21:17 -07:00
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
bool capture_option_specified;
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to have the -X opts assigned before the wslua machine starts
|
|
|
|
* we need to call getopt_long before epan_init() gets called.
|
|
|
|
*
|
|
|
|
* In addition, we process "console only" parameters (ones where we
|
|
|
|
* send output to the console and exit) here, so we don't start GUI
|
|
|
|
* if we're only showing command-line help or version information.
|
|
|
|
*
|
|
|
|
* XXX - this pre-scan is done before we start GUI, so we haven't
|
|
|
|
* run "GUI init function" on the arguments. That means that GUI-specific
|
|
|
|
* arguments have not been removed from the argument list; those arguments
|
|
|
|
* begin with "--", and will be treated as an error by getopt_long().
|
|
|
|
*
|
2021-07-26 17:22:36 +01:00
|
|
|
* We thus ignore errors - *and* set "ws_opterr" to 0 to suppress the
|
2016-06-18 16:49:23 -04:00
|
|
|
* error messages.
|
|
|
|
*
|
|
|
|
* In order to handle, for example, -o options, we also need to call it
|
|
|
|
* *after* epan_init() gets called, so that the dissectors have had a
|
|
|
|
* chance to register their preferences, so we have another getopt_long()
|
|
|
|
* call later.
|
|
|
|
*
|
|
|
|
* XXX - can we do this all with one getopt_long() call, saving the
|
|
|
|
* arguments we can't handle until after initializing libwireshark,
|
|
|
|
* and then process them after initializing libwireshark?
|
|
|
|
*
|
|
|
|
* Note that we don't want to initialize libwireshark until after the
|
|
|
|
* GUI is up, as that can take a while, and we want a window of some
|
|
|
|
* sort up to show progress while that's happening.
|
|
|
|
*/
|
2021-07-26 17:22:36 +01:00
|
|
|
ws_opterr = 0;
|
2016-06-18 16:49:23 -04:00
|
|
|
|
2016-06-19 09:29:21 -07:00
|
|
|
#ifndef HAVE_LIBPCAP
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = false;
|
2016-06-19 09:29:21 -07:00
|
|
|
#endif
|
2021-07-26 17:22:36 +01:00
|
|
|
while ((opt = ws_getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
2016-06-18 16:49:23 -04:00
|
|
|
switch (opt) {
|
|
|
|
case 'C': /* Configuration Profile */
|
2024-03-29 18:08:09 -07:00
|
|
|
if (profile_exists (ws_optarg, false)) {
|
2021-07-26 17:22:36 +01:00
|
|
|
set_profile_name (ws_optarg);
|
2024-03-29 18:08:09 -07:00
|
|
|
} else if (profile_exists (ws_optarg, true)) {
|
2022-07-05 22:06:09 -04:00
|
|
|
char *pf_dir_path, *pf_dir_path2, *pf_filename;
|
|
|
|
/* Copy from global profile */
|
|
|
|
if (create_persconffile_profile(ws_optarg, &pf_dir_path) == -1) {
|
|
|
|
cmdarg_err("Can't create directory\n\"%s\":\n%s.",
|
|
|
|
pf_dir_path, g_strerror(errno));
|
|
|
|
|
|
|
|
g_free(pf_dir_path);
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_INVALID_FILE;
|
2022-07-05 22:06:09 -04:00
|
|
|
}
|
2024-03-29 18:08:09 -07:00
|
|
|
if (copy_persconffile_profile(ws_optarg, ws_optarg, true, &pf_filename,
|
2022-07-05 22:06:09 -04:00
|
|
|
&pf_dir_path, &pf_dir_path2) == -1) {
|
|
|
|
cmdarg_err("Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.",
|
|
|
|
pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno));
|
|
|
|
|
|
|
|
g_free(pf_filename);
|
|
|
|
g_free(pf_dir_path);
|
|
|
|
g_free(pf_dir_path2);
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_INVALID_FILE;
|
2022-07-05 22:06:09 -04:00
|
|
|
}
|
|
|
|
set_profile_name (ws_optarg);
|
2016-06-18 16:49:23 -04:00
|
|
|
} else {
|
2021-07-26 17:22:36 +01:00
|
|
|
cmdarg_err("Configuration Profile \"%s\" does not exist", ws_optarg);
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_INVALID_OPTION;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'D': /* Print a list of capture devices and exit */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-04-21 12:10:32 -04:00
|
|
|
exit_status = WS_EXIT_NOW;
|
2016-06-18 16:49:23 -04:00
|
|
|
if_list = capture_interface_list(&err, &err_str, NULL);
|
2023-08-27 14:31:36 -07:00
|
|
|
if (err != 0) {
|
|
|
|
/*
|
|
|
|
* An error occurred when fetching the local
|
|
|
|
* interfaces. Report it.
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
|
|
|
create_console();
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
cmdarg_err("%s", err_str);
|
|
|
|
g_free(err_str);
|
|
|
|
exit_status = WS_EXIT_PCAP_ERROR;
|
|
|
|
}
|
2016-06-18 16:49:23 -04:00
|
|
|
if (if_list == NULL) {
|
2023-08-27 14:31:36 -07:00
|
|
|
/*
|
|
|
|
* No interfaces were found. If that's not the
|
|
|
|
* result of an error when fetching the local
|
|
|
|
* interfaces, let the user know.
|
|
|
|
*/
|
|
|
|
if (err == 0) {
|
2016-06-18 16:49:23 -04:00
|
|
|
cmdarg_err("There are no interfaces on which a capture can be done");
|
2023-08-27 14:31:36 -07:00
|
|
|
exit_status = WS_EXIT_NO_INTERFACES;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
2025-04-21 12:10:32 -04:00
|
|
|
return exit_status;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
|
|
create_console();
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
capture_opts_print_interfaces(if_list);
|
|
|
|
free_interface_list(if_list);
|
|
|
|
#ifdef _WIN32
|
|
|
|
destroy_console();
|
|
|
|
#endif /* _WIN32 */
|
2025-04-21 12:10:32 -04:00
|
|
|
return exit_status;
|
2016-06-18 16:49:23 -04:00
|
|
|
#else /* HAVE_LIBPCAP */
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif /* HAVE_LIBPCAP */
|
|
|
|
break;
|
|
|
|
case 'h': /* Print help and exit */
|
2024-03-29 18:08:09 -07:00
|
|
|
commandline_print_usage(true);
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_NOW;
|
2016-06-18 16:49:23 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
case 'i':
|
2021-07-26 17:22:36 +01:00
|
|
|
if (strcmp(ws_optarg, "-") == 0)
|
2024-03-29 18:08:09 -07:00
|
|
|
set_stdin_capture(true);
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'P': /* Personal file directory path settings - change these before the Preferences and alike are processed */
|
2021-07-26 17:22:36 +01:00
|
|
|
if (!persfilepath_opt(opt, ws_optarg)) {
|
|
|
|
cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", ws_optarg);
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_NOW;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v': /* Show version and exit */
|
|
|
|
#ifdef _WIN32
|
|
|
|
create_console();
|
|
|
|
#endif
|
2018-12-12 18:16:15 -08:00
|
|
|
show_version();
|
2016-06-18 16:49:23 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
destroy_console();
|
|
|
|
#endif
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_NOW;
|
2016-06-18 16:49:23 -04:00
|
|
|
case 'X':
|
|
|
|
/*
|
|
|
|
* Extension command line options have to be processed before
|
|
|
|
* we call epan_init() as they are supposed to be used by dissectors
|
|
|
|
* or taps very early in the registration process.
|
|
|
|
*/
|
2021-07-26 17:22:36 +01:00
|
|
|
ex_opt_add(ws_optarg);
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
case '?': /* Ignore errors - the "real" scan will catch them. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-06-19 13:21:17 -07:00
|
|
|
|
2021-03-10 08:22:53 -05:00
|
|
|
#ifndef HAVE_LUA
|
|
|
|
if (ex_opt_count("lua_script") > 0) {
|
2024-11-21 09:45:22 -08:00
|
|
|
cmdarg_err("This version of %s was not built with support for Lua scripting.", application_flavor_name_proper());
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_INVALID_OPTION;
|
2021-03-10 08:22:53 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-19 13:21:17 -07:00
|
|
|
#ifndef HAVE_LIBPCAP
|
|
|
|
if (capture_option_specified) {
|
|
|
|
print_no_capture_support_error();
|
2024-03-29 18:08:09 -07:00
|
|
|
commandline_print_usage(false);
|
2025-04-21 12:10:32 -04:00
|
|
|
return WS_EXIT_NOW;
|
2016-06-19 13:21:17 -07:00
|
|
|
}
|
|
|
|
#endif
|
2025-04-21 12:10:32 -04:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
|
2024-03-29 18:08:09 -07:00
|
|
|
void commandline_override_prefs(int argc, char *argv[], bool opt_reset)
|
Fix overriding capture option prefs at the command line
Some capture options can be overridden with command line arguments.
We want those options, like -p, -n/-P, -H, -S, and --update-interval,
to take precedence over preferences, at least until the user saves
preferences or switches profiles (at which point the new settings
will be applied.) That means we have to apply preferences to capture
options before we read most command line arguments.
However, preferences can be altered at the command line, including
the preferences that affect the capture options. So we have to
read the command line arguments that alter preferences after
reading preferences (which has to be after reading command line
arguments that control what preferences are read, like the
configuration profile), but before applying preferences to the
capture options.
Add a new "process some command line options" function that only
gets the command line options that override preferences. Final
interleaved command line / preference / capture options sequence:
1. Read command line arguments that affect what preferences to read
2. Initialize capture options to default value
3. Read preferences
4. Read command line arguments that affect value of already read
preferences
5. Apply preferences to capture options
6. Read other command line arguments, set capture options final values
7. Apply other preferences
Fix #14549
2023-11-15 21:12:47 -05:00
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To reset the options parser, set ws_optreset to 1 and set ws_optind to 1.
|
|
|
|
*
|
|
|
|
* Ignore errors and keep ws_opterr as 0; error messages will be printed
|
|
|
|
* later by command_other_options()
|
|
|
|
*/
|
|
|
|
if (opt_reset) {
|
|
|
|
ws_optreset = 1;
|
|
|
|
ws_optind = 1;
|
|
|
|
ws_opterr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize with default values */
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.user_opts = NULL;
|
Fix overriding capture option prefs at the command line
Some capture options can be overridden with command line arguments.
We want those options, like -p, -n/-P, -H, -S, and --update-interval,
to take precedence over preferences, at least until the user saves
preferences or switches profiles (at which point the new settings
will be applied.) That means we have to apply preferences to capture
options before we read most command line arguments.
However, preferences can be altered at the command line, including
the preferences that affect the capture options. So we have to
read the command line arguments that alter preferences after
reading preferences (which has to be after reading command line
arguments that control what preferences are read, like the
configuration profile), but before applying preferences to the
capture options.
Add a new "process some command line options" function that only
gets the command line options that override preferences. Final
interleaved command line / preference / capture options sequence:
1. Read command line arguments that affect what preferences to read
2. Initialize capture options to default value
3. Read preferences
4. Read command line arguments that affect value of already read
preferences
5. Apply preferences to capture options
6. Read other command line arguments, set capture options final values
7. Apply other preferences
Fix #14549
2023-11-15 21:12:47 -05:00
|
|
|
|
|
|
|
while ((opt = ws_getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'o': /* Override preference from command line */
|
|
|
|
{
|
|
|
|
char *errmsg = NULL;
|
|
|
|
|
|
|
|
switch (prefs_set_pref(ws_optarg, &errmsg)) {
|
|
|
|
case PREFS_SET_OK:
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.user_opts =
|
|
|
|
g_slist_prepend(commandline_info.user_opts,
|
Fix overriding capture option prefs at the command line
Some capture options can be overridden with command line arguments.
We want those options, like -p, -n/-P, -H, -S, and --update-interval,
to take precedence over preferences, at least until the user saves
preferences or switches profiles (at which point the new settings
will be applied.) That means we have to apply preferences to capture
options before we read most command line arguments.
However, preferences can be altered at the command line, including
the preferences that affect the capture options. So we have to
read the command line arguments that alter preferences after
reading preferences (which has to be after reading command line
arguments that control what preferences are read, like the
configuration profile), but before applying preferences to the
capture options.
Add a new "process some command line options" function that only
gets the command line options that override preferences. Final
interleaved command line / preference / capture options sequence:
1. Read command line arguments that affect what preferences to read
2. Initialize capture options to default value
3. Read preferences
4. Read command line arguments that affect value of already read
preferences
5. Apply preferences to capture options
6. Read other command line arguments, set capture options final values
7. Apply other preferences
Fix #14549
2023-11-15 21:12:47 -05:00
|
|
|
g_strdup(ws_optarg));
|
|
|
|
break;
|
|
|
|
case PREFS_SET_SYNTAX_ERR:
|
|
|
|
cmdarg_err("Invalid -o flag \"%s\"%s%s", ws_optarg,
|
|
|
|
errmsg ? ": " : "", errmsg ? errmsg : "");
|
|
|
|
g_free(errmsg);
|
|
|
|
exit_application(1);
|
|
|
|
break;
|
|
|
|
case PREFS_SET_NO_SUCH_PREF:
|
|
|
|
/* not a preference, might be a recent setting */
|
|
|
|
switch (recent_set_arg(ws_optarg)) {
|
|
|
|
case PREFS_SET_OK:
|
|
|
|
break;
|
|
|
|
case PREFS_SET_SYNTAX_ERR:
|
|
|
|
/* shouldn't happen, checked already above */
|
|
|
|
cmdarg_err("Invalid -o flag \"%s\"", ws_optarg);
|
|
|
|
exit_application(1);
|
|
|
|
break;
|
|
|
|
case PREFS_SET_NO_SUCH_PREF:
|
|
|
|
case PREFS_SET_OBSOLETE:
|
|
|
|
cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
|
|
|
|
ws_optarg);
|
|
|
|
exit_application(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ws_assert_not_reached();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PREFS_SET_OBSOLETE:
|
2024-01-19 14:53:34 +13:00
|
|
|
/* obsolete preference, might be a recent setting */
|
|
|
|
if (recent_set_arg(ws_optarg) != PREFS_SET_OK) {
|
|
|
|
cmdarg_err("-o flag \"%s\" specifies obsolete preference",
|
|
|
|
ws_optarg);
|
|
|
|
exit_application(1);
|
|
|
|
}
|
Fix overriding capture option prefs at the command line
Some capture options can be overridden with command line arguments.
We want those options, like -p, -n/-P, -H, -S, and --update-interval,
to take precedence over preferences, at least until the user saves
preferences or switches profiles (at which point the new settings
will be applied.) That means we have to apply preferences to capture
options before we read most command line arguments.
However, preferences can be altered at the command line, including
the preferences that affect the capture options. So we have to
read the command line arguments that alter preferences after
reading preferences (which has to be after reading command line
arguments that control what preferences are read, like the
configuration profile), but before applying preferences to the
capture options.
Add a new "process some command line options" function that only
gets the command line options that override preferences. Final
interleaved command line / preference / capture options sequence:
1. Read command line arguments that affect what preferences to read
2. Initialize capture options to default value
3. Read preferences
4. Read command line arguments that affect value of already read
preferences
5. Apply preferences to capture options
6. Read other command line arguments, set capture options final values
7. Apply other preferences
Fix #14549
2023-11-15 21:12:47 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ws_assert_not_reached();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
case '?': /* Ignore errors - the "real" scan will catch them. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since we prepended each option when processing `-o`, reverse the list
|
|
|
|
* in case the order of options becomes meaningful.
|
|
|
|
*/
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.user_opts = g_slist_reverse(commandline_info.user_opts);
|
Fix overriding capture option prefs at the command line
Some capture options can be overridden with command line arguments.
We want those options, like -p, -n/-P, -H, -S, and --update-interval,
to take precedence over preferences, at least until the user saves
preferences or switches profiles (at which point the new settings
will be applied.) That means we have to apply preferences to capture
options before we read most command line arguments.
However, preferences can be altered at the command line, including
the preferences that affect the capture options. So we have to
read the command line arguments that alter preferences after
reading preferences (which has to be after reading command line
arguments that control what preferences are read, like the
configuration profile), but before applying preferences to the
capture options.
Add a new "process some command line options" function that only
gets the command line options that override preferences. Final
interleaved command line / preference / capture options sequence:
1. Read command line arguments that affect what preferences to read
2. Initialize capture options to default value
3. Read preferences
4. Read command line arguments that affect value of already read
preferences
5. Apply preferences to capture options
6. Read other command line arguments, set capture options final values
7. Apply other preferences
Fix #14549
2023-11-15 21:12:47 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-29 18:08:09 -07:00
|
|
|
void commandline_other_options(int argc, char *argv[], bool opt_reset)
|
2016-06-18 16:49:23 -04:00
|
|
|
{
|
|
|
|
int opt;
|
2024-03-29 18:08:09 -07:00
|
|
|
bool arg_error = false;
|
2016-06-18 16:49:23 -04:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2017-08-22 16:09:48 +02:00
|
|
|
const char *list_option_supplied = NULL;
|
2016-06-18 16:49:23 -04:00
|
|
|
int status;
|
2016-06-19 13:21:17 -07:00
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
bool capture_option_specified;
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2021-07-26 17:22:36 +01:00
|
|
|
* To reset the options parser, set ws_optreset to 1 and set ws_optind to 1.
|
2016-06-18 16:49:23 -04:00
|
|
|
*
|
2021-07-26 17:22:36 +01:00
|
|
|
* Also reset ws_opterr to 1, so that error messages are printed by
|
2016-06-18 16:49:23 -04:00
|
|
|
* getopt_long().
|
|
|
|
*
|
|
|
|
* XXX - if we want to control all the command-line option errors, so
|
|
|
|
* that we can display them where we choose (e.g., in a window), we'd
|
2021-07-26 17:22:36 +01:00
|
|
|
* want to leave ws_opterr as 0, and produce our own messages using ws_optopt.
|
|
|
|
* We'd have to check the value of ws_optopt to see if it's a valid option
|
2016-06-18 16:49:23 -04:00
|
|
|
* letter, in which case *presumably* the error is "this option requires
|
|
|
|
* an argument but none was specified", or not a valid option letter,
|
|
|
|
* in which case *presumably* the error is "this option isn't valid".
|
|
|
|
* Some versions of getopt() let you supply a option string beginning
|
|
|
|
* with ':', which means that getopt() will return ':' rather than '?'
|
|
|
|
* for "this option requires an argument but none was specified", but
|
|
|
|
* not all do. But we're now using getopt_long() - what does it do?
|
|
|
|
*/
|
|
|
|
if (opt_reset) {
|
2021-07-26 17:22:36 +01:00
|
|
|
ws_optreset = 1;
|
|
|
|
ws_optind = 1;
|
|
|
|
ws_opterr = 1;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
|
2016-06-19 23:54:33 -07:00
|
|
|
/* Initialize with default values */
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.jump_backwards = SD_FORWARD;
|
|
|
|
commandline_info.go_to_packet = 0;
|
|
|
|
commandline_info.jfilter = NULL;
|
|
|
|
commandline_info.cf_name = NULL;
|
|
|
|
commandline_info.rfilter = NULL;
|
|
|
|
commandline_info.dfilter = NULL;
|
2016-06-19 23:54:33 -07:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.start_capture = false;
|
|
|
|
commandline_info.list_link_layer_types = false;
|
|
|
|
commandline_info.list_timestamp_types = false;
|
|
|
|
commandline_info.quit_after_cap = getenv("WIRESHARK_QUIT_AFTER_CAPTURE") ? true : false;
|
|
|
|
commandline_info.capture_comments = NULL;
|
2016-06-27 18:56:29 -07:00
|
|
|
#endif
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.full_screen = false;
|
2016-06-19 23:54:33 -07:00
|
|
|
|
2021-07-26 17:22:36 +01:00
|
|
|
while ((opt = ws_getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
2016-06-18 16:49:23 -04:00
|
|
|
switch (opt) {
|
|
|
|
/*** capture option specific ***/
|
|
|
|
case 'a': /* autostop criteria */
|
|
|
|
case 'b': /* Ringbuffer option */
|
2025-02-18 13:21:59 -08:00
|
|
|
case 'c': /* Capture xxx items */
|
2016-06-18 16:49:23 -04:00
|
|
|
case 'f': /* capture filter */
|
2024-06-06 10:56:10 -04:00
|
|
|
case 'F': /* capture file type */
|
2016-06-18 16:49:23 -04:00
|
|
|
case 'H': /* Hide capture info dialog box */
|
|
|
|
case 'p': /* Don't capture in promiscuous mode */
|
|
|
|
case 'i': /* Use interface x */
|
2017-08-07 16:38:52 +02:00
|
|
|
case LONGOPT_SET_TSTAMP_TYPE: /* Set capture timestamp type */
|
2022-02-09 14:32:28 +00:00
|
|
|
case LONGOPT_CAPTURE_TMPDIR: /* capture temp directory */
|
2023-03-08 22:15:21 -05:00
|
|
|
case LONGOPT_UPDATE_INTERVAL: /* sync pipe update interval */
|
2016-06-18 16:49:23 -04:00
|
|
|
case 'I': /* Capture in monitor mode, if available */
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
case 'A': /* Authentication */
|
|
|
|
#endif
|
|
|
|
case 's': /* Set the snapshot (capture) length */
|
|
|
|
case 'S': /* "Sync" mode: used for following file ala tail -f */
|
|
|
|
case 'w': /* Write to capture file xxx */
|
|
|
|
case 'y': /* Set the pcap data link type */
|
|
|
|
case 'B': /* Buffer size */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2021-07-26 17:22:36 +01:00
|
|
|
status = capture_opts_add_opt(&global_capture_opts, opt, ws_optarg);
|
2016-06-18 16:49:23 -04:00
|
|
|
if(status != 0) {
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(status);
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
|
|
|
arg_error = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*** all non capture option specific ***/
|
|
|
|
case 'C':
|
|
|
|
/* Configuration profile settings were already processed just ignore them this time*/
|
|
|
|
break;
|
2025-02-18 13:21:59 -08:00
|
|
|
case 'j': /* Search backwards for a matching item from filter in option J */
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.jump_backwards = SD_BACKWARD;
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
2025-02-18 13:21:59 -08:00
|
|
|
case 'g': /* Go to item with the given item number */
|
2025-05-16 06:36:13 -04:00
|
|
|
if (!get_nonzero_uint32(ws_optarg, "go to packet", &commandline_info.go_to_packet))
|
2025-04-18 13:10:42 -04:00
|
|
|
exit_application(WS_EXIT_INVALID_OPTION);
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
2025-02-18 13:21:59 -08:00
|
|
|
case 'J': /* Jump to the first item which matches the filter criteria */
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.jfilter = ws_optarg;
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
2021-04-13 12:35:02 -07:00
|
|
|
case 'k': /* Start capture immediately */
|
2021-04-13 14:33:37 -07:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.start_capture = true;
|
2021-04-13 14:33:37 -07:00
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
|
|
|
arg_error = true;
|
2021-04-13 14:33:37 -07:00
|
|
|
#endif
|
2021-04-13 12:35:02 -07:00
|
|
|
break;
|
2016-06-18 16:49:23 -04:00
|
|
|
case 'l': /* Automatic scrolling in live capture mode */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2024-03-29 18:08:09 -07:00
|
|
|
recent.capture_auto_scroll = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
|
|
|
arg_error = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'L': /* Print list of link-layer types and exit */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.list_link_layer_types = true;
|
2017-08-07 16:38:52 +02:00
|
|
|
list_option_supplied = "-L";
|
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
|
|
|
arg_error = true;
|
2017-08-07 16:38:52 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case LONGOPT_LIST_TSTAMP_TYPES:
|
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.list_timestamp_types = true;
|
2017-08-07 16:38:52 +02:00
|
|
|
list_option_supplied = "--list-time-stamp-types";
|
2016-06-18 16:49:23 -04:00
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
|
|
|
arg_error = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'o': /* Override preference from command line */
|
Fix overriding capture option prefs at the command line
Some capture options can be overridden with command line arguments.
We want those options, like -p, -n/-P, -H, -S, and --update-interval,
to take precedence over preferences, at least until the user saves
preferences or switches profiles (at which point the new settings
will be applied.) That means we have to apply preferences to capture
options before we read most command line arguments.
However, preferences can be altered at the command line, including
the preferences that affect the capture options. So we have to
read the command line arguments that alter preferences after
reading preferences (which has to be after reading command line
arguments that control what preferences are read, like the
configuration profile), but before applying preferences to the
capture options.
Add a new "process some command line options" function that only
gets the command line options that override preferences. Final
interleaved command line / preference / capture options sequence:
1. Read command line arguments that affect what preferences to read
2. Initialize capture options to default value
3. Read preferences
4. Read command line arguments that affect value of already read
preferences
5. Apply preferences to capture options
6. Read other command line arguments, set capture options final values
7. Apply other preferences
Fix #14549
2023-11-15 21:12:47 -05:00
|
|
|
/* Pref overrides were already processed just ignore them this time*/
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
/* Path settings were already processed just ignore them this time*/
|
|
|
|
break;
|
|
|
|
case 'r': /* Read capture file xxx */
|
|
|
|
/* We may set "last_open_dir" to "cf_name", and if we change
|
|
|
|
"last_open_dir" later, we free the old value, so we have to
|
|
|
|
set "cf_name" to something that's been allocated. */
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.cf_name = g_strdup(ws_optarg);
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
case 'R': /* Read file filter */
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.rfilter = ws_optarg;
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
/* ext ops were already processed just ignore them this time*/
|
|
|
|
break;
|
|
|
|
case 'Y':
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.dfilter = ws_optarg;
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
/* We won't call the init function for the stat this soon
|
|
|
|
as it would disallow MATE's fields (which are registered
|
|
|
|
by the preferences set callback) from being used as
|
|
|
|
part of a tap filter. Instead, we just add the argument
|
|
|
|
to a list of stat arguments. */
|
2021-07-26 17:22:36 +01:00
|
|
|
if (strcmp("help", ws_optarg) == 0) {
|
2024-11-28 23:07:03 -08:00
|
|
|
fprintf(stderr, "%s: The available statistics for the \"-z\" option are:\n", g_get_prgname());
|
2024-11-15 18:24:14 -06:00
|
|
|
list_stat_cmd_args();
|
|
|
|
exit_application(0);
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
2021-07-26 17:22:36 +01:00
|
|
|
if (!process_stat_cmd_arg(ws_optarg)) {
|
2016-06-18 16:49:23 -04:00
|
|
|
cmdarg_err("Invalid -z argument.");
|
|
|
|
cmdarg_err_cont(" -z argument must be one of :");
|
|
|
|
list_stat_cmd_args();
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
break;
|
2016-10-30 14:07:33 -07:00
|
|
|
case 'd': /* Decode as rule */
|
2016-10-30 18:47:59 -07:00
|
|
|
case 'K': /* Kerberos keytab file */
|
|
|
|
case 'n': /* No name resolution */
|
|
|
|
case 'N': /* Select what types of addresses/port #s to resolve */
|
2016-10-30 14:07:33 -07:00
|
|
|
case 't': /* time stamp type */
|
2016-10-30 18:47:59 -07:00
|
|
|
case 'u': /* Seconds type */
|
2016-06-18 16:49:23 -04:00
|
|
|
case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */
|
|
|
|
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
|
|
|
|
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
|
2016-12-23 15:20:31 -05:00
|
|
|
case LONGOPT_ENABLE_PROTOCOL: /* enable dissection of protocol (that is disabled by default) */
|
Add --only-protocols and --disable-all-protocols to tshark and rawshark.
--disable-all-protocols will mark all protocols as disabled by default,
and then disable them. Certain protocols can then be enabled one by one
by using --enable-protocol.
--only-protocols is a helper option to make it easier to enable only
certain protocols It's equivalent to passing --disable-all-protocols and
then several --enable-protocol options. It accepts a comma separated
list of protocols. First all protocols will be disabled, and then all
protocols included in the list will be enabled one by one.
Side-note, it wouldn't make much sense to enable only "tcp" for example
without enabling the protocols in the lower layers (e.g: eth, sll, ip,
ipv6). In this case, something like --only-protocols eth,sll,ip,ipv6,tcp
will generally be needed in order to make sure that TCP is decoded.
Signed-off-by: Juanma Sanchez <juasanch@redhat.com>
2023-05-30 14:38:23 +02:00
|
|
|
case LONGOPT_ONLY_PROTOCOLS: /* enable dissection of these comma separated protocols only */
|
|
|
|
case LONGOPT_DISABLE_ALL_PROTOCOLS: /* disable dissection of all protocols */
|
2021-07-26 17:22:36 +01:00
|
|
|
if (!dissect_opts_handle_opt(opt, ws_optarg))
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
2016-10-19 20:53:40 +02:00
|
|
|
case LONGOPT_FULL_SCREEN:
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.full_screen = true;
|
2016-10-19 20:53:40 +02:00
|
|
|
break;
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
case LONGOPT_CAPTURE_COMMENT: /* capture comment */
|
2025-05-16 06:36:13 -04:00
|
|
|
if (commandline_info.capture_comments == NULL) {
|
|
|
|
commandline_info.capture_comments = g_ptr_array_new_with_free_func(g_free);
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
}
|
2025-05-16 06:36:13 -04:00
|
|
|
g_ptr_array_add(commandline_info.capture_comments, g_strdup(ws_optarg));
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
#else
|
2024-03-29 18:08:09 -07:00
|
|
|
capture_option_specified = true;
|
|
|
|
arg_error = true;
|
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-14 22:16:30 -07:00
|
|
|
#endif
|
|
|
|
break;
|
2016-06-18 16:49:23 -04:00
|
|
|
case '?': /* Bad flag - print usage message */
|
2025-04-29 14:00:41 -04:00
|
|
|
default:
|
|
|
|
/* wslog arguments are okay */
|
|
|
|
if (ws_log_is_wslog_arg(opt))
|
|
|
|
break;
|
|
|
|
|
2024-03-29 18:08:09 -07:00
|
|
|
arg_error = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 13:21:17 -07:00
|
|
|
if (!arg_error) {
|
2021-07-26 17:22:36 +01:00
|
|
|
argc -= ws_optind;
|
|
|
|
argv += ws_optind;
|
2016-06-18 16:49:23 -04:00
|
|
|
if (argc >= 1) {
|
2025-05-16 06:36:13 -04:00
|
|
|
if (commandline_info.cf_name != NULL) {
|
2016-06-18 16:49:23 -04:00
|
|
|
/*
|
|
|
|
* Input file name specified with "-r" *and* specified as a regular
|
|
|
|
* command-line argument.
|
|
|
|
*/
|
|
|
|
cmdarg_err("File name specified both with -r and regular argument");
|
2024-03-29 18:08:09 -07:00
|
|
|
arg_error = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Input file name not specified with "-r", and a command-line argument
|
|
|
|
* was specified; treat it as the input file name.
|
|
|
|
*
|
|
|
|
* Yes, this is different from tshark, where non-flag command-line
|
|
|
|
* arguments are a filter, but this works better on GUI desktops
|
|
|
|
* where a command can be specified to be run to open a particular
|
|
|
|
* file - yes, you could have "-r" as the last part of the command,
|
|
|
|
* but that's a bit ugly.
|
|
|
|
*/
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.cf_name = g_strdup(argv[0]);
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 0) {
|
|
|
|
/*
|
|
|
|
* Extra command line arguments were specified; complain.
|
|
|
|
*/
|
|
|
|
cmdarg_err("Invalid argument: %s", argv[0]);
|
2024-03-29 18:08:09 -07:00
|
|
|
arg_error = true;
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 13:21:17 -07:00
|
|
|
if (arg_error) {
|
2024-06-06 10:56:10 -04:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
if (ws_optopt == 'F') {
|
|
|
|
capture_opts_list_file_types();
|
|
|
|
exit_application(1);
|
|
|
|
}
|
|
|
|
#else
|
2016-06-19 13:21:17 -07:00
|
|
|
if (capture_option_specified) {
|
|
|
|
print_no_capture_support_error();
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
|
|
|
#endif
|
2024-03-29 18:08:09 -07:00
|
|
|
commandline_print_usage(false);
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
2016-06-19 16:36:57 -07:00
|
|
|
|
2016-06-19 17:42:14 -07:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2025-05-16 06:36:13 -04:00
|
|
|
if (commandline_info.start_capture && list_option_supplied) {
|
2016-06-19 16:36:57 -07:00
|
|
|
/* Specifying *both* is bogus. */
|
2017-08-07 16:38:52 +02:00
|
|
|
cmdarg_err("You can't specify both %s and a live capture.", list_option_supplied);
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-19 16:36:57 -07:00
|
|
|
}
|
|
|
|
|
2017-08-07 16:38:52 +02:00
|
|
|
if (list_option_supplied) {
|
2016-06-19 16:36:57 -07:00
|
|
|
/* We're supposed to list the link-layer types for an interface;
|
|
|
|
did the user also specify a capture file to be read? */
|
2025-05-16 06:36:13 -04:00
|
|
|
if (commandline_info.cf_name) {
|
2016-06-19 16:36:57 -07:00
|
|
|
/* Yes - that's bogus. */
|
2017-08-07 16:38:52 +02:00
|
|
|
cmdarg_err("You can't specify %s and a capture file to be read.", list_option_supplied);
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-19 16:36:57 -07:00
|
|
|
}
|
|
|
|
/* No - did they specify a ring buffer option? */
|
|
|
|
if (global_capture_opts.multi_files_on) {
|
|
|
|
cmdarg_err("Ring buffer requested, but a capture isn't being done.");
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-19 16:36:57 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* We're supposed to do a live capture; did the user also specify
|
|
|
|
a capture file to be read? */
|
2025-05-16 06:36:13 -04:00
|
|
|
if (commandline_info.start_capture && commandline_info.cf_name) {
|
2016-06-19 16:36:57 -07:00
|
|
|
/* Yes - that's bogus. */
|
|
|
|
cmdarg_err("You can't specify both a live capture and a capture file to be read.");
|
2018-02-26 10:39:27 -08:00
|
|
|
exit_application(1);
|
2016-06-19 16:36:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No - was the ring buffer option specified and, if so, does it make
|
|
|
|
sense? */
|
|
|
|
if (global_capture_opts.multi_files_on) {
|
|
|
|
/* Ring buffer works only under certain conditions:
|
|
|
|
a) ring buffer does not work with temporary files;
|
|
|
|
b) real_time_mode and multi_files_on are mutually exclusive -
|
|
|
|
real_time_mode takes precedence;
|
|
|
|
c) it makes no sense to enable the ring buffer if the maximum
|
|
|
|
file size is set to "infinite". */
|
|
|
|
if (global_capture_opts.save_file == NULL) {
|
|
|
|
cmdarg_err("Ring buffer requested, but capture isn't being saved to a permanent file.");
|
2024-03-29 18:08:09 -07:00
|
|
|
global_capture_opts.multi_files_on = false;
|
2016-06-19 16:36:57 -07:00
|
|
|
}
|
2017-06-27 22:04:33 +02:00
|
|
|
if (!global_capture_opts.has_autostop_filesize &&
|
|
|
|
!global_capture_opts.has_file_duration &&
|
2021-07-04 17:43:02 +02:00
|
|
|
!global_capture_opts.has_file_interval &&
|
|
|
|
!global_capture_opts.has_file_packets) {
|
|
|
|
cmdarg_err("Ring buffer requested, but no maximum capture file size, duration, interval or packets were specified.");
|
2016-06-19 16:36:57 -07:00
|
|
|
/* XXX - this must be redesigned as the conditions changed */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-19 17:42:14 -07:00
|
|
|
#endif
|
2016-06-18 16:49:23 -04:00
|
|
|
}
|
2021-08-30 16:02:17 -04:00
|
|
|
|
|
|
|
/* Local function used by commandline_options_drop */
|
2024-07-04 13:32:14 -05:00
|
|
|
static int cl_find_custom(const void *elem_data, const void *search_data) {
|
2025-04-13 23:35:28 +02:00
|
|
|
const char *prefix = (const char *)search_data;
|
|
|
|
const char *opt_and_val = (const char *)elem_data;
|
|
|
|
|
|
|
|
return strncmp(opt_and_val, prefix, strlen(prefix));
|
2021-08-30 16:02:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Drop any options the user specified on the command line with `-o`
|
|
|
|
* that have the given module and preference names
|
|
|
|
*/
|
|
|
|
void commandline_options_drop(const char *module_name, const char *pref_name) {
|
|
|
|
GSList *elem;
|
|
|
|
char *opt_prefix;
|
|
|
|
|
2025-05-16 06:36:13 -04:00
|
|
|
if (commandline_info.user_opts == NULL) return;
|
2021-08-30 16:02:17 -04:00
|
|
|
|
2021-12-18 18:48:20 +00:00
|
|
|
opt_prefix = ws_strdup_printf("%s.%s:", module_name, pref_name);
|
2021-08-30 16:02:17 -04:00
|
|
|
|
2025-05-16 06:36:13 -04:00
|
|
|
while (NULL != (elem = g_slist_find_custom(commandline_info.user_opts,
|
2024-07-04 13:32:14 -05:00
|
|
|
(const void *)opt_prefix, cl_find_custom))) {
|
2025-05-16 06:36:13 -04:00
|
|
|
commandline_info.user_opts =
|
|
|
|
g_slist_remove_link(commandline_info.user_opts, elem);
|
2021-08-30 16:02:17 -04:00
|
|
|
g_free(elem->data);
|
|
|
|
g_slist_free_1(elem);
|
|
|
|
}
|
|
|
|
g_free(opt_prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reapply any options the user specified on the command line with `-o`
|
|
|
|
* Called in the Qt UI when reloading Lua plugins
|
|
|
|
* For https://gitlab.com/wireshark/wireshark/-/issues/12331
|
|
|
|
*/
|
|
|
|
void commandline_options_reapply(void) {
|
|
|
|
char *errmsg = NULL;
|
|
|
|
GSList *entry = NULL;
|
|
|
|
|
2025-05-16 06:36:13 -04:00
|
|
|
for (entry = commandline_info.user_opts; entry != NULL; entry = g_slist_next(entry)) {
|
2021-08-30 16:02:17 -04:00
|
|
|
/* Although these options are from the user-supplied command line,
|
|
|
|
* they were checked for validity before we added them to user_opts,
|
|
|
|
* so we don't check them again here. In the worst case, a pref is
|
|
|
|
* specified for a lua plugin which has been edited after Wireshark
|
|
|
|
* started and has had that pref removed; not worth exiting over.
|
|
|
|
* See #12331
|
|
|
|
*/
|
|
|
|
prefs_set_pref((char *)entry->data, &errmsg);
|
|
|
|
if (errmsg != NULL) {
|
|
|
|
g_free(errmsg);
|
|
|
|
errmsg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-09 23:12:03 -04:00
|
|
|
void commandline_options_apply_extcap(void) {
|
|
|
|
char *errmsg = NULL;
|
|
|
|
GSList *entry = NULL;
|
2024-09-19 10:01:15 -04:00
|
|
|
char *pref_arg;
|
2024-09-09 23:12:03 -04:00
|
|
|
|
|
|
|
if (prefs.capture_no_extcap)
|
|
|
|
return;
|
|
|
|
|
2025-05-16 06:36:13 -04:00
|
|
|
for (entry = commandline_info.user_opts; entry != NULL; entry = g_slist_next(entry)) {
|
2024-09-19 10:01:15 -04:00
|
|
|
pref_arg = (char *)entry->data;
|
|
|
|
if (g_str_has_prefix(pref_arg, "extcap.")) {
|
|
|
|
switch (prefs_set_pref(pref_arg, &errmsg)) {
|
2024-09-09 23:12:03 -04:00
|
|
|
case PREFS_SET_OK:
|
|
|
|
break;
|
|
|
|
case PREFS_SET_SYNTAX_ERR:
|
2024-09-19 10:01:15 -04:00
|
|
|
cmdarg_err("Invalid -o flag \"%s\"%s%s", pref_arg,
|
2024-09-09 23:12:03 -04:00
|
|
|
errmsg ? ": " : "", errmsg ? errmsg : "");
|
|
|
|
g_free(errmsg);
|
|
|
|
exit_application(1);
|
|
|
|
break;
|
|
|
|
case PREFS_SET_NO_SUCH_PREF:
|
|
|
|
cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
|
2024-09-19 10:01:15 -04:00
|
|
|
pref_arg);
|
2024-09-09 23:12:03 -04:00
|
|
|
exit_application(1);
|
|
|
|
break;
|
|
|
|
case PREFS_SET_OBSOLETE:
|
|
|
|
cmdarg_err("-o flag \"%s\" specifies obsolete preference",
|
2024-09-19 10:01:15 -04:00
|
|
|
pref_arg);
|
2024-09-09 23:12:03 -04:00
|
|
|
exit_application(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ws_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 16:02:17 -04:00
|
|
|
/* Free memory used to hold user-specified command line options */
|
|
|
|
void commandline_options_free(void) {
|
2025-05-16 06:36:13 -04:00
|
|
|
g_slist_free_full(g_steal_pointer(&commandline_info.user_opts), g_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool commandline_is_full_screen(void)
|
|
|
|
{
|
|
|
|
return commandline_info.full_screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* commandline_get_cf_name(void)
|
|
|
|
{
|
|
|
|
return commandline_info.cf_name;
|
2021-08-30 16:02:17 -04:00
|
|
|
}
|
2025-05-16 06:36:13 -04:00
|
|
|
|
|
|
|
char* commandline_get_rfilter(void)
|
|
|
|
{
|
|
|
|
return commandline_info.rfilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* commandline_get_dfilter(void)
|
|
|
|
{
|
|
|
|
return commandline_info.dfilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* commandline_get_jfilter(void)
|
|
|
|
{
|
|
|
|
return commandline_info.jfilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
search_direction commandline_get_jump_direction(void)
|
|
|
|
{
|
|
|
|
return commandline_info.jump_backwards;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t commandline_get_go_to_packet(void)
|
|
|
|
{
|
|
|
|
return commandline_info.go_to_packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
bool commandline_is_start_capture(void)
|
|
|
|
{
|
|
|
|
return commandline_info.start_capture;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool commandline_is_quit_after_capture(void)
|
|
|
|
{
|
|
|
|
return commandline_info.quit_after_cap;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* commandline_get_first_capture_comment(void)
|
|
|
|
{
|
|
|
|
if (commandline_info.capture_comments == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (char*)g_ptr_array_index(commandline_info.capture_comments, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int commandline_get_caps_queries(void)
|
|
|
|
{
|
|
|
|
int caps = 0;
|
|
|
|
|
|
|
|
if (commandline_info.list_link_layer_types)
|
|
|
|
caps |= CAPS_QUERY_LINK_TYPES;
|
|
|
|
if (commandline_info.list_timestamp_types)
|
|
|
|
caps |= CAPS_QUERY_TIMESTAMP_TYPES;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPtrArray* commandline_get_capture_comments(void)
|
|
|
|
{
|
|
|
|
return commandline_info.capture_comments;
|
|
|
|
}
|
|
|
|
#endif
|