Skip to content

Commit

Permalink
Move more version-info-related stuff to version_info.c.
Browse files Browse the repository at this point in the history
Have a ws_init_version_info() routine that, given an application name
string:

	constructs the app-name-and-version-information string, and
	saves it;

	adds the initial crash information on platforms that support it,
	and saves it.

Have show_version() use the saved information and take no arguments.

Add a show_help_header() routine to print the header for --help
command-line options, given a description of the application; it prints
the application name and version information, the description, and the
"See {wireshark.org URL}" line.

Use those routines in various places, including providing the
"application name" string in pcapng SHBs.

Change-Id: I0042a8fcc91aa919ad5c381a8b8674a007ce66df
Reviewed-on: https://code.wireshark.org/review/31029
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
  • Loading branch information
guyharris committed Dec 13, 2018
1 parent a34cc98 commit 43dfd45
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 374 deletions.
31 changes: 4 additions & 27 deletions capinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#include <wiretap/wtap.h>

#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
#include <cli_main.h>
Expand Down Expand Up @@ -1403,8 +1402,6 @@ hash_to_str(const unsigned char *hash, size_t length, char *str) {
int
real_main(int argc, char *argv[])
{
GString *comp_info_str;
GString *runtime_info_str;
char *init_progfile_dir_error;
wtap *wth;
int err;
Expand All @@ -1431,21 +1428,8 @@ real_main(int argc, char *argv[])
/* Get the decimal point. */
decimal_point = g_strdup(localeconv()->decimal_point);

/* Get the compile-time version information string */
comp_info_str = get_compiled_version_info(NULL, NULL);

/* Get the run-time version information string */
runtime_info_str = get_runtime_version_info(NULL);

/* Add it to the information to be reported on a crash. */
ws_add_crash_info("Capinfos (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
/* Initialize the version information. */
ws_init_version_info("Capinfos (Wireshark)", NULL, NULL, NULL);

#ifdef _WIN32
create_app_running_mutex();
Expand Down Expand Up @@ -1629,20 +1613,13 @@ real_main(int argc, char *argv[])
break;

case 'h':
printf("Capinfos (Wireshark) %s\n"
"Print various information (infos) about capture files.\n"
"See https://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
show_help_header("Print various information (infos) about capture files.");
print_usage(stdout);
goto exit;
break;

case 'v':
comp_info_str = get_compiled_version_info(NULL, NULL);
runtime_info_str = get_runtime_version_info(NULL);
show_version("Capinfos (Wireshark)", comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
show_version();
goto exit;
break;

Expand Down
31 changes: 4 additions & 27 deletions captype.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <wiretap/wtap.h>

#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/file_util.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
Expand Down Expand Up @@ -81,8 +80,6 @@ failure_message_cont(const char *msg_format, va_list ap)
int
real_main(int argc, char *argv[])
{
GString *comp_info_str;
GString *runtime_info_str;
char *init_progfile_dir_error;
wtap *wth;
int err;
Expand All @@ -101,21 +98,8 @@ real_main(int argc, char *argv[])

cmdarg_err_init(failure_warning_message, failure_message_cont);

/* Get the compile-time version information string */
comp_info_str = get_compiled_version_info(NULL, NULL);

/* Get the run-time version information string */
runtime_info_str = get_runtime_version_info(NULL);

/* Add it to the information to be reported on a crash. */
ws_add_crash_info("Captype (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
/* Initialize the version information. */
ws_init_version_info("Captype (Wireshark)", NULL, NULL, NULL);

#ifdef _WIN32
create_app_running_mutex();
Expand Down Expand Up @@ -149,20 +133,13 @@ real_main(int argc, char *argv[])
switch (opt) {

case 'h':
printf("Captype (Wireshark) %s\n"
"Print the file types of capture files.\n"
"See https://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
show_help_header("Print the file types of capture files.");
print_usage(stdout);
exit(0);
break;

case 'v':
comp_info_str = get_compiled_version_info(NULL, NULL);
runtime_info_str = get_runtime_version_info(NULL);
show_version("Captype (Wireshark)", comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
show_version();
exit(0);
break;

Expand Down
36 changes: 6 additions & 30 deletions dumpcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <errno.h>

#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/strtoi.h>
#include <cli_main.h>
#include <version_info.h>
Expand Down Expand Up @@ -3028,18 +3027,16 @@ capture_loop_init_pcapng_output(capture_options *capture_opts, loop_data *ld)
GString *cpu_info_str = g_string_new("");
get_cpu_info(cpu_info_str);

char *appname = g_strdup_printf("Dumpcap (Wireshark) %s", get_ws_vcs_version_info());
successful = pcapng_write_session_header_block(ld->pdh,
(const char *)capture_opts->capture_comment, /* Comment */
cpu_info_str->str, /* HW */
os_info_str->str, /* OS */
appname,
get_appname_and_version(),
-1, /* section_length */
&ld->bytes_written,
&err);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "%s: wrote dumpcap SHB %d", G_STRFUNC, successful);
g_string_free(cpu_info_str, TRUE);
g_free(appname);
}

for (unsigned i = 0; successful && (i < ld->saved_idbs->len); i++) {
Expand Down Expand Up @@ -4613,8 +4610,6 @@ get_dumpcap_runtime_info(GString *str)
int
real_main(int argc, char *argv[])
{
GString *comp_info_str;
GString *runtime_info_str;
int opt;
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
Expand Down Expand Up @@ -4655,21 +4650,9 @@ real_main(int argc, char *argv[])

cmdarg_err_init(dumpcap_cmdarg_err, dumpcap_cmdarg_err_cont);

/* Get the compile-time version information string */
comp_info_str = get_compiled_version_info(NULL, get_dumpcap_compiled_info);

/* Get the run-time version information string */
runtime_info_str = get_runtime_version_info(get_dumpcap_runtime_info);

/* Add it to the information to be reported on a crash. */
ws_add_crash_info("Dumpcap (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
/* Initialize the version information. */
ws_init_version_info("Dumpcap (Wireshark)", NULL, get_dumpcap_compiled_info,
get_dumpcap_runtime_info);

#ifdef _WIN32
create_app_running_mutex();
Expand Down Expand Up @@ -4961,19 +4944,12 @@ real_main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
switch (opt) {
case 'h': /* Print help and exit */
printf("Dumpcap (Wireshark) %s\n"
"Capture network packets and dump them into a pcapng or pcap file.\n"
"See https://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
show_help_header("Capture network packets and dump them into a pcapng or pcap file.");
print_usage(stdout);
exit_main(0);
break;
case 'v': /* Show version and exit */
comp_info_str = get_compiled_version_info(NULL, get_dumpcap_compiled_info);
runtime_info_str = get_runtime_version_info(get_dumpcap_runtime_info);
show_version("Dumpcap (Wireshark)", comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
show_version();
exit_main(0);
break;
/*** capture option specific ***/
Expand Down
37 changes: 5 additions & 32 deletions editcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
# include "wsutil/strptime.h"
#endif

#include <wsutil/crash_info.h>
#include <wsutil/clopts_common.h>
#include <wsutil/cmdarg_err.h>
#include <wsutil/filesystem.h>
Expand Down Expand Up @@ -985,9 +984,6 @@ editcap_dump_open(const char *filename, const wtap_dump_params *params,
int
real_main(int argc, char *argv[])
{
GString *comp_info_str;
GString *runtime_info_str;
char *appname;
char *init_progfile_dir_error;
wtap *wth = NULL;
int i, j, read_err, write_err;
Expand Down Expand Up @@ -1043,24 +1039,8 @@ real_main(int argc, char *argv[])
create_app_running_mutex();
#endif /* _WIN32 */

/* Get the compile-time version information string */
comp_info_str = get_compiled_version_info(NULL, NULL);

/* Get the run-time version information string */
runtime_info_str = get_runtime_version_info(NULL);

/* Get the application name with version info */
appname = g_strdup_printf("Editcap (Wireshark) %s", get_ws_vcs_version_info());

/* Add it to the information to be reported on a crash. */
ws_add_crash_info("%s\n"
"\n"
"%s"
"\n"
"%s",
appname, comp_info_str->str, runtime_info_str->str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
/* Initialize the version information. */
ws_init_version_info("Editcap (Wireshark)", NULL, NULL, NULL);

/*
* Get credential information for later use.
Expand Down Expand Up @@ -1282,10 +1262,7 @@ real_main(int argc, char *argv[])
break;

case 'h':
printf("Editcap (Wireshark) %s\n"
"Edit and/or translate the format of capture files.\n"
"See https://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
show_help_header("Edit and/or translate the format of capture files.");
print_usage(stdout);
goto clean_exit;
break;
Expand Down Expand Up @@ -1345,11 +1322,7 @@ real_main(int argc, char *argv[])
break;

case 'V':
comp_info_str = get_compiled_version_info(NULL, NULL);
runtime_info_str = get_runtime_version_info(NULL);
show_version("Editcap (Wireshark)", comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
show_version();
goto clean_exit;
break;

Expand Down Expand Up @@ -1566,7 +1539,7 @@ real_main(int argc, char *argv[])

/* If we don't have an application name add one */
if (wtap_block_get_string_option_value(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) {
wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "%s", appname);
wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "%s", get_appname_and_version());
}

pdh = editcap_dump_open(filename, &params, &write_err);
Expand Down
23 changes: 3 additions & 20 deletions fuzz/fuzzshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <epan/epan.h>

#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
#include <wsutil/report_message.h>
Expand Down Expand Up @@ -180,8 +179,6 @@ fuzz_prefs_apply(void)
static int
fuzz_init(int argc _U_, char **argv)
{
GString *comp_info_str;
GString *runtime_info_str;
char *init_progfile_dir_error;

char *err_msg = NULL;
Expand Down Expand Up @@ -238,23 +235,9 @@ fuzz_init(int argc _U_, char **argv)
if (init_progfile_dir_error != NULL)
fprintf(stderr, "fuzzshark: Can't get pathname of oss-fuzzshark program: %s.\n", init_progfile_dir_error);

/* Get the compile-time version information string */
comp_info_str = get_compiled_version_info(NULL, epan_get_compiled_version_info);

/* Get the run-time version information string */
runtime_info_str = get_runtime_version_info(epan_get_runtime_version_info);

/* Add it to the information to be reported on a crash. */
ws_add_crash_info("OSS Fuzzshark (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(),
comp_info_str->str,
runtime_info_str->str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
/* Initialize the version information. */
ws_init_version_info("OSS Fuzzshark (Wireshark)", NULL,
epan_get_compiled_version_info, epan_get_runtime_version_info);

init_report_message(failure_warning_message, failure_warning_message,
open_failure_message, read_failure_message, write_failure_message);
Expand Down
Loading

0 comments on commit 43dfd45

Please sign in to comment.