From 8a422b5d020361df0f69d71c78a30527a8ba8c4b Mon Sep 17 00:00:00 2001 From: John Thacker Date: Thu, 12 Oct 2023 18:54:13 -0400 Subject: [PATCH] docs: Make version option handling consistent Document the help and version option handling, including long option form, the same for all the command line tools, both in the their help output and in any manpages. Add version option to randpkt. Fix #15483 --- dftest.c | 2 +- doc/capinfos.adoc | 12 ++++++++++-- doc/captype.adoc | 10 ++++++++-- doc/dumpcap.adoc | 14 ++++++++++---- doc/editcap.adoc | 4 ++-- doc/mergecap.adoc | 4 ++-- doc/randpkt.adoc | 20 ++++++++++++++++++++ doc/rawshark.adoc | 18 ++++++++++++------ doc/reordercap.adoc | 19 ++++++++++++++++--- doc/text2pcap.adoc | 18 ++++++++++++------ doc/tshark.adoc | 12 ++++++++++-- doc/wireshark.adoc | 8 ++++++++ randpkt.c | 30 +++++++++++++++++++++++------- reordercap.c | 6 +++--- sharkd_daemon.c | 1 + text2pcap.c | 4 ++-- 16 files changed, 140 insertions(+), 42 deletions(-) diff --git a/dftest.c b/dftest.c index d41b5159a0..b51896e4df 100644 --- a/dftest.c +++ b/dftest.c @@ -304,7 +304,7 @@ main(int argc, char **argv) opt_dump_refs = 1; break; case 'v': - show_help_header(NULL); + show_version(); exit(EXIT_SUCCESS); break; case 'h': diff --git a/doc/capinfos.adoc b/doc/capinfos.adoc index 271452dfcd..a8f2b599d6 100644 --- a/doc/capinfos.adoc +++ b/doc/capinfos.adoc @@ -55,6 +55,14 @@ capinfos - Prints information about capture files <__infile__> __...__ +[manarg] +*capinfos* +*-h|--help* + +[manarg] +*capinfos* +*-v|--version* + == DESCRIPTION *Capinfos* is a program that reads one or more capture files and @@ -196,7 +204,7 @@ Displays additional capture file information. -h|--help:: + -- -Prints the help listing and exits. +Print the version number and options and exit. -- -H:: @@ -397,7 +405,7 @@ latest packet seen. -v|--version:: + -- -Displays the tool's version and exits. +Print the full version information and exit. -- -x:: diff --git a/doc/captype.adoc b/doc/captype.adoc index 4fd5eebde3..485bac9ee9 100644 --- a/doc/captype.adoc +++ b/doc/captype.adoc @@ -13,11 +13,17 @@ captype - Prints the types of capture files [manarg] *captype* -[ *-h* ] -[ *-v* ] <__infile__> __...__ +[manarg] +*captype* +*-h|--help* + +[manarg] +*captype* +*-v|--version* + == DESCRIPTION *Captype* is a program that opens one or more capture files and diff --git a/doc/dumpcap.adoc b/doc/dumpcap.adoc index dd55f9c3e9..f0d85b4996 100644 --- a/doc/dumpcap.adoc +++ b/doc/dumpcap.adoc @@ -22,7 +22,6 @@ dumpcap - Dump network traffic [ *-D*|*--list-interfaces* ] [ *-f* ] [ *-g* ] -[ *-h*|*--help* ] [ *-i*|*--interface* |rpcap://:/|TCP@:|- ] [ *-I*|*--monitor-mode* ] [ *-k* ,[],[],[] ] @@ -39,7 +38,6 @@ dumpcap - Dump network traffic [ *-S* ] [ *-t* ] [ *--temp-dir* ] -[ *-v*|*--version* ] [ *-w* ] [ *-y*|*--linktype* ] [ *--capture-comment* ] @@ -47,6 +45,14 @@ dumpcap - Dump network traffic [ *--time-stamp-type* ] [ *--update-interval* ] +[manarg] +*dumpcap* +*-h|--help* + +[manarg] +*dumpcap* +*-v|--version* + == DESCRIPTION *Dumpcap* is a network traffic dump tool. It lets you capture packet @@ -231,7 +237,7 @@ user's group). -h|--help:: + -- -Print the version and options and exits. +Print the version number and options and exit. -- -i|--interface |rpcap://:/|TCP@:|-:: @@ -463,7 +469,7 @@ typically defaults to __%USERPROFILE%\AppData\Local\Temp__. -v|--version:: + -- -Print the version and exit. +Print the full version information and exit. -- -w :: diff --git a/doc/editcap.adoc b/doc/editcap.adoc index 4e7edd32af..bb9b2c2fbf 100644 --- a/doc/editcap.adoc +++ b/doc/editcap.adoc @@ -249,7 +249,7 @@ is the *pcapng* format. -h|--help:: + -- -Prints the version and options and exits. +Print the version number and options and exit. -- -i :: @@ -412,7 +412,7 @@ packet, you will need od(1)/xref:text2pcap.html[text2pcap](1). -v|--version:: + -- -Print the version and exit. +Print the full version information and exit. -- -V:: diff --git a/doc/mergecap.adoc b/doc/mergecap.adoc index 407f3f506a..9885fcd981 100644 --- a/doc/mergecap.adoc +++ b/doc/mergecap.adoc @@ -93,7 +93,7 @@ available output formats. By default this is the *pcapng* format. -h|--help:: + -- -Prints the version and options and exits. +Print the version number and options and exit. -- -I :: @@ -143,7 +143,7 @@ frames were used). -v|--version:: + -- -Print the version and exit. +Print the full version information and exit. -- -V:: diff --git a/doc/randpkt.adoc b/doc/randpkt.adoc index 9fc80f152e..75e0ccc276 100644 --- a/doc/randpkt.adoc +++ b/doc/randpkt.adoc @@ -20,6 +20,14 @@ randpkt - Random packet generator [ *-t* ] +[manarg] +*randpkt* +*-h|--help* + +[manarg] +*randpkt* +*-v|--version* + == DESCRIPTION *randpkt* is a small utility that creates a trace file full of random packets. @@ -72,6 +80,12 @@ available output formats. Note that not all output formats support all packet types. -- +-h|--help:: ++ +-- +Print the version number and options and exit. +-- + -r:: + -- @@ -112,6 +126,12 @@ Defines the type of packet to generate: usb-linux Universal Serial Bus with Linux specific header -- +-v|--version:: ++ +-- +Print the full version information and exit. +-- + include::diagnostic-options.adoc[] == EXAMPLES diff --git a/doc/rawshark.adoc b/doc/rawshark.adoc index 885d32975a..1b0064bae1 100644 --- a/doc/rawshark.adoc +++ b/doc/rawshark.adoc @@ -15,7 +15,6 @@ rawshark - Dump and analyze raw pcap data *rawshark* [ *-d* | ] [ *-F* ] -[ *-h* ] [ *-l* ] [ *-m* ] [ *-o* ] ... @@ -24,9 +23,16 @@ rawshark - Dump and analyze raw pcap data [ *-R* ] [ *-s* ] [ *-S* ] -[ *-v* ] [ *options* ] +[manarg] +*rawshark* +*-h|--help* + +[manarg] +*rawshark* +*-v|--version* + == DESCRIPTION *Rawshark* reads a stream of packets from a file or pipe, and prints a line @@ -132,10 +138,10 @@ multiple times in a given packet. A single field may be specified per *-F* flag. If you want to apply a display filter, use the *-R* flag. -- --h:: +-h|--help:: + -- -Print the version and options and exits. +Print the version number and options and exit. -- -l:: @@ -226,10 +232,10 @@ For something similar to Wireshark's standard display ("Type: A (1)") you could use *%D: %S (%N)*. -- --v:: +-v|--version:: + -- -Print the version and exit. +Print the full version information and exit. -- include::dissection-options.adoc[tags=!tshark;!decode_as] diff --git a/doc/reordercap.adoc b/doc/reordercap.adoc index 623b26e995..b6e199e95d 100644 --- a/doc/reordercap.adoc +++ b/doc/reordercap.adoc @@ -14,9 +14,16 @@ reordercap - Reorder input file by timestamp into output file [manarg] *reordercap* [ *-n* ] -[ *-v* ] <__infile__> <__outfile__> +[manarg] +*reordercap* +*-h|--help* + +[manarg] +*reordercap* +*-v|--version* + == DESCRIPTION *Reordercap* is a program that reads an input capture file and rewrites the @@ -41,6 +48,12 @@ the same way *reordercap* handles this. == OPTIONS +-h|--help:: ++ +-- +Print the version number and options and exit. +-- + -n:: + -- @@ -48,10 +61,10 @@ When the *-n* option is used, *reordercap* will not write out the output file if it finds that the input file is already in order. -- --v:: +-v|--version:: + -- -Print the version and exit. +Print the full version information and exit. -- include::diagnostic-options.adoc[] diff --git a/doc/text2pcap.adoc b/doc/text2pcap.adoc index 70c51552b9..ab8947479d 100644 --- a/doc/text2pcap.adoc +++ b/doc/text2pcap.adoc @@ -19,7 +19,6 @@ text2pcap - Generate a capture file from an ASCII hexdump of packets [ *-e* ] [ *-E* ] [ *-F* ] -[ *-h* ] [ *-i* ] [ *-l* ] [ *-N* ] @@ -32,12 +31,19 @@ text2pcap - Generate a capture file from an ASCII hexdump of packets [ *-t* ] [ *-T* , ] [ *-u* , ] -[ *-v* ] [ *-4* , ] [ *-6* , ] <__infile__>|- <__outfile__>|- +[manarg] +*text2pcap* +*-h|--help* + +[manarg] +*text2pcap* +*-v|--version* + == DESCRIPTION *Text2pcap* is a program that reads in an ASCII hex dump and writes the @@ -233,8 +239,8 @@ the file in several formats; *text2pcap -F* provides a list of the available output formats. The default is the *pcapng* format. -- --h:: -Displays a help message. +-h|--help:: +Print the version number and options and exit. -i :: + @@ -373,8 +379,8 @@ are automatically also included with each packet. Example: __-u1000,69__ to make the packets look like TFTP/UDP packets. -- --v:: -Print the version and exit. +-v|--version:: +Print the full version information and exit. -4 ,:: + diff --git a/doc/tshark.adoc b/doc/tshark.adoc index 1f156a375b..0db762afa9 100644 --- a/doc/tshark.adoc +++ b/doc/tshark.adoc @@ -25,6 +25,14 @@ tshark - Dump and analyze network traffic *tshark* *-G* [ ] [ --elastic-mapping-filter ] +[manarg] +*tshark* +*-h|--help* + +[manarg] +*tshark* +*-v|--version* + == DESCRIPTION *TShark* is a network protocol analyzer. It lets you capture packet @@ -574,7 +582,7 @@ Field 4:: False String -h|--help:: + -- -Print the version and options and exit. +Print the version number and options and exit. -- -H :: @@ -907,7 +915,7 @@ names. -v|--version:: + -- -Print the version and exit. +Print the full version information and exit. -- -V:: diff --git a/doc/wireshark.adoc b/doc/wireshark.adoc index 3cba121e45..0dc269f0c9 100644 --- a/doc/wireshark.adoc +++ b/doc/wireshark.adoc @@ -20,6 +20,14 @@ wireshark - Interactively dump and analyze network traffic [ *options* ] [ ] +[manarg] +*wireshark* +*-h|--help* + +[manarg] +*wireshark* +*-v|--version* + == DESCRIPTION *Wireshark* is a GUI network protocol analyzer. It lets you diff --git a/randpkt.c b/randpkt.c index c8aee85d29..77e2d8843d 100644 --- a/randpkt.c +++ b/randpkt.c @@ -34,6 +34,7 @@ #include #include +#include #include "randpkt_core/randpkt_core.h" @@ -92,11 +93,17 @@ usage(gboolean is_error) output = stderr; } - fprintf(output, "Usage: randpkt [-b maxbytes] [-c count] [-t type] [-r] [-F output file type] filename\n"); - fprintf(output, "Default max bytes (per packet) is 5000\n"); - fprintf(output, "Default count is 1000.\n"); - fprintf(output, "Default output file type is pcapng.\n"); - fprintf(output, "-r: random packet type selection\n"); + fprintf(output, "Usage: randpkt [options] \n"); + fprintf(output, "\n"); + fprintf(output, "Options:\n"); + fprintf(output, " -b maximum bytes per packet (default: 5000)\n"); + fprintf(output, " -c packet count (default: 1000)\n"); + fprintf(output, " -F output file type (default: pcapng)\n"); + fprintf(output, " an empty \"-F\" option will list the file types\n"); + fprintf(output, " -r select a different random type for each packet\n"); + fprintf(output, " -t packet type\n"); + fprintf(output, " -h, --help display this help and exit.\n"); + fprintf(output, " -v, --version print version information and exit.\n"); fprintf(output, "\n"); fprintf(output, "Types:\n"); @@ -110,7 +117,7 @@ usage(gboolean is_error) g_strfreev(abbrev_list); g_strfreev(longname_list); - fprintf(output, "\nIf type is not specified, a random packet will be chosen\n\n"); + fprintf(output, "\nIf type is not specified, a random packet type will be chosen\n\n"); } int @@ -142,6 +149,7 @@ main(int argc, char *argv[]) int ret = EXIT_SUCCESS; static const struct ws_option long_options[] = { {"help", ws_no_argument, NULL, 'h'}, + {"version", ws_no_argument, NULL, 'v'}, {0, 0, 0, 0 } }; @@ -180,7 +188,9 @@ main(int argc, char *argv[]) create_app_running_mutex(); #endif /* _WIN32 */ - while ((opt = ws_getopt_long(argc, argv, "b:c:F:ht:r", long_options, NULL)) != -1) { + ws_init_version_info("Randpkt", NULL, NULL); + + while ((opt = ws_getopt_long(argc, argv, "b:c:F:ht:rv", long_options, NULL)) != -1) { switch (opt) { case 'b': /* max bytes */ produce_max_bytes = get_positive_int(ws_optarg, "max bytes"); @@ -209,6 +219,7 @@ main(int argc, char *argv[]) break; case 'h': + show_help_header(NULL); usage(FALSE); goto clean_exit; break; @@ -217,6 +228,11 @@ main(int argc, char *argv[]) allrandom = TRUE; break; + case 'v': + show_version(); + goto clean_exit; + break; + case '?': switch(ws_optopt) { case 'F': diff --git a/reordercap.c b/reordercap.c index 3fdad59414..ed4a36493b 100644 --- a/reordercap.c +++ b/reordercap.c @@ -49,9 +49,9 @@ print_usage(FILE *output) fprintf(output, "Usage: reordercap [options] \n"); fprintf(output, "\n"); fprintf(output, "Options:\n"); - fprintf(output, " -n don't write to output file if the input file is ordered.\n"); - fprintf(output, " -h display this help and exit.\n"); - fprintf(output, " -v print version information and exit.\n"); + fprintf(output, " -n don't write to output file if the input file is ordered.\n"); + fprintf(output, " -h, --help display this help and exit.\n"); + fprintf(output, " -v, --version print version information and exit.\n"); } /* Remember where this frame was in the file */ diff --git a/sharkd_daemon.c b/sharkd_daemon.c index 319b5f0d75..346f87b79c 100644 --- a/sharkd_daemon.c +++ b/sharkd_daemon.c @@ -312,6 +312,7 @@ sharkd_init(int argc, char **argv) break; case 'h': + show_help_header("Daemon variant of Wireshark"); print_usage(stderr); exit(0); break; diff --git a/text2pcap.c b/text2pcap.c index 161f0a79f1..aa3a279fdf 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -268,8 +268,8 @@ print_usage (FILE *output) fprintf(output, "\n" "Miscellaneous:\n" - " -h display this help and exit\n" - " -v print version information and exit\n" + " -h, --help display this help and exit\n" + " -v, --version print version information and exit\n" " -q don't report processed packet counts\n" ""); }