2 * Routines to report version information for stuff used by Wireshark
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <zlib.h> /* to get the libz version number */
40 #ifdef HAVE_SYS_UTSNAME_H
41 #include <sys/utsname.h>
44 #include "version_info.h"
45 #include "capture-pcap-util.h"
46 #include <wsutil/unicode-utils.h>
48 #include "svnversion.h"
54 #ifdef HAVE_OS_X_FRAMEWORKS
55 #include <CoreServices/CoreServices.h>
59 # include <sys/capability.h>
63 const char *wireshark_svnversion = " (" SVNVERSION " from " SVNPATH ")";
65 const char *wireshark_svnversion = "";
69 * If the string doesn't end with a newline, append one.
70 * Then word-wrap it to 80 columns.
73 end_string(GString *str)
79 if (point == 0 || str->str[point - 1] != '\n')
80 g_string_append(str, "\n");
86 * Break at or before this point.
89 while (q > p && *q != ' ')
99 * Get various library compile-time versions and append them to
100 * the specified GString.
102 * "additional_info" is called at the end to append any additional
103 * information; this is required in order to, for example, put the
104 * Portaudio information at the end of the string, as we currently
105 * don't use Portaudio in TShark.
108 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
109 void (*append_info)(GString *))
111 if (sizeof(str) == 4)
112 g_string_append(str, "(32-bit) ");
114 g_string_append(str, "(64-bit) ");
117 (*prepend_info)(str);
120 g_string_append(str, "with ");
121 g_string_append_printf(str,
122 #ifdef GLIB_MAJOR_VERSION
123 "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
126 "GLib (version unknown)");
130 g_string_append(str, ", ");
131 get_compiled_pcap_version(str);
134 g_string_append(str, ", ");
136 g_string_append(str, "with libz ");
138 g_string_append(str, ZLIB_VERSION);
139 #else /* ZLIB_VERSION */
140 g_string_append(str, "(version unknown)");
141 #endif /* ZLIB_VERSION */
142 #else /* HAVE_LIBZ */
143 g_string_append(str, "without libz");
144 #endif /* HAVE_LIBZ */
147 g_string_append(str, ", ");
149 g_string_append(str, "with POSIX capabilities");
150 #ifdef _LINUX_CAPABILITY_VERSION
151 g_string_append(str, " (Linux)");
152 #endif /* _LINUX_CAPABILITY_VERSION */
153 #else /* HAVE_LIBCAP */
154 g_string_append(str, "without POSIX capabilities");
155 #endif /* HAVE_LIBCAP */
157 /* Additional application-dependent information */
160 g_string_append(str, ".");
166 typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
170 * Get various library run-time versions, and the OS version, and append
171 * them to the specified GString.
174 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
177 OSVERSIONINFOEX info;
178 SYSTEM_INFO system_info;
179 nativesi_func_ptr nativesi_func;
180 #elif defined(HAVE_SYS_UTSNAME_H)
183 #if HAVE_OS_X_FRAMEWORKS
184 SInt32 macosx_ver, macosx_major_ver, macosx_minor_ver, macosx_bugfix_ver;
190 g_string_append(str, "on ");
196 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
198 * for more than you ever wanted to know about determining the
199 * flavor of Windows on which you're running. Implementing more
200 * of that is left as an exercise to the reader - who should
201 * check any copyright information about code samples on MSDN
202 * before cutting and pasting into Wireshark.
204 * They should also note that you need an OSVERSIONINFOEX structure
205 * to get some of that information, and that not only is that
206 * structure not supported on older versions of Windows, you might
207 * not even be able to compile code that *uses* that structure with
208 * older versions of the SDK.
211 memset(&info, '\0', sizeof info);
212 info.dwOSVersionInfoSize = sizeof info;
213 if (!GetVersionEx((OSVERSIONINFO *)&info)) {
215 * XXX - get the failure reason.
217 g_string_append(str, "unknown Windows version");
221 memset(&system_info, '\0', sizeof system_info);
222 /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
223 * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
224 nativesi_func = (nativesi_func_ptr)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo");
226 nativesi_func(&system_info);
228 GetSystemInfo(&system_info);
230 switch (info.dwPlatformId) {
232 case VER_PLATFORM_WIN32s:
234 g_string_append_printf(str, "Windows 3.1 with Win32s");
237 case VER_PLATFORM_WIN32_WINDOWS:
239 switch (info.dwMajorVersion) {
242 /* 3 cheers for Microsoft marketing! */
243 switch (info.dwMinorVersion) {
246 g_string_append_printf(str, "Windows 95");
250 g_string_append_printf(str, "Windows 98");
254 g_string_append_printf(str, "Windows Me");
258 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
259 info.dwMajorVersion, info.dwMinorVersion);
265 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
266 info.dwMajorVersion, info.dwMinorVersion);
271 case VER_PLATFORM_WIN32_NT:
273 switch (info.dwMajorVersion) {
277 g_string_append_printf(str, "Windows NT %lu.%lu",
278 info.dwMajorVersion, info.dwMinorVersion);
282 /* 3 cheers for Microsoft marketing! */
283 switch (info.dwMinorVersion) {
286 g_string_append_printf(str, "Windows 2000");
290 g_string_append_printf(str, "Windows XP");
294 if ((info.wProductType == VER_NT_WORKSTATION) &&
295 (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
296 g_string_append_printf(str, "Windows XP Professional x64 Edition");
298 g_string_append_printf(str, "Windows Server 2003");
299 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
300 g_string_append_printf(str, " x64 Edition");
305 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
306 info.dwMajorVersion, info.dwMinorVersion);
312 gboolean is_nt_workstation;
314 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
315 g_string_append(str, "64-bit ");
316 else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
317 g_string_append(str, "32-bit ");
318 #ifndef VER_NT_WORKSTATION
319 #define VER_NT_WORKSTATION 0x01
320 is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
322 is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
324 switch (info.dwMinorVersion) {
326 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
329 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
332 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
333 info.dwMajorVersion, info.dwMinorVersion);
339 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
340 info.dwMajorVersion, info.dwMinorVersion);
342 } /* info.dwMajorVersion */
346 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
347 info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
350 if (info.szCSDVersion[0] != '\0')
351 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
352 g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
353 #elif defined(HAVE_SYS_UTSNAME_H)
355 * We have <sys/utsname.h>, so we assume we have "uname()".
357 if (uname(&name) < 0) {
358 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
363 if (strcmp(name.sysname, "AIX") == 0) {
365 * Yay, IBM! Thanks for doing something different
366 * from most of the other UNIXes out there, and
367 * making "name.version" apparently be the major
368 * version number and "name.release" be the minor
371 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
375 * XXX - get "version" on any other platforms?
377 * On Digital/Tru64 UNIX, it's something unknown.
378 * On Solaris, it's some kind of build information.
379 * On HP-UX, it appears to be some sort of subrevision
381 * On *BSD and Darwin/OS X, it's a long string giving
382 * a build date, config file name, etc., etc., etc..
384 #ifdef HAVE_OS_X_FRAMEWORKS
386 * On Mac OS X, report the Mac OS X version number as
387 * the OS, and put the Darwin information in parentheses.
389 * XXX - can we get the build name? There's no API to
390 * get it; it's currently in
391 * /System/Library/CoreServices/SystemVersion.plist
392 * but there's no guarantee that it will continue to
395 Gestalt(gestaltSystemVersion, &macosx_ver);
397 /* The following functions are only available in Mac OS 10.4+ */
398 if(macosx_ver >= 0x1040) {
399 Gestalt(gestaltSystemVersionMajor, &macosx_major_ver);
400 Gestalt(gestaltSystemVersionMinor, &macosx_minor_ver);
401 Gestalt(gestaltSystemVersionBugFix, &macosx_bugfix_ver);
403 g_string_append_printf(str, "Mac OS %ld.%ld.%ld",
404 (long)macosx_major_ver,
405 (long)macosx_minor_ver,
406 (long)macosx_bugfix_ver);
408 g_string_append_printf(str, "Mac OS X < 10.4 [%lx]",
410 /* See Apple's Gestalt Manager Reference for meanings
411 * of the macosx_ver values. */
413 g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
414 #else /* HAVE_OS_X_FRAMEWORKS */
416 * XXX - on Linux, are there any APIs to get the distribution
417 * name and version number? I think some distributions have
420 * At least on Linux Standard Base-compliant distributions,
421 * there's an "lsb_release" command. However:
423 * http://forums.fedoraforum.org/showthread.php?t=220885
425 * seems to suggest that if you don't have the redhat-lsb
426 * package installed, you don't have lsb_release, and that
427 * /etc/fedora-release has the release information on
430 * http://linux.die.net/man/1/lsb_release
432 * suggests that there's an /etc/distrib-release file, but
433 * it doesn't indicate whether "distrib" is literally
434 * "distrib" or is the name for the distribution, and
435 * also speaks of an /etc/debian_version file.
437 * "lsb_release" apparently parses /etc/lsb-release, which
438 * has shell-style assignments, assigning to, among other
439 * values, DISTRIB_ID (distributor/distribution name),
440 * DISTRIB_RELEASE (release number of the distribution),
441 * DISTRIB_DESCRIPTION (*might* be name followed by version,
442 * but the manpage for lsb_release seems to indicate that's
443 * not guaranteed), and DISTRIB_CODENAME (code name, e.g.
444 * "licentious" for the Ubuntu Licentious Lemur release).
445 * the lsb_release man page also speaks of the distrib-release
446 * file, but Debian doesn't have one, and Ubuntu 7's
447 * lsb_release command doesn't look for one.
449 * I've seen references to /etc/redhat-release as well.
451 * At least on my Ubuntu 7 system, /etc/debian_version
452 * doesn't contain anything interesting (just some Debian
457 * http://bugs.python.org/issue1322
459 * http://www.novell.com/coolsolutions/feature/11251.html
461 * http://linuxmafia.com/faq/Admin/release-files.html
463 * and the Lib/Platform.py file in recent Python 2.x
466 g_string_append_printf(str, "%s %s", name.sysname, name.release);
467 #endif /* HAVE_OS_X_FRAMEWORKS */
470 g_string_append(str, "an unknown OS");
475 if ((lang = getenv ("LANG")) != NULL)
476 g_string_append_printf(str, ", with locale %s", lang);
478 g_string_append(str, ", without locale");
482 g_string_append(str, ", ");
483 get_runtime_pcap_version(str);
486 #if defined(HAVE_LIBZ) && !defined(_WIN32)
487 g_string_append_printf(str, ", with libz %s", zlibVersion());
490 /* Additional application-dependent information */
492 (*additional_info)(str);
494 g_string_append(str, ".");
499 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
500 * information on various defined strings.
502 * GCC's __VERSION__ is a nice text string for humans to
503 * read. The page at sourceforge.net largely describes
504 * numeric #defines that encode the version; if the compiler
505 * doesn't also offer a nice printable string, we try prettifying
506 * the number somehow.
508 #if defined(__GNUC__) && defined(__VERSION__)
510 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
511 * distinguish between them.
513 #if defined(__clang__)
514 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
515 #elif defined(__llvm__)
516 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
517 #else /* boring old GCC */
518 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
520 #elif defined(__HP_aCC)
521 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
522 #elif defined(__xlC__)
523 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
524 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
526 if ((__IBMC__ % 10) != 0)
527 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
528 #endif /* __IBMC__ */
529 g_string_append_printf(str, "\n");
530 #elif defined(__INTEL_COMPILER)
531 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
532 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
533 if ((__INTEL_COMPILER % 10) != 0)
534 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
535 #ifdef __INTEL_COMPILER_BUILD_DATE
536 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
537 __INTEL_COMPILER_BUILD_DATE / 10000,
538 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
539 __INTEL_COMPILER_BUILD_DATE % 100);
540 #endif /* __INTEL_COMPILER_BUILD_DATE */
541 g_string_append_printf(str, "\n");
542 #elif defined(_MSC_FULL_VER)
543 # if _MSC_FULL_VER > 99999999
544 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
545 (_MSC_FULL_VER / 10000000) - 6,
546 (_MSC_FULL_VER / 100000) % 100);
547 # if (_MSC_FULL_VER % 100000) != 0
548 g_string_append_printf(str, " build %d",
549 _MSC_FULL_VER % 100000);
552 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
553 (_MSC_FULL_VER / 1000000) - 6,
554 (_MSC_FULL_VER / 10000) % 100);
555 # if (_MSC_FULL_VER % 10000) != 0
556 g_string_append_printf(str, " build %d",
557 _MSC_FULL_VER % 10000);
560 g_string_append_printf(str, "\n");
561 #elif defined(_MSC_VER)
562 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
563 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
564 (_MSC_VER / 100) - 6, _MSC_VER % 100);
565 #elif defined(__SUNPRO_C)
566 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
567 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
568 if ((__SUNPRO_C & 0xF) != 0)
569 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
570 g_string_append_printf(str, "\n");
577 * Get copyright information.
580 get_copyright_info(void)
583 "Copyright 1998-2011 Gerald Combs <gerald@wireshark.org> and contributors.\n"
584 "This is free software; see the source for copying conditions. There is NO\n"
585 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
590 * Get the major OS version.
592 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
594 get_os_major_version()
597 info.dwOSVersionInfoSize = sizeof info;
598 if (GetVersionEx(&info)) {
599 return info.dwMajorVersion;
611 * indent-tabs-mode: t
614 * ex: set shiftwidth=8 tabstop=8 noexpandtab:
615 * :indentSize=8:tabSize=8:noTabs=false: