Move more version-info-related stuff to version_info.c.
authorGuy Harris <guy@alum.mit.edu>
Thu, 13 Dec 2018 02:16:15 +0000 (18:16 -0800)
committerGuy Harris <guy@alum.mit.edu>
Thu, 13 Dec 2018 03:16:13 +0000 (03:16 +0000)
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>
19 files changed:
capinfos.c
captype.c
dumpcap.c
editcap.c
fuzz/fuzzshark.c
mergecap.c
rawshark.c
reordercap.c
sharkd.c
text2pcap.c
tfshark.c
tshark.c
ui/commandline.c
ui/commandline.h
ui/qt/main.cpp
ui/tap_export_pdu.c
version_info.c
version_info.h
wiretap/nettrace_3gpp_32_423.c

index 0b06e42207eb1451a3c63e15f3f0618023bc16f2..c0417621003994311f80f0cef8a4e04eaf68eea8 100644 (file)
@@ -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>
@@ -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;
@@ -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();
@@ -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;
 
index 50de540f418fd28fea20fd2a63f211041c0a114d..b35728e26cd668567196c5583027af6725f5f225 100644 (file)
--- a/captype.c
+++ b/captype.c
@@ -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>
@@ -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;
@@ -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();
@@ -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;
 
index f36ce588bd0493ca47aa6f88009c20b927e40c62..38e7d2ac9038ff352ad3d98b0ad5ba9e912421ec 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -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>
@@ -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++) {
@@ -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'},
@@ -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();
@@ -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 ***/
index 78b83b6a2fd6bf8ae541a2feff49c9ab569be152..0346cc9ca0f9ffebd858c044653f5bc2da84cbb4 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -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>
@@ -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;
@@ -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.
@@ -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;
@@ -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;
 
@@ -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);
index e31d8219a5f9f27efa60dee11467147645342596..d618b81121b36462ad0af58080091f3a6980c2f5 100644 (file)
@@ -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>
@@ -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;
@@ -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);
index 21798ad974a1b074569a3351bb394915bed8f5f2..6601f31d516c2b716b321db277ec752e0341228a 100644 (file)
@@ -32,7 +32,6 @@
 
 #include <wsutil/clopts_common.h>
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
@@ -230,9 +229,6 @@ merge_callback(merge_event event, int num,
 int
 real_main(int argc, char *argv[])
 {
-  GString            *comp_info_str;
-  GString            *runtime_info_str;
-  char               *appname;
   char               *init_progfile_dir_error;
   int                 opt;
   static const struct option long_options[] = {
@@ -264,24 +260,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("mergecap (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("Mergecap (Wireshark)", NULL, NULL, NULL);
 
   /*
    * Get credential information for later use.
@@ -325,10 +305,7 @@ real_main(int argc, char *argv[])
       break;
 
     case 'h':
-      printf("Mergecap (Wireshark) %s\n"
-             "Merge two or more capture files into one.\n"
-             "See https://www.wireshark.org for more information.\n",
-             get_ws_vcs_version_info());
+      show_help_header("Merge two or more capture files into one.");
       print_usage(stdout);
       goto clean_exit;
       break;
@@ -353,11 +330,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("Mergecap (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;
 
@@ -418,13 +391,15 @@ real_main(int argc, char *argv[])
     status = merge_files_to_stdout(file_type,
                                    (const char *const *) &argv[optind],
                                    in_file_count, do_append, mode, snaplen,
-                                   appname, verbose ? &cb : NULL,
+                                   get_appname_and_version(),
+                                   verbose ? &cb : NULL,
                                    &err, &err_info, &err_fileno, &err_framenum);
   } else {
     /* merge the files to the outfile */
     status = merge_files(out_filename, file_type,
                          (const char *const *) &argv[optind], in_file_count,
-                         do_append, mode, snaplen, appname, verbose ? &cb : NULL,
+                         do_append, mode, snaplen, get_appname_and_version(),
+                         verbose ? &cb : NULL,
                          &err, &err_info, &err_fileno, &err_framenum);
   }
 
index 15b7b4c933aab2153c30a84d98cdcfad4a04564a..77e7fdb6764b4da7efc0d43617312fb32510c8e1 100644 (file)
@@ -47,7 +47,6 @@
 #include <epan/epan.h>
 
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/plugins.h>
@@ -406,8 +405,6 @@ set_link_type(const char *lt_arg) {
 int
 real_main(int argc, char *argv[])
 {
-    GString             *comp_info_str;
-    GString             *runtime_info_str;
     char                *init_progfile_dir_error;
     int                  opt, i;
 
@@ -442,19 +439,10 @@ real_main(int argc, char *argv[])
 
     cmdarg_err_init(rawshark_cmdarg_err, rawshark_cmdarg_err_cont);
 
-    /* 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(NULL);
-
-    /* Add it to the information to be reported on a crash. */
-    ws_add_crash_info("Rawshark (Wireshark) %s\n"
-           "\n"
-           "%s"
-           "\n"
-           "%s",
-        get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
+    /* Initialize the version information. */
+    ws_init_version_info("Rawshark (Wireshark)", NULL,
+                         epan_get_compiled_version_info,
+                         NULL);
 
 #ifdef _WIN32
     create_app_running_mutex();
@@ -553,10 +541,7 @@ real_main(int argc, char *argv[])
                 g_ptr_array_add(disp_fields, g_strdup(optarg));
                 break;
             case 'h':        /* Print help and exit */
-                printf("Rawshark (Wireshark) %s\n"
-                       "Dump and analyze network traffic.\n"
-                       "See https://www.wireshark.org for more information.\n",
-                       get_ws_vcs_version_info());
+                show_help_header("Dump and analyze network traffic.");
                 print_usage(stdout);
                 goto clean_exit;
                 break;
@@ -691,7 +676,7 @@ real_main(int argc, char *argv[])
                 break;
             case 'v':        /* Show version and exit */
             {
-                show_version("Rawshark (Wireshark)", comp_info_str, runtime_info_str);
+                show_version();
                 goto clean_exit;
             }
             default:
@@ -819,8 +804,6 @@ real_main(int argc, char *argv[])
 
 clean_exit:
     g_free(pipe_name);
-    g_string_free(comp_info_str, TRUE);
-    g_string_free(runtime_info_str, TRUE);
     epan_free(cfile.epan);
     epan_cleanup();
     extcap_cleanup();
index ce85acbeefddcce0aa2c5edc2bef37967a93a770..c727db6e781f4e60bf496ba263e511256ad63db9 100644 (file)
@@ -26,7 +26,6 @@
 #endif
 
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
@@ -164,8 +163,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 = NULL;
     wtap_dumper *pdh = NULL;
@@ -196,21 +193,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("Reordercap (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("Reordercap (Wireshark)", NULL, NULL, NULL);
 
     /*
      * Get credential information for later use.
@@ -241,18 +225,11 @@ real_main(int argc, char *argv[])
                 write_output_regardless = FALSE;
                 break;
             case 'h':
-                printf("Reordercap (Wireshark) %s\n"
-                       "Reorder timestamps of input file frames into output file.\n"
-                       "See https://www.wireshark.org for more information.\n",
-                       get_ws_vcs_version_info());
+                show_help_header("Reorder timestamps of input file frames into output file.");
                 print_usage(stdout);
                 goto clean_exit;
             case 'v':
-                comp_info_str = get_compiled_version_info(NULL, NULL);
-                runtime_info_str = get_runtime_version_info(NULL);
-                show_version("Reordercap (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;
             case '?':
                 print_usage(stderr);
index 46d3a338a1a924c449673075297e258e020d74ea..ba304d97c1ae48514dbef40c6db50ce84afabe1b 100644 (file)
--- a/sharkd.c
+++ b/sharkd.c
@@ -25,7 +25,6 @@
 
 #include <wsutil/clopts_common.h>
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
@@ -103,8 +102,6 @@ print_current_user(void) {
 int
 main(int argc, char *argv[])
 {
-  GString             *comp_info_str;
-  GString             *runtime_info_str;
   char                *init_progfile_dir_error;
 
   char                *err_msg = NULL;
@@ -131,21 +128,10 @@ main(int argc, char *argv[])
             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("Sharkd (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("Sharkd (Wireshark)", NULL,
+                       epan_get_compiled_version_info,
+                       epan_get_runtime_version_info);
 
   if (sharkd_init(argc, argv) < 0)
   {
index 5ac0e9c7a3f88fa86ac534a26fcc57c8da4529cd..6ffa7cf3e5dc1082f51e81d351ffaa55e7223263 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <wsutil/file_util.h>
-#include <wsutil/crash_info.h>
 #include <cli_main.h>
 #include <version_info.h>
 #include <wsutil/inet_addr.h>
@@ -872,20 +871,17 @@ write_file_header (void)
     gboolean success;
 
     if (use_pcapng) {
-        char *appname;
         char *comment;
 
-        appname = g_strdup_printf("text2pcap (Wireshark) %s", get_ws_vcs_version_info());
         comment = g_strdup_printf("Generated from input file %s.", input_filename);
         success = pcapng_write_session_header_block(output_file,
                                                     comment,
                                                     NULL,    /* HW */
                                                     NULL,    /* OS */
-                                                    appname,
+                                                    get_appname_and_version(),
                                                     -1,      /* section_length */
                                                     &bytes_written,
                                                     &err);
-        g_free(appname);
         g_free(comment);
         if (success) {
             success = pcapng_write_interface_description_block(output_file,
@@ -1441,8 +1437,6 @@ print_usage (FILE *output)
 static int
 parse_options (int argc, char *argv[])
 {
-    GString *comp_info_str;
-    GString *runtime_info_str;
     int   c;
     char *p;
     static const struct option long_options[] = {
@@ -1452,30 +1446,14 @@ parse_options (int argc, char *argv[])
     };
     struct tm *now_tm;
 
-    /* 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("Text2pcap (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("Text2pcap (Wireshark)", NULL, NULL, NULL);
 
     /* Scan CLI parameters */
     while ((c = getopt_long(argc, argv, "aDdhqe:i:l:m:no:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) {
         switch (c) {
         case 'h':
-            printf("Text2pcap (Wireshark) %s\n"
-                   "Generate a capture file from an ASCII hexdump of packets.\n"
-                   "See https://www.wireshark.org for more information.\n",
-                   get_ws_vcs_version_info());
+            show_help_header("Generate a capture file from an ASCII hexdump of packets.");
             print_usage(stdout);
             exit(0);
             break;
@@ -1665,11 +1643,7 @@ parse_options (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("Text2pcap (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;
 
index 52f8fb13a43414a38d77ce5c1d67014673bf1afa..c84e7acf2fc84d3bbb0215ede1229ad9543498cd 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
@@ -34,7 +34,6 @@
 
 #include <wsutil/clopts_common.h>
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
@@ -228,7 +227,7 @@ glossary_option_help(void)
 
   output = stdout;
 
-  fprintf(output, "TFShark (Wireshark) %s\n", get_ws_vcs_version_info());
+  fprintf(output, "%s\n", get_appname_and_version());
 
   fprintf(output, "\n");
   fprintf(output, "Usage: tfshark -G [report]\n");
@@ -303,8 +302,6 @@ get_tfshark_runtime_version_info(GString *str)
 int
 real_main(int argc, char *argv[])
 {
-  GString             *comp_info_str;
-  GString             *runtime_info_str;
   char                *init_progfile_dir_error;
   int                  opt;
   static const struct option long_options[] = {
@@ -383,21 +380,10 @@ real_main(int argc, char *argv[])
 
   initialize_funnel_ops();
 
-  /* 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(get_tfshark_runtime_version_info);
-
-  /* Add it to the information to be reported on a crash. */
-  ws_add_crash_info("TFShark (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("TFShark (Wireshark)", NULL,
+                       epan_get_compiled_version_info,
+                       get_tfshark_runtime_version_info);
 
   /*
    * In order to have the -X opts assigned before the wslua machine starts
@@ -620,10 +606,7 @@ real_main(int argc, char *argv[])
       break;
 
     case 'h':        /* Print help and exit */
-      printf("TFShark (Wireshark) %s\n"
-             "Dump and analyze network traffic.\n"
-             "See https://www.wireshark.org for more information.\n",
-             get_ws_vcs_version_info());
+      show_help_header("Analyze file structure.");
       print_usage(stdout);
       goto clean_exit;
       break;
@@ -736,11 +719,7 @@ real_main(int argc, char *argv[])
       }
       break;
     case 'v':         /* Show version and exit */
-      comp_info_str = get_compiled_version_info(NULL, epan_get_compiled_version_info);
-      runtime_info_str = get_runtime_version_info(get_tfshark_runtime_version_info);
-      show_version("TFShark (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;
     case 'O':        /* Only output these protocols */
       /* already processed; just ignore it now */
index eb0304d0584558b5c6aab95a811b3aee41d52d4f..00c28db7818113fe0ceb01f7bee77a460d143330 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -47,7 +47,6 @@
 
 #include <wsutil/clopts_common.h>
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
@@ -475,7 +474,7 @@ glossary_option_help(void)
 
   output = stdout;
 
-  fprintf(output, "TShark (Wireshark) %s\n", get_ws_vcs_version_info());
+  fprintf(output, "%s\n", get_appname_and_version());
 
   fprintf(output, "\n");
   fprintf(output, "Usage: tshark -G [report]\n");
@@ -673,8 +672,6 @@ must_do_dissection(dfilter_t *rfcode, dfilter_t *dfcode,
 int
 real_main(int argc, char *argv[])
 {
-  GString             *comp_info_str;
-  GString             *runtime_info_str;
   char                *init_progfile_dir_error;
   int                  opt;
   static const struct option long_options[] = {
@@ -799,22 +796,10 @@ real_main(int argc, char *argv[])
 #endif /* HAVE_LIBPCAP */
 #endif /* _WIN32 */
 
-  /* Get the compile-time version information string */
-  comp_info_str = get_compiled_version_info(get_tshark_compiled_version_info,
-                                            epan_get_compiled_version_info);
-
-  /* Get the run-time version information string */
-  runtime_info_str = get_runtime_version_info(get_tshark_runtime_version_info);
-
-  /* Add it to the information to be reported on a crash. */
-  ws_add_crash_info("TShark (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("TShark (Wireshark)", get_tshark_compiled_version_info,
+                       epan_get_compiled_version_info,
+                       get_tshark_runtime_version_info);
 
   /* Fail sometimes. Useful for testing fuzz scripts. */
   /* if (g_random_int_range(0, 100) < 5) abort(); */
@@ -1188,10 +1173,7 @@ real_main(int argc, char *argv[])
       break;
 
     case 'h':        /* Print help and exit */
-      printf("TShark (Wireshark) %s\n"
-             "Dump and analyze network traffic.\n"
-             "See https://www.wireshark.org for more information.\n",
-             get_ws_vcs_version_info());
+      show_help_header("Dump and analyze network traffic.");
       print_usage(stdout);
       exit_status = EXIT_SUCCESS;
       goto clean_exit;
@@ -1370,12 +1352,7 @@ real_main(int argc, char *argv[])
         break;
     }
     case 'v':         /* Show version and exit */
-      comp_info_str = get_compiled_version_info(get_tshark_compiled_version_info,
-                                                epan_get_compiled_version_info);
-      runtime_info_str = get_runtime_version_info(get_tshark_runtime_version_info);
-      show_version("TShark (Wireshark)", comp_info_str, runtime_info_str);
-      g_string_free(comp_info_str, TRUE);
-      g_string_free(runtime_info_str, TRUE);
+      show_version();
       /* We don't really have to cleanup here, but it's a convenient way to test
        * start-up and shut-down of the epan library without any UI-specific
        * cruft getting in the way. Makes the results of running
@@ -3089,7 +3066,7 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
     /* If we don't have an application name add Tshark */
     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) {
         /* this is free'd by wtap_block_free() later */
-        wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "TShark (Wireshark) %s", get_ws_vcs_version_info());
+        wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "%s", get_appname_and_version());
     }
 
     tshark_debug("tshark: writing format type %d, to %s", out_file_type, save_file);
index 7c0768a0b599843c74d9b2eb3053edf93e1e0b3a..fc3c375a0384abb660675a2380c1ebb938859d59 100644 (file)
@@ -63,11 +63,8 @@ commandline_print_usage(gboolean for_help_option) {
 #endif
 
     if (for_help_option) {
+        show_help_header("Interactively dump and analyze network traffic.");
         output = stdout;
-        fprintf(output, "Wireshark %s\n"
-            "Interactively dump and analyze network traffic.\n"
-            "See https://www.wireshark.org for more information.\n",
-            get_ws_vcs_version_info());
     } else {
         output = stderr;
     }
@@ -204,8 +201,7 @@ static void print_no_capture_support_error(void)
 }
 #endif
 
-void commandline_early_options(int argc, char *argv[],
-    GString *comp_info_str, GString *runtime_info_str)
+void commandline_early_options(int argc, char *argv[])
 {
     int opt;
 #ifdef HAVE_LIBPCAP
@@ -305,7 +301,7 @@ void commandline_early_options(int argc, char *argv[],
 #ifdef _WIN32
                 create_console();
 #endif
-                show_version("Wireshark", comp_info_str, runtime_info_str);
+                show_version();
 #ifdef _WIN32
                 destroy_console();
 #endif
index e88b0e16f7a31019f3fe96fcba4a2d6fa70ca807..a93d6d6bcacd78e2e7f861b77730f8b131abc88f 100644 (file)
@@ -17,8 +17,7 @@ extern "C" {
 
 extern void commandline_print_usage(gboolean for_help_option);
 
-extern void commandline_early_options(int argc, char *argv[],
-    GString *comp_info_str, GString *runtime_info_str);
+extern void commandline_early_options(int argc, char *argv[]);
 
 /* Command-line options that don't have direct API calls to handle the data */
 typedef struct commandline_param_info
index 351f71985ea2a06d7811ac0de89219af28ac6557..a4c27a97fb1424db30aae1d8bf395bdf357c12d0 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <wsutil/clopts_common.h>
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/privileges.h>
 #ifdef HAVE_PLUGINS
@@ -380,8 +379,6 @@ int main(int argc, char *qt_argv[])
 #endif
 #endif
     gchar               *err_msg = NULL;
-    GString             *comp_info_str = NULL;
-    GString             *runtime_info_str = NULL;
 
     QString              dfilter, read_filter;
 #ifdef HAVE_LIBPCAP
@@ -496,11 +493,8 @@ int main(int argc, char *qt_argv[])
 #endif /* _WIN32 */
 
     /* Get the compile-time version information string */
-    comp_info_str = get_compiled_version_info(get_wireshark_qt_compiled_info,
-                                              get_gui_compiled_info);
-
-    /* Assemble the run-time version information string */
-    runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info);
+    ws_init_version_info("Wireshark", get_wireshark_qt_compiled_info,
+                         get_gui_compiled_info, get_wireshark_runtime_info);
 
     /* Create the user profiles directory */
     if (create_profiles_dir(&rf_path) == -1) {
@@ -522,7 +516,7 @@ int main(int argc, char *qt_argv[])
         g_free(rf_path);
     }
 
-    commandline_early_options(argc, argv, comp_info_str, runtime_info_str);
+    commandline_early_options(argc, argv);
 
 #ifdef _WIN32
     reset_library_path();
@@ -554,16 +548,6 @@ int main(int argc, char *qt_argv[])
     QString cf_name;
     unsigned int in_file_type = WTAP_TYPE_AUTO;
 
-    /* Add it to the information to be reported on a crash. */
-    ws_add_crash_info("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);
-
 #ifdef _WIN32
     /* Start windows sockets */
     result = WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
index 5b8165de7012eba4b06da91de3348b8110c0d985..25232f0452d95aa2c6527df75a2c9d8e22c0c22e 100644 (file)
@@ -119,7 +119,7 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
      * UTF-8 string containing the name of the application used to create
      * this section.
      */
-    wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
+    wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "%s", get_appname_and_version());
 
     /* Create fake IDB info */
     exp_pdu_tap_data->idb_inf = g_new(wtapng_iface_descriptions_t,1);
index 2b1008683eab7f4b705f3f218617952403e150b2..017135c46f2ebcf7dfe890c8f21232543de4f67f 100644 (file)
 #include <wsutil/cpu_info.h>
 #include <wsutil/copyright_info.h>
 #include <wsutil/os_version_info.h>
+#include <wsutil/crash_info.h>
 #include <wsutil/ws_printf.h> /* ws_debug_printf */
 #include <wsutil/plugins.h>
 
+static char *appname_with_version;
+static char *comp_info;
+static char *runtime_info;
+
+void
+ws_init_version_info(const char *appname,
+    void (*prepend_compile_time_info)(GString *),
+    void (*append_compile_time_info)(GString *),
+    void (*additional_run_time_info)(GString *))
+{
+       GString *comp_info_str, *runtime_info_str;
+
+       /*
+        * Combine the supplied application name string with the
+        * version - including the VCS version, for a build from
+        * a checkout.
+        */
+       appname_with_version = g_strdup_printf("%s %s",
+           appname, get_ws_vcs_version_info());
+
+       /* Get the compile-time version information string */
+       comp_info_str = get_compiled_version_info(prepend_compile_time_info,
+           append_compile_time_info);
+
+       /* Get the run-time version information string */
+       runtime_info_str = get_runtime_version_info(additional_run_time_info);
+
+       comp_info = g_string_free(comp_info_str, FALSE);
+       runtime_info = g_string_free(runtime_info_str, FALSE);
+
+       /* Add this information to the information to be reported on a crash. */
+       ws_add_crash_info("%s\n"
+           "\n"
+           "%s\n"
+           "%s",
+           appname_with_version, comp_info, runtime_info);
+}
+
+const char *
+get_appname_and_version(void)
+{
+       return appname_with_version;
+}
+
 /*
  * If the string doesn't end with a newline, append one.
  * Then word-wrap it to 80 columns.
@@ -413,21 +458,6 @@ get_runtime_version_info(void (*additional_info)(GString *))
        return str;
 }
 
-void
-show_version(const gchar *prog_name_str, GString *comp_info_str,
-            GString *runtime_info_str)
-{
-       ws_debug_printf("%s %s\n"
-              "\n"
-              "%s"
-              "\n"
-              "%s"
-              "\n"
-              "%s",
-              prog_name_str, get_ws_vcs_version_info(), get_copyright_info(),
-              comp_info_str->str, runtime_info_str->str);
-}
-
 /*
  * Return a version number string for Wireshark, including, for builds
  * from a tree checked out from Wireshark's version control system,
@@ -454,6 +484,27 @@ get_ws_version_number(int *major, int *minor, int *micro)
                *micro = VERSION_MICRO;
 }
 
+void
+show_version(void)
+{
+       ws_debug_printf("%s\n"
+              "\n"
+              "%s\n"
+              "%s\n"
+              "%s",
+              appname_with_version, get_copyright_info(),
+              comp_info, runtime_info);
+}
+
+void
+show_help_header(const char *description)
+{
+       ws_debug_printf("%s\n"
+               "%s\n"
+               "See https://www.wireshark.org for more information.\n",
+               appname_with_version, description);
+}
+
 /*
  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
  *
index 4dfb74fab227e8d7f1561b7328c67171ab68d715..92857a9f2a48ed71251cf79d886df010a39ac895 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
+/*
+ * Initialize information about the program for various purposes, including
+ * reporting the version and build information for the program, putting
+ * that information into crash dumps if possible, and giving the program
+ * name and version information into capture files written by the program
+ * if possible.
+ *
+ * "appname" is a string that appears at the beginning of the information;
+ * it should include the application name, followed by "(Wireshark)" if
+ * the program isn't Wireshark.
+ *
+ * "prepend_compile_time_info" is called at the start to prepend any
+ * additional build information before the standard library information.
+ *
+ * "append_compile_time_info" is called at the end to append any additional
+ * build information after the standard library information.  This is
+ * required in order to, for example, put Qt information at the
+ * end of the string, as we don't use Qt in TShark.
+ *
+ * "additional_info" is called at the end to append any additional
+ * run-time information; this is required in order to, for example,
+ * put the libcap information at the end of the string, as we currently
+ * don't use libcap in TShark.
+ */
+void ws_init_version_info(const char *appname,
+    void (*prepend_compile_time_info)(GString *),
+    void (*append_compile_time_info)(GString *),
+    void (*additional_run_time_info)(GString *));
+
+/*
+ * Get a string giving the application name, as provided to
+ * ws_init_version_info(), followed by a string giving the
+ * application version.
+ */
+const char *get_appname_and_version(void);
+
 /*
  * Get various library compile-time versions, put them in a GString,
  * and return the GString.
@@ -44,8 +80,6 @@ GString *get_compiled_version_info(void (*prepend_info)(GString *),
  */
 GString *get_runtime_version_info(void (*additional_info)(GString *));
 
-void show_version(const gchar *prog_name, GString *comp_info_str, GString *runtime_info_str);
-
 /*
  * Return a version number string for Wireshark, including, for builds
  * from a tree checked out from Wireshark's version control system,
@@ -58,6 +92,19 @@ const char *get_ws_vcs_version_info(void);
  */
 void get_ws_version_number(int *major, int *minor, int *micro);
 
+/*
+ * Show the program name and version number information on the standard
+ * output; this is used for command-line "show the version" options.
+ */
+void show_version(void);
+
+/*
+ * Show the program name and version number information, a supplied
+ * description string, and a "See {URL} for more information" message.
+ * This is used for command-line "help" options.
+ */
+void show_help_header(const char *description);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index fb9b3814b51366aab2c65dadb9ec244871f48a5a..533d79379b3d88736f8de517b8407767e78e0d9c 100644 (file)
@@ -858,7 +858,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
        * UTF-8 string containing the name of the application used to create
        * this section.
        */
-       wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
+       wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "%s", get_appname_and_version());
 
        /* Add header to the array */
        g_array_append_val(shb_hdrs, shb_hdr);