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
21 #include <sys/types.h>
22 #include <sys/sysctl.h>
24 #include <sys/sysinfo.h>
35 #include "version_info.h"
37 #include <wsutil/cpu_info.h>
38 #include <wsutil/copyright_info.h>
39 #include <wsutil/os_version_info.h>
40 #include <wsutil/ws_printf.h> /* ws_debug_printf */
41 #include <wsutil/plugins.h>
44 * If the string doesn't end with a newline, append one.
45 * Then word-wrap it to 80 columns.
48 end_string(GString *str)
54 if (point == 0 || str->str[point - 1] != '\n')
55 g_string_append(str, "\n");
61 * Break at or before this point.
64 while (q > p && *q != ' ')
74 get_zlib_compiled_version_info(void)
78 return "with zlib "ZLIB_VERSION;
80 return "with zlib (version unknown)";
81 #endif /* ZLIB_VERSION */
83 return "without zlib";
84 #endif /* HAVE_ZLIB */
88 * Get various library compile-time versions, put them in a GString,
89 * and return the GString.
91 * "prepend_info" is called at the start to prepend any additional
92 * information before the standard library information.
94 * "append_info" is called at the end to append any additional
95 * information after the standard library information. This is
96 * required in order to, for example, put Qt information at the
97 * end of the string, as we don't use Qt in TShark.
100 get_compiled_version_info(void (*prepend_info)(GString *),
101 void (*append_info)(GString *))
105 str = g_string_new("Compiled ");
107 if (sizeof(str) == 4)
108 g_string_append(str, "(32-bit) ");
110 g_string_append(str, "(64-bit) ");
113 (*prepend_info)(str);
114 g_string_append(str, ", ");
118 g_string_append(str, "with ");
119 g_string_append_printf(str,
120 #ifdef GLIB_MAJOR_VERSION
121 "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
124 "GLib (version unknown)");
127 g_string_append_printf(str, ", %s", get_zlib_compiled_version_info());
129 /* Additional application-dependent information */
132 g_string_append(str, ".");
140 get_mem_info(GString *str)
145 MEMORYSTATUSEX statex;
147 statex.dwLength = sizeof (statex);
149 if (GlobalMemoryStatusEx(&statex))
150 memsize = statex.ullTotalPhys;
152 size_t len = sizeof(memsize);
153 sysctlbyname("hw.memsize", &memsize, &len, NULL, 0);
156 if (sysinfo(&info) == 0)
157 memsize = info.totalram * info.mem_unit;
161 g_string_append_printf(str, ", with ""%" G_GINT64_MODIFIER "d" " MB of physical memory", memsize/(1024*1024));
165 * Get compiler information, and append it to the GString.
168 get_compiler_info(GString *str)
171 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
172 * information on various defined strings.
174 * GCC's __VERSION__ is a nice text string for humans to
175 * read. The page at sourceforge.net largely describes
176 * numeric #defines that encode the version; if the compiler
177 * doesn't also offer a nice printable string, we try prettifying
178 * the number somehow.
180 #if defined(_MSC_FULL_VER)
182 * We check for this first, as Microsoft have a version of their
183 * compiler that has Clang as the front end and their code generator
189 /* As of Wireshark 3.0, we support only Visual Studio 2015 (14.x)
192 * https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
193 * has a *large* table of Microsoft product names, VC++ versions,
194 * _MSC_VER values, and _MSC_FULL_VER values. All the versions
195 * we support define _MSC_FULL_VER. We don't bother trying to
196 * get the SP/update/version number from the build number, as
197 * we'd have to keep updating that with every update; there's no
198 * way to get that information directly from a predefine, and in
199 * some cases multiple updates/versions have the *same* build
200 * number (because they didn't update the toolchain).
202 * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
203 * defines the format of _MSC_VER and _MSC_FULL_VER. _MSC_FULL_VER
204 * is a decimal number of the form MMmmBBBBB, where MM is the compiler/
205 * toolchain major version, mm is the minor version, and BBBBB is the
206 * build. We break it down based on that.
208 #define COMPILER_MAJOR_VERSION (_MSC_FULL_VER / 10000000)
209 #define COMPILER_MINOR_VERSION ((_MSC_FULL_VER % 10000000) / 100000)
210 #define COMPILER_BUILD_NUMBER (_MSC_FULL_VER % 100000)
213 * From https://blogs.msdn.microsoft.com/vcblog/2014/11/17/c111417-features-in-vs-2015-preview/
215 * Bakersfield: DevDiv's upper management determines the scheduling
216 * of new major versions. They also decided to increment the product
217 * version from 12 (for VS 2013) to 14 (for VS 2015). However, the
218 * C++ compiler's version incremented normally, from 18 to 19.
219 * (It's larger because the C++ compiler predates the "Visual" in
222 * So the product version number is 5 less than the compiler version
225 #define VCPP_MAJOR_VERSION (COMPILER_MAJOR_VERSION - 5)
227 #if VCPP_MAJOR_VERSION == 14
229 * From https://blogs.msdn.microsoft.com/vcblog/2017/11/15/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/:
231 * We've been delivering improvements to Visual Studio 2017 more
232 * frequently than ever before. Since its first release in March
233 * we've released four major updates to VS2017 and are currently
234 * previewing the fifth update, VS2017 version 15.5.
236 * The MSVC toolset in VS2017 is built as a minor version update to
237 * the VS2015 compiler toolset. This minor version bump indicates
238 * that the VS2017 MSVC toolset is binary compatible with the VS2015
239 * MSVC toolset, enabling an easier upgrade for VS2015 users. Even
240 * though the MSVC compiler toolset in VS2017 delivers many new
241 * features and conformance improvements it is a minor version,
242 * compatible update from 14.00 in VS2015 to 14.10 in VS2017.
244 #if COMPILER_MINOR_VERSION < 10
245 #define VS_VERSION "2015"
247 #define VS_VERSION "2017"
251 * Add additional checks here, before the #else.
253 #define VS_VERSION "(unknown)"
254 #endif /* VCPP_MAJOR_VERSION */
257 * XXX - should we show the raw compiler version number, as is
258 * shown by "cl /?", which would be %d.%d.%d.%d with
259 * COMPILER_MAJOR_VERSION, COMPILER_MINOR_VERSION,
260 * COMPILER_BUILD_NUMBER, and _MSC_BUILD, the last of which is
261 * "the revision number element of the compiler's version number",
262 * which I guess is not to be confused with the build number,
263 * the _BUILD in the name nonwithstanding.
265 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual Studio " VS_VERSION " (VC++ %d.%d, build %d)",
266 VCPP_MAJOR_VERSION, COMPILER_MINOR_VERSION, COMPILER_BUILD_NUMBER);
267 #if defined(__clang__)
271 g_string_append_printf(str, " clang/C2 %s and -fno-ms-compatibility.\n",
274 g_string_append_printf(str, ".\n");
276 #elif defined(__GNUC__) && defined(__VERSION__)
278 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
279 * distinguish between them.
281 #if defined(__clang__)
283 * We know this isn't clang/C2, as _MSC_FULL_VER isn't defined.
285 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
286 #elif defined(__llvm__)
288 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
289 #else /* boring old GCC */
290 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
292 #elif defined(__HP_aCC)
293 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
294 #elif defined(__xlC__)
295 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
296 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
298 if ((__IBMC__ % 10) != 0)
299 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
300 #endif /* __IBMC__ */
301 g_string_append_printf(str, "\n");
302 #elif defined(__INTEL_COMPILER)
303 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
304 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
305 if ((__INTEL_COMPILER % 10) != 0)
306 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
307 #ifdef __INTEL_COMPILER_BUILD_DATE
308 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
309 __INTEL_COMPILER_BUILD_DATE / 10000,
310 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
311 __INTEL_COMPILER_BUILD_DATE % 100);
312 #endif /* __INTEL_COMPILER_BUILD_DATE */
313 g_string_append_printf(str, "\n");
314 #elif defined(__SUNPRO_C)
315 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
316 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
317 if ((__SUNPRO_C & 0xF) != 0)
318 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
319 g_string_append_printf(str, "\n");
323 /* XXX - is the setlocale() return string opaque? For glibc the separator is ';' */
330 lang = setlocale(LC_ALL, NULL);
335 locv = g_strsplit(lang, ";", -1);
336 loc = g_strjoinv(", ", locv);
342 * Get various library run-time versions, and the OS version, and append
343 * them to the specified GString.
345 * "additional_info" is called at the end to append any additional
346 * information; this is required in order to, for example, put the
347 * libcap information at the end of the string, as we currently
348 * don't use libcap in TShark.
351 get_runtime_version_info(void (*additional_info)(GString *))
356 str = g_string_new("Running on ");
358 get_os_version_info(str);
363 /* Get info about installed memory */
369 * This returns the C language's locale information; this
370 * returns the locale that's actually in effect, even if
371 * it doesn't happen to match the settings of any of the
372 * locale environment variables.
374 * On Windows get_locale returns the full language, country
375 * name, and code page, e.g. "English_United States.1252":
376 * https://msdn.microsoft.com/en-us/library/x99tb11d.aspx
378 if ((lang = get_locale()) != NULL) {
379 g_string_append_printf(str, ", with locale %s", lang);
383 g_string_append(str, ", with default locale");
387 /* Additional application-dependent information */
389 (*additional_info)(str);
392 #if defined(HAVE_ZLIB) && !defined(_WIN32)
393 g_string_append_printf(str, ", with zlib %s", zlibVersion());
398 if (g_module_supported()) {
399 g_string_append_printf(str, ", binary plugins supported (%d loaded)", plugins_get_count());
402 g_string_append(str, ", binary plugins not supported");
406 g_string_append(str, ".");
409 get_compiler_info(str);
417 show_version(const gchar *prog_name_str, GString *comp_info_str,
418 GString *runtime_info_str)
420 ws_debug_printf("%s %s\n"
427 prog_name_str, get_ws_vcs_version_info(), get_copyright_info(),
428 comp_info_str->str, runtime_info_str->str);
432 * Return a version number string for Wireshark, including, for builds
433 * from a tree checked out from Wireshark's version control system,
434 * something identifying what version was checked out.
437 get_ws_vcs_version_info(void)
440 return VERSION " (" VCSVERSION ")";
447 get_ws_version_number(int *major, int *minor, int *micro)
450 *major = VERSION_MAJOR;
452 *minor = VERSION_MINOR;
454 *micro = VERSION_MICRO;
458 * Editor modelines - http://www.wireshark.org/tools/modelines.html
463 * indent-tabs-mode: t
466 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
467 * :indentSize=8:tabSize=8:noTabs=false: