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"
22 #include <sys/types.h>
23 #include <sys/sysctl.h>
25 #include <sys/sysinfo.h>
36 //#include <zlib-ng.h>
39 #include "vcs_version.h"
41 #include <wsutil/cpu_info.h>
42 #include <wsutil/os_version_info.h>
43 #include <wsutil/crash_info.h>
44 #include <wsutil/plugins.h>
46 static char *appname_with_version
;
47 static char *copyright_info
;
48 static char *license_info
;
49 static char *comp_info
;
50 static char *runtime_info
;
52 static void end_string(GString
*str
);
53 static void get_compiler_info(GString
*str
);
54 static void get_mem_info(GString
*str
);
57 ws_init_version_info(const char *appname
,
58 gather_feature_func gather_compile
,
59 gather_feature_func gather_runtime
)
61 GString
*comp_info_str
, *runtime_info_str
;
62 GString
*copyright_info_str
;
63 GString
*license_info_str
;
65 copyright_info_str
= g_string_new(get_copyright_info());
66 end_string(copyright_info_str
);
67 copyright_info
= g_string_free(copyright_info_str
, FALSE
);
69 license_info_str
= g_string_new(get_license_info_short());
70 end_string(license_info_str
);
71 license_info
= g_string_free(license_info_str
, FALSE
);
74 * Combine the supplied application name string with the
75 * version - including the VCS version, for a build from
78 if (strstr(appname
, "Wireshark") != NULL
) {
79 appname_with_version
= ws_strdup_printf("%s %s",
80 appname
, get_ws_vcs_version_info());
83 appname_with_version
= ws_strdup_printf("%s (Wireshark) %s",
84 appname
, get_ws_vcs_version_info());
87 /* Get the compile-time version information string */
88 comp_info_str
= get_compiled_version_info(gather_compile
);
90 /* Get the run-time version information string */
91 runtime_info_str
= get_runtime_version_info(gather_runtime
);
93 comp_info
= g_string_free(comp_info_str
, FALSE
);
94 runtime_info
= g_string_free(runtime_info_str
, FALSE
);
96 /* Add this information to the information to be reported on a crash. */
97 ws_add_crash_info("%s\n"
101 appname_with_version
, comp_info
, runtime_info
);
105 * Take the gathered list of present/absent features (dependencies)
106 * and add them to the given string.
107 * Callback function for g_list_foreach() used in
108 * get_compiled_version_info() and get_runtime_version_info().
111 feature_to_gstring(void * data
, void * user_data
)
113 char *feature
= (char *)data
;
114 GString
*str
= (GString
*)user_data
;
116 g_string_append(str
, ", ");
118 g_string_append_printf(str
, "%s %s",
119 (*feature
== '+' ? "with" : "without"), feature
+ 1);
123 * If the string doesn't end with a newline, append one.
124 * Then word-wrap it to 80 columns.
127 end_string(GString
*str
)
133 if (point
== 0 || str
->str
[point
- 1] != '\n')
134 g_string_append(str
, "\n");
140 * Break at or before this point.
143 while (q
> p
&& *q
!= ' ')
153 get_appname_and_version(void)
155 return appname_with_version
;
159 gather_pcre2_compile_info(feature_list l
)
161 with_feature(l
, "PCRE2");
165 gather_zlib_compile_info(feature_list l
)
169 with_feature(l
, "zlib " ZLIB_VERSION
);
171 with_feature(l
, "zlib (version unknown)");
172 #endif /* ZLIB_VERSION */
174 without_feature(l
, "zlib");
175 #endif /* HAVE_ZLIB */
179 gather_zlib_ng_compile_info(feature_list l
)
182 with_feature(l
, "zlib-ng " ZLIBNG_VERSION_STRING
);
184 without_feature(l
, "zlib-ng");
185 #endif /* HAVE_ZLIB */
190 * Get various library compile-time versions, put them in a GString,
191 * and return the GString.
194 get_compiled_version_info(gather_feature_func gather_compile
)
199 str
= g_string_new("Compiled ");
200 g_string_append_printf(str
, "(%d-bit) ", (int)sizeof(str
) * 8);
203 g_string_append(str
, "using ");
204 get_compiler_info(str
);
206 #ifdef GLIB_MAJOR_VERSION
208 "GLib %d.%d.%d", GLIB_MAJOR_VERSION
, GLIB_MINOR_VERSION
,
212 "GLib (version unknown)");
215 if (gather_compile
!= NULL
) {
219 l
= g_list_reverse(l
);
220 g_list_foreach(l
, feature_to_gstring
, str
);
223 g_string_append(str
, ", with binary plugins");
225 g_string_append(str
, ", without binary plugins");
229 g_string_append(str
, ", debug build");
232 g_string_append(str
, ".");
240 get_mem_info(GString
*str
)
245 MEMORYSTATUSEX statex
;
247 statex
.dwLength
= sizeof (statex
);
249 if (GlobalMemoryStatusEx(&statex
))
250 memsize
= statex
.ullTotalPhys
;
252 size_t len
= sizeof(memsize
);
253 sysctlbyname("hw.memsize", &memsize
, &len
, NULL
, 0);
256 if (sysinfo(&info
) == 0)
257 memsize
= info
.totalram
* info
.mem_unit
;
261 g_string_append_printf(str
, ", with %" PRId64
" MB of physical memory", memsize
/(1024*1024));
265 * Get compiler information, and append it to the GString.
268 get_compiler_info(GString
*str
)
271 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
272 * information on various defined strings.
274 * GCC's __VERSION__ is a nice text string for humans to
275 * read. The page at sourceforge.net largely describes
276 * numeric #defines that encode the version; if the compiler
277 * doesn't also offer a nice printable string, we try prettifying
278 * the number somehow.
280 #if defined(_MSC_FULL_VER)
282 * We check for this first, as Microsoft have a version of their
283 * compiler that has Clang as the front end and their code generator
289 /* As of Wireshark 3.0, we support only Visual Studio 2015 (14.x)
292 * https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
293 * has a *large* table of Microsoft product names, VC++ versions,
294 * _MSC_VER values, and _MSC_FULL_VER values. All the versions
295 * we support define _MSC_FULL_VER. We don't bother trying to
296 * get the SP/update/version number from the build number, as
297 * we'd have to keep updating that with every update; there's no
298 * way to get that information directly from a predefine, and in
299 * some cases multiple updates/versions have the *same* build
300 * number (because they didn't update the toolchain).
302 * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
303 * defines the format of _MSC_VER and _MSC_FULL_VER. _MSC_FULL_VER
304 * is a decimal number of the form MMmmBBBBB, where MM is the compiler/
305 * toolchain major version, mm is the minor version, and BBBBB is the
306 * build. We break it down based on that.
308 #define COMPILER_MAJOR_VERSION (_MSC_FULL_VER / 10000000)
309 #define COMPILER_MINOR_VERSION ((_MSC_FULL_VER % 10000000) / 100000)
310 #define COMPILER_BUILD_NUMBER (_MSC_FULL_VER % 100000)
313 * From https://web.archive.org/web/20190125151548/https://blogs.msdn.microsoft.com/vcblog/2014/11/17/c111417-features-in-vs-2015-preview/
314 * Bakersfield: DevDiv's upper management determines the scheduling
315 * of new major versions. They also decided to increment the product
316 * version from 12 (for VS 2013) to 14 (for VS 2015). However, the
317 * C++ compiler's version incremented normally, from 18 to 19.
318 * (It's larger because the C++ compiler predates the "Visual" in
321 * So the product version number is 5 less than the compiler version
324 #define VCPP_MAJOR_VERSION (COMPILER_MAJOR_VERSION - 5)
326 #if VCPP_MAJOR_VERSION == 14
328 * From https://devblogs.microsoft.com/cppblog/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/
330 * We've been delivering improvements to Visual Studio 2017 more
331 * frequently than ever before. Since its first release in March
332 * we've released four major updates to VS2017 and are currently
333 * previewing the fifth update, VS2017 version 15.5.
335 * The MSVC toolset in VS2017 is built as a minor version update to
336 * the VS2015 compiler toolset. This minor version bump indicates
337 * that the VS2017 MSVC toolset is binary compatible with the VS2015
338 * MSVC toolset, enabling an easier upgrade for VS2015 users. Even
339 * though the MSVC compiler toolset in VS2017 delivers many new
340 * features and conformance improvements it is a minor version,
341 * compatible update from 14.00 in VS2015 to 14.10 in VS2017.
343 #if COMPILER_MINOR_VERSION < 10
344 #define VS_VERSION "2015"
345 #elif COMPILER_MINOR_VERSION < 20
346 #define VS_VERSION "2017"
347 #elif COMPILER_MINOR_VERSION < 30
348 #define VS_VERSION "2019"
350 #define VS_VERSION "2022"
354 * Add additional checks here, before the #else.
356 #define VS_VERSION "(unknown)"
357 #endif /* VCPP_MAJOR_VERSION */
360 * XXX - should we show the raw compiler version number, as is
361 * shown by "cl /?", which would be %d.%d.%d.%d with
362 * COMPILER_MAJOR_VERSION, COMPILER_MINOR_VERSION,
363 * COMPILER_BUILD_NUMBER, and _MSC_BUILD, the last of which is
364 * "the revision number element of the compiler's version number",
365 * which I guess is not to be confused with the build number,
366 * the _BUILD in the name nonwithstanding.
368 g_string_append_printf(str
, "Microsoft Visual Studio " VS_VERSION
" (VC++ %d.%d, build %d)",
369 VCPP_MAJOR_VERSION
, COMPILER_MINOR_VERSION
, COMPILER_BUILD_NUMBER
);
370 #if defined(__clang__)
374 g_string_append_printf(str
, " clang/C2 %s and -fno-ms-compatibility",
377 #elif defined(__GNUC__) && defined(__VERSION__)
379 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
380 * distinguish between them.
382 #if defined(__clang__)
384 char *version
; /* clang's version string has a trailing space. */
385 #if defined(__clang_version__)
386 version
= g_strdup(__clang_version__
);
387 g_string_append_printf(str
, "Clang %s", g_strstrip(version
));
389 version
= g_strdup(__VERSION__
);
390 g_string_append_printf(str
, "%s", g_strstrip(version
));
391 #endif /* __clang_version__ */
393 #elif defined(__llvm__)
395 g_string_append_printf(str
, "llvm-gcc %s", __VERSION__
);
398 g_string_append_printf(str
, "GCC %s", __VERSION__
);
400 #elif defined(__HP_aCC)
401 g_string_append_printf(str
, "HP aCC %d", __HP_aCC
);
402 #elif defined(__xlC__)
403 g_string_append_printf(str
, "IBM XL C %d.%d",
404 (__xlC__
>> 8) & 0xFF, __xlC__
& 0xFF);
406 if ((__IBMC__
% 10) != 0)
407 g_string_append_printf(str
, " patch %d", __IBMC__
% 10);
408 #endif /* __IBMC__ */
409 #elif defined(__INTEL_COMPILER)
410 g_string_append_printf(str
, "Intel C %d.%d",
411 __INTEL_COMPILER
/ 100, (__INTEL_COMPILER
/ 10) % 10);
412 if ((__INTEL_COMPILER
% 10) != 0)
413 g_string_append_printf(str
, " patch %d", __INTEL_COMPILER
% 10);
414 #ifdef __INTEL_COMPILER_BUILD_DATE
415 g_string_sprinta(str
, ", compiler built %04d-%02d-%02d",
416 __INTEL_COMPILER_BUILD_DATE
/ 10000,
417 (__INTEL_COMPILER_BUILD_DATE
/ 100) % 100,
418 __INTEL_COMPILER_BUILD_DATE
% 100);
419 #endif /* __INTEL_COMPILER_BUILD_DATE */
420 #elif defined(__SUNPRO_C)
421 g_string_append_printf(str
, "Sun C %d.%d",
422 (__SUNPRO_C
>> 8) & 0xF, (__SUNPRO_C
>> 4) & 0xF);
423 if ((__SUNPRO_C
& 0xF) != 0)
424 g_string_append_printf(str
, " patch %d", __SUNPRO_C
& 0xF);
426 g_string_append(str
, "unknown compiler");
431 gather_pcre2_runtime_info(feature_list l
)
433 /* From pcre2_api(3):
434 * The where argument should point to a buffer that is at least 24 code
435 * units long. (The exact length required can be found by calling
436 * pcre2_config() with where set to NULL.)
438 * The API should accept a buffer size as additional input. We could opt for a
439 * stack buffer size greater than 24 but let's just go with the weirdness...
444 size
= pcre2_config(PCRE2_CONFIG_VERSION
, NULL
);
445 if (size
< 0 || size
> 255) {
446 without_feature(l
, "PCRE2 (error querying)");
449 buf_pcre2
= g_malloc(size
+ 1);
450 pcre2_config(PCRE2_CONFIG_VERSION
, buf_pcre2
);
451 buf_pcre2
[size
] = '\0';
452 with_feature(l
, "PCRE2 %s", buf_pcre2
);
457 gather_zlib_runtime_info(feature_list l
)
460 #if defined(HAVE_ZLIB) && !defined(_WIN32)
461 with_feature(l
, "zlib %s", zlibVersion());
466 * Get various library run-time versions, and the OS version, and append
467 * them to the specified GString.
469 * "additional_info" is called at the end to append any additional
470 * information; this is required in order to, for example, put the
471 * libcap information at the end of the string, as we currently
472 * don't use libcap in TShark.
475 get_runtime_version_info(gather_feature_func gather_runtime
)
481 str
= g_string_new("Running on ");
483 get_os_version_info(str
);
488 /* Get info about installed memory */
491 with_feature(&l
, "GLib %u.%u.%u",
492 glib_major_version
, glib_minor_version
, glib_micro_version
);
494 if (gather_runtime
!= NULL
) {
498 l
= g_list_reverse(l
);
499 g_list_foreach(l
, feature_to_gstring
, str
);
502 * Display LC_CTYPE as a relevant, portable and sort of representative
503 * locale configuration without being exceedingly verbose and including
504 * the whole shebang of categories using LC_ALL.
506 if ((lc
= setlocale(LC_CTYPE
, NULL
)) != NULL
) {
507 g_string_append_printf(str
, ", with LC_TYPE=%s", lc
);
511 if (plugins_supported()) {
512 g_string_append(str
, ", binary plugins supported");
516 g_string_append_c(str
, '.');
524 * Return a version number string for Wireshark, including, for builds
525 * from a tree checked out from Wireshark's version control system,
526 * something identifying what version was checked out.
529 get_ws_vcs_version_info(void)
532 return VERSION
" (" VCS_VERSION
")";
539 get_ss_vcs_version_info(void)
542 return LOG_VERSION
" (" VCS_NUM_COMMITS
"-" VCS_COMMIT_ID
")";
549 get_ws_vcs_version_info_short(void)
559 get_ws_version_number(int *major
, int *minor
, int *micro
)
562 *major
= VERSION_MAJOR
;
564 *minor
= VERSION_MINOR
;
566 *micro
= VERSION_MICRO
;
577 appname_with_version
,
585 show_help_header(const char *description
)
587 printf("%s\n", appname_with_version
);
589 printf("%s\n", description
);
590 printf("See https://www.wireshark.org for more information.\n");
595 * Get copyright information.
598 get_copyright_info(void)
601 "Copyright 1998-2024 Gerald Combs <gerald@wireshark.org> and contributors.";
605 get_license_info_short(void)
608 "Licensed under the terms of the GNU General Public License (version 2 or later). "
609 "This is free software; see the file named COPYING in the distribution. "
610 "There is NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.";
614 get_license_info(void)
617 "This program is free software: you can redistribute it and/or modify "
618 "it under the terms of the GNU General Public License as published by "
619 "the Free Software Foundation, either version 2 of the License, or "
620 "(at your option) any later version. This program is distributed in the "
621 "hope that it will be useful, but WITHOUT ANY WARRANTY; without even "
622 "the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
623 "See the GNU General Public License for more details.";
627 * Editor modelines - https://www.wireshark.org/tools/modelines.html
632 * indent-tabs-mode: t
635 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
636 * :indentSize=8:tabSize=8:noTabs=false: