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 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42 #include <wsutil/ws_version_info.h>
44 #include <wsutil/ws_cpuid.h>
45 #include <wsutil/copyright_info.h>
46 #include <wsutil/os_version_info.h>
49 * If the string doesn't end with a newline, append one.
50 * Then word-wrap it to 80 columns.
53 end_string(GString *str)
59 if (point == 0 || str->str[point - 1] != '\n')
60 g_string_append(str, "\n");
66 * Break at or before this point.
69 while (q > p && *q != ' ')
79 get_zlib_compiled_version_info(void)
83 return "with zlib "ZLIB_VERSION;
85 return "with zlib (version unknown)";
86 #endif /* ZLIB_VERSION */
88 return "without zlib";
89 #endif /* HAVE_ZLIB */
93 * Get various library compile-time versions, put them in a GString,
94 * and return the GString.
96 * "prepend_info" is called at the start to prepend any additional
97 * information before the standard library information.
99 * "append_info" is called at the end to append any additional
100 * information after the standard library information. This is
101 * required in order to, for example, put the Portaudio information
102 * at the end of the string, as we currently don't use Portaudio in
106 get_compiled_version_info(void (*prepend_info)(GString *),
107 void (*append_info)(GString *))
111 str = g_string_new("Compiled ");
113 if (sizeof(str) == 4)
114 g_string_append(str, "(32-bit) ");
116 g_string_append(str, "(64-bit) ");
119 (*prepend_info)(str);
120 g_string_append(str, ", ");
124 g_string_append(str, "with ");
125 g_string_append_printf(str,
126 #ifdef GLIB_MAJOR_VERSION
127 "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
130 "GLib (version unknown)");
133 g_string_append_printf(str, ", %s", get_zlib_compiled_version_info());
135 /* Additional application-dependent information */
138 g_string_append(str, ".");
146 * Get the CPU info, and append it to the GString
149 get_cpu_info(GString *str)
152 char CPUBrandString[0x40];
155 /* http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx */
157 /* Calling __cpuid with 0x80000000 as the InfoType argument*/
158 /* gets the number of valid extended IDs.*/
159 if (!ws_cpuid(CPUInfo, 0x80000000))
163 if( nExIds<0x80000005)
165 memset(CPUBrandString, 0, sizeof(CPUBrandString));
167 /* Interpret CPU brand string.*/
168 ws_cpuid(CPUInfo, 0x80000002);
169 memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
170 ws_cpuid(CPUInfo, 0x80000003);
171 memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
172 ws_cpuid(CPUInfo, 0x80000004);
173 memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
175 g_string_append_printf(str, "\n%s", CPUBrandString);
177 if (ws_cpuid_sse42())
178 g_string_append(str, " (with SSE4.2)");
182 get_mem_info(GString *str _U_)
185 MEMORYSTATUSEX statex;
187 statex.dwLength = sizeof (statex);
189 if (GlobalMemoryStatusEx(&statex))
190 g_string_append_printf(str, ", with ""%" G_GINT64_MODIFIER "d" "MB of physical memory.\n", statex.ullTotalPhys/(1024*1024));
195 * Get compiler information, and append it to the GString.
198 get_compiler_info(GString *str)
201 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
202 * information on various defined strings.
204 * GCC's __VERSION__ is a nice text string for humans to
205 * read. The page at sourceforge.net largely describes
206 * numeric #defines that encode the version; if the compiler
207 * doesn't also offer a nice printable string, we try prettifying
208 * the number somehow.
210 #if defined(__GNUC__) && defined(__VERSION__)
212 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
213 * distinguish between them.
215 #if defined(__clang__)
216 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
217 #elif defined(__llvm__)
218 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
219 #else /* boring old GCC */
220 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
222 #elif defined(__HP_aCC)
223 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
224 #elif defined(__xlC__)
225 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
226 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
228 if ((__IBMC__ % 10) != 0)
229 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
230 #endif /* __IBMC__ */
231 g_string_append_printf(str, "\n");
232 #elif defined(__INTEL_COMPILER)
233 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
234 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
235 if ((__INTEL_COMPILER % 10) != 0)
236 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
237 #ifdef __INTEL_COMPILER_BUILD_DATE
238 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
239 __INTEL_COMPILER_BUILD_DATE / 10000,
240 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
241 __INTEL_COMPILER_BUILD_DATE % 100);
242 #endif /* __INTEL_COMPILER_BUILD_DATE */
243 g_string_append_printf(str, "\n");
244 #elif defined(_MSC_FULL_VER)
245 # if _MSC_FULL_VER > 99999999
246 /* Quote from the web:
247 * Bakersfield: DevDiv's upper management determines the scheduling of new major versions.
248 * They also decided to increment the product version from 12 (for VS 2013) to 14 (for VS 2015).
249 * However, the C++ compiler's version incremented normally, from 18 to 19.
250 * (It's larger because the C++ compiler predates the "Visual" in Visual C++.)
251 * XXX? Should we just output the compiler version?
253 int compiler_major_version = (_MSC_FULL_VER / 10000000), visual_studio_ver;
255 if (compiler_major_version < 19) {
256 visual_studio_ver = compiler_major_version - 6;
258 visual_studio_ver = compiler_major_version - 5;
261 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
263 (_MSC_FULL_VER / 100000) % 100);
264 # if (_MSC_FULL_VER % 100000) != 0
265 g_string_append_printf(str, " build %d",
266 _MSC_FULL_VER % 100000);
269 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
270 (_MSC_FULL_VER / 1000000) - 6,
271 (_MSC_FULL_VER / 10000) % 100);
272 # if (_MSC_FULL_VER % 10000) != 0
273 g_string_append_printf(str, " build %d",
274 _MSC_FULL_VER % 10000);
277 g_string_append_printf(str, "\n");
278 #elif defined(_MSC_VER)
279 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
280 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
281 (_MSC_VER / 100) - 6, _MSC_VER % 100);
282 #elif defined(__SUNPRO_C)
283 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
284 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
285 if ((__SUNPRO_C & 0xF) != 0)
286 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
287 g_string_append_printf(str, "\n");
291 /* XXX - is the setlocale() return string opaque? For glibc the separator is ';' */
298 lang = setlocale(LC_ALL, NULL);
303 locv = g_strsplit(lang, ";", -1);
304 loc = g_strjoinv(", ", locv);
310 * Get various library run-time versions, and the OS version, and append
311 * them to the specified GString.
313 * "additional_info" is called at the end to append any additional
314 * information; this is required in order to, for example, put the
315 * Portaudio information at the end of the string, as we currently
316 * don't use Portaudio in TShark.
319 get_runtime_version_info(void (*additional_info)(GString *))
324 str = g_string_new("Running on ");
326 get_os_version_info(str);
331 * This returns the C language's locale information; this
332 * returns the locale that's actually in effect, even if
333 * it doesn't happen to match the settings of any of the
334 * locale environment variables.
336 * XXX - what happens on Windows? If nobody's explicitly
337 * overridden any of the environment variables, does this
338 * reflect the locale settings in the OS? If so, does
339 * that include the code page? (We're not using UTF-16
340 * for output to files or the console; using code page
341 * 65001, i.e. UTF-8, as your system code page probably
342 * works best with Wireshark.)
344 if ((lang = get_locale()) != NULL) {
345 g_string_append_printf(str, ", with locale %s", lang);
349 g_string_append(str, ", with default locale");
353 /* Additional application-dependent information */
355 (*additional_info)(str);
358 #if defined(HAVE_ZLIB) && !defined(_WIN32)
359 g_string_append_printf(str, ", with zlib %s", zlibVersion());
362 g_string_append(str, ".");
367 /* Get info about installed memory Windows only */
371 get_compiler_info(str);
379 show_version(const gchar *prog_name_str, GString *comp_info_str,
380 GString *runtime_info_str)
389 prog_name_str, get_ws_vcs_version_info(), get_copyright_info(),
390 comp_info_str->str, runtime_info_str->str);
394 * Return a version number string for Wireshark, including, for builds
395 * from a tree checked out from Wireshark's version control system,
396 * something identifying what version was checked out.
399 get_ws_vcs_version_info(void)
402 return VERSION " (" VCSVERSION " from " VCSBRANCH ")";
409 * Editor modelines - http://www.wireshark.org/tools/modelines.html
414 * indent-tabs-mode: t
417 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
418 * :indentSize=8:tabSize=8:noTabs=false: