2 * Routines to report version information for Wireshark programs
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "version_info.h"
21 #include <sys/types.h>
22 #include <sys/sysctl.h>
24 #include <sys/sysinfo.h>
36 //#include <zlib-ng.h>
39 #include "vcs_version.h"
41 #include <wsutil/application_flavor.h>
42 #include <wsutil/cpu_info.h>
43 #include <wsutil/os_version_info.h>
44 #include <wsutil/crash_info.h>
45 #include <wsutil/plugins.h>
47 static char *appname_with_version
;
48 static char *copyright_info
;
49 static char *license_info
;
50 static char *comp_info
;
51 static char *runtime_info
;
53 static void end_string(GString
*str
);
54 static void get_compiler_info(GString
*str
);
55 static void get_mem_info(GString
*str
);
58 ws_init_version_info(const char *appname
,
59 gather_feature_func gather_compile
,
60 gather_feature_func gather_runtime
)
62 GString
*comp_info_str
, *runtime_info_str
;
63 GString
*copyright_info_str
;
64 GString
*license_info_str
;
66 copyright_info_str
= g_string_new(get_copyright_info());
67 end_string(copyright_info_str
);
68 copyright_info
= g_string_free(copyright_info_str
, FALSE
);
70 license_info_str
= g_string_new(get_license_info_short());
71 end_string(license_info_str
);
72 license_info
= g_string_free(license_info_str
, FALSE
);
75 * Combine the supplied application name string with the
76 * version - including the VCS version, for a build from
79 if (strstr(appname
, application_flavor_name_proper()) != NULL
) {
80 appname_with_version
= ws_strdup_printf("%s %s",
81 appname
, get_ws_vcs_version_info());
83 /* Include our application flavor. The default is "Wireshark" */
85 appname_with_version
= ws_strdup_printf("%s (%s) %s",
86 appname
, application_flavor_name_proper(), get_ws_vcs_version_info());
89 /* Get the compile-time version information string */
90 comp_info_str
= get_compiled_version_info(gather_compile
);
92 /* Get the run-time version information string */
93 runtime_info_str
= get_runtime_version_info(gather_runtime
);
95 comp_info
= g_string_free(comp_info_str
, FALSE
);
96 runtime_info
= g_string_free(runtime_info_str
, FALSE
);
98 /* Add this information to the information to be reported on a crash. */
99 ws_add_crash_info("%s\n"
103 appname_with_version
, comp_info
, runtime_info
);
107 * Used below in features_to_columns()
110 rtrim_gstring(GString
*str
)
112 gsize end
= str
->len
- 1; // get to 0-based offset
113 while(str
->str
[end
] == ' ') {
116 end
++; // return to 1-based length
117 if (end
< str
->len
) {
118 g_string_truncate(str
, end
);
123 * Take the list of features, and format it into a number of vertical
124 * columns, presented in column-major order. Calculates the number of
125 * columns based on the length of the longest list item.
128 features_to_columns(feature_list l
, GString
*str
)
130 const uint8_t linelen
= 85; // Same value used in end_string() +10
131 const uint8_t linepad
= 2; // left-side padding
132 uint8_t ncols
= 0; // number of columns to show
133 uint8_t maxlen
= 0; // length of longest item
134 unsigned num
= 0; // number of items in list
139 num
= g_list_length(*l
);
143 a
= g_ptr_array_sized_new(num
);
144 for (iter
= *l
; iter
!= NULL
; iter
= iter
->next
) {
145 c
= (gchar
*)iter
->data
;
146 maxlen
= MAX(maxlen
, (uint8_t)strlen(c
));
147 g_ptr_array_add(a
, iter
->data
);
149 maxlen
+= 2; // allow space between columns
150 ncols
= (linelen
- linepad
) / maxlen
;
151 if (ncols
<= 1 || num
<= 1) {
152 for (iter
= *l
; iter
!= NULL
; iter
= iter
->next
) {
153 c
= (gchar
*)iter
->data
;
154 g_string_append_printf(str
, "%*s%s\n", linepad
, "", c
);
158 uint8_t nrows
= (num
+ ncols
- 1) / ncols
;
160 for (i
= 0; i
< nrows
; i
++) {
161 g_string_append_printf(str
, "%*s", linepad
, "");
162 for (j
= 0; j
< ncols
; j
++) {
163 unsigned idx
= i
+ (j
* nrows
);
165 g_string_append_printf(str
, "%-*s", maxlen
, (gchar
*)g_ptr_array_index(a
, idx
));
169 g_string_append(str
, "\n");
172 g_ptr_array_free(a
, TRUE
);
176 * If the string doesn't end with a newline, append one.
177 * Then word-wrap it to 80 columns.
180 end_string(GString
*str
)
186 if (point
== 0 || str
->str
[point
- 1] != '\n')
187 g_string_append(str
, "\n");
193 * Break at or before this point.
196 while (q
> p
&& *q
!= ' ')
206 get_appname_and_version(void)
208 return appname_with_version
;
212 gather_pcre2_compile_info(feature_list l
)
214 #define PCRE2_DATE_QUOTE(str) #str
215 #define PCRE2_DATE_EXPAND_AND_QUOTE(str) PCRE2_DATE_QUOTE(str)
217 * PCRE2_PRERELEASE appears to be empty for a regular release;
218 * I don't know what it is for a pre-release.
220 with_feature(l
, "PCRE2 %u.%u %s", PCRE2_MAJOR
, PCRE2_MINOR
, PCRE2_DATE_EXPAND_AND_QUOTE(PCRE2_DATE
));
224 gather_zlib_compile_info(feature_list l
)
228 with_feature(l
, "zlib " ZLIB_VERSION
);
230 with_feature(l
, "zlib (version unknown)");
231 #endif /* ZLIB_VERSION */
233 without_feature(l
, "zlib");
234 #endif /* HAVE_ZLIB */
238 gather_zlib_ng_compile_info(feature_list l
)
241 with_feature(l
, "zlib-ng " ZLIBNG_VERSION_STRING
);
243 without_feature(l
, "zlib-ng");
244 #endif /* HAVE_ZLIB */
249 * Get various library compile-time versions, put them in a GString,
250 * and return the GString.
253 get_compiled_version_info(gather_feature_func gather_compile
)
256 GList
*l
= NULL
, *with_list
= NULL
, *without_list
= NULL
;
258 str
= g_string_new("Compile-time info:\n");
259 g_string_append_printf(str
, " Bit width: %d-bit\n", (int)sizeof(str
) * 8);
262 g_string_append_printf(str
, " Compiler: ");
263 get_compiler_info(str
);
265 #ifdef GLIB_MAJOR_VERSION
266 g_string_append_printf(str
,
267 " GLib: %d.%d.%d", GLIB_MAJOR_VERSION
, GLIB_MINOR_VERSION
,
270 g_string_append(str
, " GLib: version unknown");
272 #ifdef WS_DISABLE_DEBUG
273 g_string_append(str
, ", release build");
275 #ifdef WS_DISABLE_ASSERT
276 g_string_append(str
, ", without assertions");
278 g_string_append(str
, "\n");
280 if (gather_compile
!= NULL
) {
285 separate_features(&l
, &with_list
, &without_list
);
288 g_string_append(str
, " With:\n");
289 features_to_columns(&with_list
, str
);
290 free_features(&with_list
);
291 if (without_list
!= NULL
) {
292 g_string_append(str
, " Without:\n");
293 features_to_columns(&without_list
, str
);
294 free_features(&without_list
);
302 get_mem_info(GString
*str
)
307 MEMORYSTATUSEX statex
;
309 statex
.dwLength
= sizeof (statex
);
311 if (GlobalMemoryStatusEx(&statex
))
312 memsize
= statex
.ullTotalPhys
;
314 size_t len
= sizeof(memsize
);
315 sysctlbyname("hw.memsize", &memsize
, &len
, NULL
, 0);
318 if (sysinfo(&info
) == 0)
319 memsize
= info
.totalram
* info
.mem_unit
;
323 g_string_append_printf(str
, "%" G_GINT64_FORMAT
" MB of physical memory", memsize
/(1024*1024));
327 * Get compiler information, and append it to the GString.
330 get_compiler_info(GString
*str
)
333 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
334 * information on various defined strings.
336 * GCC's __VERSION__ is a nice text string for humans to
337 * read. The page at sourceforge.net largely describes
338 * numeric #defines that encode the version; if the compiler
339 * doesn't also offer a nice printable string, we try prettifying
340 * the number somehow.
342 #if defined(_MSC_FULL_VER)
344 * We check for this first, as Microsoft have a version of their
345 * compiler that has Clang as the front end and their code generator
351 /* As of Wireshark 3.0, we support only Visual Studio 2015 (14.x)
354 * https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
355 * has a *large* table of Microsoft product names, VC++ versions,
356 * _MSC_VER values, and _MSC_FULL_VER values. All the versions
357 * we support define _MSC_FULL_VER. We don't bother trying to
358 * get the SP/update/version number from the build number, as
359 * we'd have to keep updating that with every update; there's no
360 * way to get that information directly from a predefine, and in
361 * some cases multiple updates/versions have the *same* build
362 * number (because they didn't update the toolchain).
364 * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
365 * defines the format of _MSC_VER and _MSC_FULL_VER. _MSC_FULL_VER
366 * is a decimal number of the form MMmmBBBBB, where MM is the compiler/
367 * toolchain major version, mm is the minor version, and BBBBB is the
368 * build. We break it down based on that.
370 #define COMPILER_MAJOR_VERSION (_MSC_FULL_VER / 10000000)
371 #define COMPILER_MINOR_VERSION ((_MSC_FULL_VER % 10000000) / 100000)
372 #define COMPILER_BUILD_NUMBER (_MSC_FULL_VER % 100000)
375 * From https://web.archive.org/web/20190125151548/https://blogs.msdn.microsoft.com/vcblog/2014/11/17/c111417-features-in-vs-2015-preview/
376 * Bakersfield: DevDiv's upper management determines the scheduling
377 * of new major versions. They also decided to increment the product
378 * version from 12 (for VS 2013) to 14 (for VS 2015). However, the
379 * C++ compiler's version incremented normally, from 18 to 19.
380 * (It's larger because the C++ compiler predates the "Visual" in
383 * So the product version number is 5 less than the compiler version
386 #define VCPP_MAJOR_VERSION (COMPILER_MAJOR_VERSION - 5)
388 #if VCPP_MAJOR_VERSION == 14
390 * From https://devblogs.microsoft.com/cppblog/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/
392 * We've been delivering improvements to Visual Studio 2017 more
393 * frequently than ever before. Since its first release in March
394 * we've released four major updates to VS2017 and are currently
395 * previewing the fifth update, VS2017 version 15.5.
397 * The MSVC toolset in VS2017 is built as a minor version update to
398 * the VS2015 compiler toolset. This minor version bump indicates
399 * that the VS2017 MSVC toolset is binary compatible with the VS2015
400 * MSVC toolset, enabling an easier upgrade for VS2015 users. Even
401 * though the MSVC compiler toolset in VS2017 delivers many new
402 * features and conformance improvements it is a minor version,
403 * compatible update from 14.00 in VS2015 to 14.10 in VS2017.
405 #if COMPILER_MINOR_VERSION < 10
406 #define VS_VERSION "2015"
407 #elif COMPILER_MINOR_VERSION < 20
408 #define VS_VERSION "2017"
409 #elif COMPILER_MINOR_VERSION < 30
410 #define VS_VERSION "2019"
412 #define VS_VERSION "2022"
416 * Add additional checks here, before the #else.
418 #define VS_VERSION "(unknown)"
419 #endif /* VCPP_MAJOR_VERSION */
422 * XXX - should we show the raw compiler version number, as is
423 * shown by "cl /?", which would be %d.%d.%d.%d with
424 * COMPILER_MAJOR_VERSION, COMPILER_MINOR_VERSION,
425 * COMPILER_BUILD_NUMBER, and _MSC_BUILD, the last of which is
426 * "the revision number element of the compiler's version number",
427 * which I guess is not to be confused with the build number,
428 * the _BUILD in the name nonwithstanding.
430 g_string_append_printf(str
, "Microsoft Visual Studio " VS_VERSION
" (VC++ %d.%d, build %d)",
431 VCPP_MAJOR_VERSION
, COMPILER_MINOR_VERSION
, COMPILER_BUILD_NUMBER
);
432 #if defined(__clang__)
436 g_string_append_printf(str
, " clang/C2 %s and -fno-ms-compatibility",
439 #elif defined(__GNUC__) && defined(__VERSION__)
441 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
442 * distinguish between them.
444 #if defined(__clang__)
446 char *version
; /* clang's version string has a trailing space. */
447 #if defined(__clang_version__)
448 version
= g_strdup(__clang_version__
);
449 g_string_append_printf(str
, "Clang %s", g_strstrip(version
));
451 version
= g_strdup(__VERSION__
);
452 g_string_append_printf(str
, "%s", g_strstrip(version
));
453 #endif /* __clang_version__ */
455 #elif defined(__llvm__)
457 g_string_append_printf(str
, "llvm-gcc %s", __VERSION__
);
460 g_string_append_printf(str
, "GCC %s", __VERSION__
);
462 #elif defined(__HP_aCC)
463 g_string_append_printf(str
, "HP aCC %d", __HP_aCC
);
464 #elif defined(__xlC__)
465 g_string_append_printf(str
, "IBM XL C %d.%d",
466 (__xlC__
>> 8) & 0xFF, __xlC__
& 0xFF);
468 if ((__IBMC__
% 10) != 0)
469 g_string_append_printf(str
, " patch %d", __IBMC__
% 10);
470 #endif /* __IBMC__ */
471 #elif defined(__INTEL_COMPILER)
472 g_string_append_printf(str
, "Intel C %d.%d",
473 __INTEL_COMPILER
/ 100, (__INTEL_COMPILER
/ 10) % 10);
474 if ((__INTEL_COMPILER
% 10) != 0)
475 g_string_append_printf(str
, " patch %d", __INTEL_COMPILER
% 10);
476 #ifdef __INTEL_COMPILER_BUILD_DATE
477 g_string_sprinta(str
, ", compiler built %04d-%02d-%02d",
478 __INTEL_COMPILER_BUILD_DATE
/ 10000,
479 (__INTEL_COMPILER_BUILD_DATE
/ 100) % 100,
480 __INTEL_COMPILER_BUILD_DATE
% 100);
481 #endif /* __INTEL_COMPILER_BUILD_DATE */
482 #elif defined(__SUNPRO_C)
483 g_string_append_printf(str
, "Sun C %d.%d",
484 (__SUNPRO_C
>> 8) & 0xF, (__SUNPRO_C
>> 4) & 0xF);
485 if ((__SUNPRO_C
& 0xF) != 0)
486 g_string_append_printf(str
, " patch %d", __SUNPRO_C
& 0xF);
488 g_string_append(str
, "unknown compiler");
490 g_string_append(str
, "\n");
494 gather_pcre2_runtime_info(feature_list l
)
496 /* From pcre2_api(3):
497 * The where argument should point to a buffer that is at least 24 code
498 * units long. (The exact length required can be found by calling
499 * pcre2_config() with where set to NULL.)
501 * The API should accept a buffer size as additional input. We could opt for a
502 * stack buffer size greater than 24 but let's just go with the weirdness...
507 size
= pcre2_config(PCRE2_CONFIG_VERSION
, NULL
);
508 if (size
< 0 || size
> 255) {
509 without_feature(l
, "PCRE2 (error querying)");
512 buf_pcre2
= g_malloc(size
+ 1);
513 pcre2_config(PCRE2_CONFIG_VERSION
, buf_pcre2
);
514 buf_pcre2
[size
] = '\0';
515 with_feature(l
, "PCRE2 %s", buf_pcre2
);
520 gather_zlib_runtime_info(feature_list l
)
523 #if defined(HAVE_ZLIB) && !defined(_WIN32)
524 with_feature(l
, "zlib %s", zlibVersion());
529 * Get various library run-time versions, and the OS version, and append
530 * them to the specified GString.
532 * "additional_info" is called at the end to append any additional
533 * information; this is required in order to, for example, put the
534 * libcap information at the end of the string, as we currently
535 * don't use libcap in TShark.
538 get_runtime_version_info(gather_feature_func gather_runtime
)
542 GList
*l
= NULL
, *with_list
= NULL
, *without_list
= NULL
;
544 str
= g_string_new("Runtime info:\n OS: ");
545 get_os_version_info(str
);
548 g_string_append(str
, "\n CPU: ");
551 /* Get info about installed memory */
552 g_string_append(str
, "\n Memory: ");
555 g_string_append_printf(str
, "\n GLib: %u.%u.%u\n",
556 glib_major_version
, glib_minor_version
, glib_micro_version
);
558 * Display LC_CTYPE as a relevant, portable and sort of representative
559 * locale configuration without being exceedingly verbose and including
560 * the whole shebang of categories using LC_ALL.
562 if ((lc
= setlocale(LC_CTYPE
, NULL
)) != NULL
) {
563 g_string_append_printf(str
, " Locale: LC_TYPE=%s\n", lc
);
566 if (g_module_supported()) {
567 g_string_append_printf(str
, " Plugins: supported, %d loaded\n", plugins_get_count());
570 g_string_append(str
, " Plugins: not supported by platform\n");
573 g_string_append(str
, " Plugins: disabled at compile time\n");
576 if (gather_runtime
!= NULL
) {
581 separate_features(&l
, &with_list
, &without_list
);
584 g_string_append(str
, " With:\n");
585 features_to_columns(&with_list
, str
);
586 free_features(&with_list
);
587 if (without_list
!= NULL
) {
588 g_string_append(str
, " Without:\n");
589 features_to_columns(&without_list
, str
);
590 free_features(&without_list
);
598 * Return a version number string for Wireshark, including, for builds
599 * from a tree checked out from Wireshark's version control system,
600 * something identifying what version was checked out.
603 get_ws_vcs_version_info(void)
606 return VERSION
" (" VCS_VERSION
")";
613 get_ss_vcs_version_info(void)
616 return LOG_VERSION
" (" VCS_NUM_COMMITS
"-" VCS_COMMIT_ID
")";
623 get_ws_vcs_version_info_short(void)
633 get_ws_version_number(int *major
, int *minor
, int *micro
)
636 *major
= VERSION_MAJOR
;
638 *minor
= VERSION_MINOR
;
640 *micro
= VERSION_MICRO
;
651 appname_with_version
,
659 show_help_header(const char *description
)
661 printf("%s\n", appname_with_version
);
663 printf("%s\n", description
);
664 printf("See https://www.wireshark.org for more information.\n");
669 * Get copyright information.
672 get_copyright_info(void)
675 "Copyright 1998-2024 Gerald Combs <gerald@wireshark.org> and contributors.";
679 get_license_info_short(void)
682 "Licensed under the terms of the GNU General Public License (version 2 or later). "
683 "This is free software; see the file named COPYING in the distribution. "
684 "There is NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.";
688 get_license_info(void)
691 "This program is free software: you can redistribute it and/or modify "
692 "it under the terms of the GNU General Public License as published by "
693 "the Free Software Foundation, either version 2 of the License, or "
694 "(at your option) any later version. This program is distributed in the "
695 "hope that it will be useful, but WITHOUT ANY WARRANTY; without even "
696 "the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
697 "See the GNU General Public License for more details.";
701 * Editor modelines - https://www.wireshark.org/tools/modelines.html
706 * indent-tabs-mode: t
709 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
710 * :indentSize=8:tabSize=8:noTabs=false: