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 the Portaudio information
97 * at the end of the string, as we currently don't use Portaudio in
101 get_compiled_version_info(void (*prepend_info)(GString *),
102 void (*append_info)(GString *))
106 str = g_string_new("Compiled ");
108 if (sizeof(str) == 4)
109 g_string_append(str, "(32-bit) ");
111 g_string_append(str, "(64-bit) ");
114 (*prepend_info)(str);
115 g_string_append(str, ", ");
119 g_string_append(str, "with ");
120 g_string_append_printf(str,
121 #ifdef GLIB_MAJOR_VERSION
122 "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
125 "GLib (version unknown)");
128 g_string_append_printf(str, ", %s", get_zlib_compiled_version_info());
130 /* Additional application-dependent information */
133 g_string_append(str, ".");
141 get_mem_info(GString *str)
146 MEMORYSTATUSEX statex;
148 statex.dwLength = sizeof (statex);
150 if (GlobalMemoryStatusEx(&statex))
151 memsize = statex.ullTotalPhys;
153 size_t len = sizeof(memsize);
154 sysctlbyname("hw.memsize", &memsize, &len, NULL, 0);
157 if (sysinfo(&info) == 0)
158 memsize = info.totalram * info.mem_unit;
162 g_string_append_printf(str, ", with ""%" G_GINT64_MODIFIER "d" " MB of physical memory", memsize/(1024*1024));
166 * Get compiler information, and append it to the GString.
169 get_compiler_info(GString *str)
172 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
173 * information on various defined strings.
175 * GCC's __VERSION__ is a nice text string for humans to
176 * read. The page at sourceforge.net largely describes
177 * numeric #defines that encode the version; if the compiler
178 * doesn't also offer a nice printable string, we try prettifying
179 * the number somehow.
181 #if defined(__GNUC__) && defined(__VERSION__)
183 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
184 * distinguish between them.
186 #if defined(__clang__)
187 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
188 #elif defined(__llvm__)
189 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
190 #else /* boring old GCC */
191 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
193 #elif defined(__HP_aCC)
194 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
195 #elif defined(__xlC__)
196 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
197 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
199 if ((__IBMC__ % 10) != 0)
200 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
201 #endif /* __IBMC__ */
202 g_string_append_printf(str, "\n");
203 #elif defined(__INTEL_COMPILER)
204 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
205 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
206 if ((__INTEL_COMPILER % 10) != 0)
207 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
208 #ifdef __INTEL_COMPILER_BUILD_DATE
209 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
210 __INTEL_COMPILER_BUILD_DATE / 10000,
211 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
212 __INTEL_COMPILER_BUILD_DATE % 100);
213 #endif /* __INTEL_COMPILER_BUILD_DATE */
214 g_string_append_printf(str, "\n");
215 #elif defined(_MSC_FULL_VER)
216 # if _MSC_FULL_VER > 99999999
217 /* Quote from the web:
218 * Bakersfield: DevDiv's upper management determines the scheduling of new major versions.
219 * They also decided to increment the product version from 12 (for VS 2013) to 14 (for VS 2015).
220 * However, the C++ compiler's version incremented normally, from 18 to 19.
221 * (It's larger because the C++ compiler predates the "Visual" in Visual C++.)
222 * XXX? Should we just output the compiler version?
224 int compiler_major_version = (_MSC_FULL_VER / 10000000), visual_studio_ver;
226 if (compiler_major_version < 19) {
227 visual_studio_ver = compiler_major_version - 6;
229 visual_studio_ver = compiler_major_version - 5;
232 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
234 (_MSC_FULL_VER / 100000) % 100);
235 # if (_MSC_FULL_VER % 100000) != 0
236 g_string_append_printf(str, " build %d",
237 _MSC_FULL_VER % 100000);
240 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
241 (_MSC_FULL_VER / 1000000) - 6,
242 (_MSC_FULL_VER / 10000) % 100);
243 # if (_MSC_FULL_VER % 10000) != 0
244 g_string_append_printf(str, " build %d",
245 _MSC_FULL_VER % 10000);
248 g_string_append_printf(str, "\n");
249 #elif defined(_MSC_VER)
250 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
251 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
252 (_MSC_VER / 100) - 6, _MSC_VER % 100);
253 #elif defined(__SUNPRO_C)
254 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
255 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
256 if ((__SUNPRO_C & 0xF) != 0)
257 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
258 g_string_append_printf(str, "\n");
262 /* XXX - is the setlocale() return string opaque? For glibc the separator is ';' */
269 lang = setlocale(LC_ALL, NULL);
274 locv = g_strsplit(lang, ";", -1);
275 loc = g_strjoinv(", ", locv);
281 * Get various library run-time versions, and the OS version, and append
282 * them to the specified GString.
284 * "additional_info" is called at the end to append any additional
285 * information; this is required in order to, for example, put the
286 * Portaudio information at the end of the string, as we currently
287 * don't use Portaudio in TShark.
290 get_runtime_version_info(void (*additional_info)(GString *))
295 str = g_string_new("Running on ");
297 get_os_version_info(str);
302 /* Get info about installed memory */
308 * This returns the C language's locale information; this
309 * returns the locale that's actually in effect, even if
310 * it doesn't happen to match the settings of any of the
311 * locale environment variables.
313 * On Windows get_locale returns the full language, country
314 * name, and code page, e.g. "English_United States.1252":
315 * https://msdn.microsoft.com/en-us/library/x99tb11d.aspx
317 if ((lang = get_locale()) != NULL) {
318 g_string_append_printf(str, ", with locale %s", lang);
322 g_string_append(str, ", with default locale");
326 /* Additional application-dependent information */
328 (*additional_info)(str);
331 #if defined(HAVE_ZLIB) && !defined(_WIN32)
332 g_string_append_printf(str, ", with zlib %s", zlibVersion());
337 if (g_module_supported()) {
338 g_string_append_printf(str, ", binary plugins supported (%d loaded)", plugins_get_count());
341 g_string_append(str, ", binary plugins not supported");
345 g_string_append(str, ".");
348 get_compiler_info(str);
356 show_version(const gchar *prog_name_str, GString *comp_info_str,
357 GString *runtime_info_str)
359 ws_debug_printf("%s %s\n"
366 prog_name_str, get_ws_vcs_version_info(), get_copyright_info(),
367 comp_info_str->str, runtime_info_str->str);
371 * Return a version number string for Wireshark, including, for builds
372 * from a tree checked out from Wireshark's version control system,
373 * something identifying what version was checked out.
376 get_ws_vcs_version_info(void)
379 return VERSION " (" VCSVERSION ")";
386 get_ws_version_number(int *major, int *minor, int *micro)
389 *major = VERSION_MAJOR;
391 *minor = VERSION_MINOR;
393 *micro = VERSION_MICRO;
397 * Editor modelines - http://www.wireshark.org/tools/modelines.html
402 * indent-tabs-mode: t
405 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
406 * :indentSize=8:tabSize=8:noTabs=false: