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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include <zlib.h> /* to get the libz version number */
38 #ifdef HAVE_SYS_UTSNAME_H
39 #include <sys/utsname.h>
42 #include "version_info.h"
43 #include "capture-pcap-util.h"
44 #include <wsutil/unicode-utils.h>
46 #include "svnversion.h"
52 #ifdef HAVE_OS_X_FRAMEWORKS
53 #include <CoreFoundation/CoreFoundation.h>
58 # include <sys/capability.h>
62 const char *wireshark_svnversion = " (" SVNVERSION " from " SVNPATH ")";
64 const char *wireshark_svnversion = "";
68 * If the string doesn't end with a newline, append one.
69 * Then word-wrap it to 80 columns.
72 end_string(GString *str)
78 if (point == 0 || str->str[point - 1] != '\n')
79 g_string_append(str, "\n");
85 * Break at or before this point.
88 while (q > p && *q != ' ')
98 * Get various library compile-time versions and append them to
99 * the specified GString.
101 * "additional_info" is called at the end to append any additional
102 * information; this is required in order to, for example, put the
103 * Portaudio information at the end of the string, as we currently
104 * don't use Portaudio in TShark.
107 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
108 void (*append_info)(GString *))
110 if (sizeof(str) == 4)
111 g_string_append(str, "(32-bit) ");
113 g_string_append(str, "(64-bit) ");
116 (*prepend_info)(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)");
129 g_string_append(str, ", ");
130 get_compiled_pcap_version(str);
133 g_string_append(str, ", ");
135 g_string_append(str, "with libz ");
137 g_string_append(str, ZLIB_VERSION);
138 #else /* ZLIB_VERSION */
139 g_string_append(str, "(version unknown)");
140 #endif /* ZLIB_VERSION */
141 #else /* HAVE_LIBZ */
142 g_string_append(str, "without libz");
143 #endif /* HAVE_LIBZ */
146 g_string_append(str, ", ");
148 g_string_append(str, "with POSIX capabilities");
149 #ifdef _LINUX_CAPABILITY_VERSION
150 g_string_append(str, " (Linux)");
151 #endif /* _LINUX_CAPABILITY_VERSION */
152 #else /* HAVE_LIBCAP */
153 g_string_append(str, "without POSIX capabilities");
154 #endif /* HAVE_LIBCAP */
157 g_string_append(str, ", ");
158 #if defined(HAVE_LIBNL1)
159 g_string_append(str, "with libnl 1");
160 #elif defined(HAVE_LIBNL2)
161 g_string_append(str, "with libnl 2");
162 #elif defined(HAVE_LIBNL3)
163 g_string_append(str, "with libnl 3");
165 g_string_append(str, "without libnl");
168 /* Additional application-dependent information */
171 g_string_append(str, ".");
177 typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
181 * Handles the rather elaborate process of getting OS version information
182 * from OS X (we want the OS X version, not the Darwin version, the latter
183 * being easy to get with uname()).
185 #ifdef HAVE_OS_X_FRAMEWORKS
188 * Fetch a string, as a UTF-8 C string, from a dictionary, given a key.
191 get_string_from_dictionary(CFPropertyListRef dict, CFStringRef key)
193 CFStringRef cfstring;
195 cfstring = CFDictionaryGetValue(dict, key);
196 if (cfstring == NULL)
198 if (CFGetTypeID(cfstring) != CFStringGetTypeID()) {
199 /* It isn't a string. Punt. */
202 return CFString_to_C_string(cfstring);
206 * Get the OS X version information, and append it to the GString.
207 * Return TRUE if we succeed, FALSE if we fail.
210 get_os_x_version_info(GString *str)
212 static const UInt8 server_version_plist_path[] =
213 "/System/Library/CoreServices/ServerVersion.plist";
214 static const UInt8 system_version_plist_path[] =
215 "/System/Library/CoreServices/SystemVersion.plist";
216 CFURLRef version_plist_file_url;
217 CFReadStreamRef version_plist_stream;
218 CFDictionaryRef version_dict;
222 * On OS X, report the OS X version number as the OS, and put
223 * the Darwin information in parentheses.
225 * Alas, Gestalt() is deprecated in Mountain Lion, so the build
226 * fails if you treat deprecation warnings as fatal. I don't
227 * know of any replacement API, so we fall back on reading
228 * /System/Library/CoreServices/ServerVersion.plist if it
229 * exists, otherwise /System/Library/CoreServices/SystemVersion.plist,
230 * and using ProductUserVisibleVersion. We also get the build
231 * version from ProductBuildVersion and the product name from
234 version_plist_file_url = CFURLCreateFromFileSystemRepresentation(NULL,
235 server_version_plist_path, sizeof server_version_plist_path - 1,
237 if (version_plist_file_url == NULL)
239 version_plist_stream = CFReadStreamCreateWithFile(NULL,
240 version_plist_file_url);
241 CFRelease(version_plist_file_url);
242 if (version_plist_stream == NULL)
244 if (!CFReadStreamOpen(version_plist_stream)) {
245 CFRelease(version_plist_stream);
248 * Try SystemVersion.plist.
250 version_plist_file_url = CFURLCreateFromFileSystemRepresentation(NULL,
251 system_version_plist_path, sizeof system_version_plist_path - 1,
253 if (version_plist_file_url == NULL)
255 version_plist_stream = CFReadStreamCreateWithFile(NULL,
256 version_plist_file_url);
257 CFRelease(version_plist_file_url);
258 if (version_plist_stream == NULL)
260 if (!CFReadStreamOpen(version_plist_stream)) {
261 CFRelease(version_plist_stream);
265 #ifdef HAVE_CFPROPERTYLISTCREATEWITHSTREAM
266 version_dict = CFPropertyListCreateWithStream(NULL,
267 version_plist_stream, 0, kCFPropertyListImmutable,
270 version_dict = CFPropertyListCreateFromStream(NULL,
271 version_plist_stream, 0, kCFPropertyListImmutable,
274 if (version_dict == NULL)
276 if (CFGetTypeID(version_dict) != CFDictionaryGetTypeID()) {
277 /* This is *supposed* to be a dictionary. Punt. */
278 CFRelease(version_dict);
279 CFReadStreamClose(version_plist_stream);
280 CFRelease(version_plist_stream);
283 /* Get the product name string. */
284 string = get_string_from_dictionary(version_dict,
285 CFSTR("ProductName"));
286 if (string == NULL) {
287 CFRelease(version_dict);
288 CFReadStreamClose(version_plist_stream);
289 CFRelease(version_plist_stream);
292 g_string_append_printf(str, "%s", string);
295 /* Get the OS version string. */
296 string = get_string_from_dictionary(version_dict,
297 CFSTR("ProductUserVisibleVersion"));
298 if (string == NULL) {
299 CFRelease(version_dict);
300 CFReadStreamClose(version_plist_stream);
301 CFRelease(version_plist_stream);
304 g_string_append_printf(str, " %s", string);
307 /* Get the build string */
308 string = get_string_from_dictionary(version_dict,
309 CFSTR("ProductBuildVersion"));
310 if (string == NULL) {
311 CFRelease(version_dict);
312 CFReadStreamClose(version_plist_stream);
313 CFRelease(version_plist_stream);
316 g_string_append_printf(str, ", build %s", string);
318 CFRelease(version_dict);
319 CFReadStreamClose(version_plist_stream);
320 CFRelease(version_plist_stream);
326 * Get the OS version, and append it to the GString
328 void get_os_version_info(GString *str)
331 OSVERSIONINFOEX info;
332 SYSTEM_INFO system_info;
333 nativesi_func_ptr nativesi_func;
334 #elif defined(HAVE_SYS_UTSNAME_H)
342 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
344 * for more than you ever wanted to know about determining the
345 * flavor of Windows on which you're running. Implementing more
346 * of that is left as an exercise to the reader - who should
347 * check any copyright information about code samples on MSDN
348 * before cutting and pasting into Wireshark.
350 * They should also note that you need an OSVERSIONINFOEX structure
351 * to get some of that information, and that not only is that
352 * structure not supported on older versions of Windows, you might
353 * not even be able to compile code that *uses* that structure with
354 * older versions of the SDK.
357 memset(&info, '\0', sizeof info);
358 info.dwOSVersionInfoSize = sizeof info;
359 if (!GetVersionEx((OSVERSIONINFO *)&info)) {
361 * XXX - get the failure reason.
363 g_string_append(str, "unknown Windows version");
367 memset(&system_info, '\0', sizeof system_info);
368 /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
369 * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
370 nativesi_func = (nativesi_func_ptr)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo");
372 nativesi_func(&system_info);
374 GetSystemInfo(&system_info);
376 switch (info.dwPlatformId) {
378 case VER_PLATFORM_WIN32s:
380 g_string_append_printf(str, "Windows 3.1 with Win32s");
383 case VER_PLATFORM_WIN32_WINDOWS:
385 switch (info.dwMajorVersion) {
388 /* 3 cheers for Microsoft marketing! */
389 switch (info.dwMinorVersion) {
392 g_string_append_printf(str, "Windows 95");
396 g_string_append_printf(str, "Windows 98");
400 g_string_append_printf(str, "Windows Me");
404 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
405 info.dwMajorVersion, info.dwMinorVersion);
411 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
412 info.dwMajorVersion, info.dwMinorVersion);
417 case VER_PLATFORM_WIN32_NT:
419 switch (info.dwMajorVersion) {
423 g_string_append_printf(str, "Windows NT %lu.%lu",
424 info.dwMajorVersion, info.dwMinorVersion);
428 /* 3 cheers for Microsoft marketing! */
429 switch (info.dwMinorVersion) {
432 g_string_append_printf(str, "Windows 2000");
436 g_string_append_printf(str, "Windows XP");
440 if ((info.wProductType == VER_NT_WORKSTATION) &&
441 (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
442 g_string_append_printf(str, "Windows XP Professional x64 Edition");
444 g_string_append_printf(str, "Windows Server 2003");
445 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
446 g_string_append_printf(str, " x64 Edition");
451 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
452 info.dwMajorVersion, info.dwMinorVersion);
458 gboolean is_nt_workstation;
460 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
461 g_string_append(str, "64-bit ");
462 else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
463 g_string_append(str, "32-bit ");
464 #ifndef VER_NT_WORKSTATION
465 #define VER_NT_WORKSTATION 0x01
466 is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
468 is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
470 switch (info.dwMinorVersion) {
472 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
475 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
478 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
479 info.dwMajorVersion, info.dwMinorVersion);
485 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
486 info.dwMajorVersion, info.dwMinorVersion);
488 } /* info.dwMajorVersion */
492 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
493 info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
496 if (info.szCSDVersion[0] != '\0')
497 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
498 g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
499 #elif defined(HAVE_SYS_UTSNAME_H)
501 * We have <sys/utsname.h>, so we assume we have "uname()".
503 if (uname(&name) < 0) {
504 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
509 if (strcmp(name.sysname, "AIX") == 0) {
511 * Yay, IBM! Thanks for doing something different
512 * from most of the other UNIXes out there, and
513 * making "name.version" apparently be the major
514 * version number and "name.release" be the minor
517 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
521 * XXX - get "version" on any other platforms?
523 * On Digital/Tru64 UNIX, it's something unknown.
524 * On Solaris, it's some kind of build information.
525 * On HP-UX, it appears to be some sort of subrevision
527 * On *BSD and Darwin/OS X, it's a long string giving
528 * a build date, config file name, etc., etc., etc..
530 #ifdef HAVE_OS_X_FRAMEWORKS
532 * On Mac OS X, report the Mac OS X version number as
533 * the OS version if we can, and put the Darwin information
536 if (get_os_x_version_info(str)) {
537 /* Success - append the Darwin information. */
538 g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
540 /* Failure - just use the Darwin information. */
541 g_string_append_printf(str, "%s %s", name.sysname, name.release);
543 #else /* HAVE_OS_X_FRAMEWORKS */
545 * XXX - on Linux, are there any APIs to get the distribution
546 * name and version number? I think some distributions have
549 * At least on Linux Standard Base-compliant distributions,
550 * there's an "lsb_release" command. However:
552 * http://forums.fedoraforum.org/showthread.php?t=220885
554 * seems to suggest that if you don't have the redhat-lsb
555 * package installed, you don't have lsb_release, and that
556 * /etc/fedora-release has the release information on
559 * http://linux.die.net/man/1/lsb_release
561 * suggests that there's an /etc/distrib-release file, but
562 * it doesn't indicate whether "distrib" is literally
563 * "distrib" or is the name for the distribution, and
564 * also speaks of an /etc/debian_version file.
566 * "lsb_release" apparently parses /etc/lsb-release, which
567 * has shell-style assignments, assigning to, among other
568 * values, DISTRIB_ID (distributor/distribution name),
569 * DISTRIB_RELEASE (release number of the distribution),
570 * DISTRIB_DESCRIPTION (*might* be name followed by version,
571 * but the manpage for lsb_release seems to indicate that's
572 * not guaranteed), and DISTRIB_CODENAME (code name, e.g.
573 * "licentious" for the Ubuntu Licentious Lemur release).
574 * the lsb_release man page also speaks of the distrib-release
575 * file, but Debian doesn't have one, and Ubuntu 7's
576 * lsb_release command doesn't look for one.
578 * I've seen references to /etc/redhat-release as well.
580 * At least on my Ubuntu 7 system, /etc/debian_version
581 * doesn't contain anything interesting (just some Debian
586 * http://bugs.python.org/issue1322
588 * http://www.novell.com/coolsolutions/feature/11251.html
590 * http://linuxmafia.com/faq/Admin/release-files.html
592 * and the Lib/Platform.py file in recent Python 2.x
595 g_string_append_printf(str, "%s %s", name.sysname, name.release);
596 #endif /* HAVE_OS_X_FRAMEWORKS */
599 g_string_append(str, "an unknown OS");
605 * Get various library run-time versions, and the OS version, and append
606 * them to the specified GString.
609 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
615 g_string_append(str, "on ");
617 get_os_version_info(str);
621 if ((lang = getenv ("LANG")) != NULL)
622 g_string_append_printf(str, ", with locale %s", lang);
624 g_string_append(str, ", without locale");
628 g_string_append(str, ", ");
629 get_runtime_pcap_version(str);
632 #if defined(HAVE_LIBZ) && !defined(_WIN32)
633 g_string_append_printf(str, ", with libz %s", zlibVersion());
636 /* Additional application-dependent information */
638 (*additional_info)(str);
640 g_string_append(str, ".");
645 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
646 * information on various defined strings.
648 * GCC's __VERSION__ is a nice text string for humans to
649 * read. The page at sourceforge.net largely describes
650 * numeric #defines that encode the version; if the compiler
651 * doesn't also offer a nice printable string, we try prettifying
652 * the number somehow.
654 #if defined(__GNUC__) && defined(__VERSION__)
656 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
657 * distinguish between them.
659 #if defined(__clang__)
660 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
661 #elif defined(__llvm__)
662 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
663 #else /* boring old GCC */
664 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
666 #elif defined(__HP_aCC)
667 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
668 #elif defined(__xlC__)
669 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
670 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
672 if ((__IBMC__ % 10) != 0)
673 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
674 #endif /* __IBMC__ */
675 g_string_append_printf(str, "\n");
676 #elif defined(__INTEL_COMPILER)
677 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
678 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
679 if ((__INTEL_COMPILER % 10) != 0)
680 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
681 #ifdef __INTEL_COMPILER_BUILD_DATE
682 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
683 __INTEL_COMPILER_BUILD_DATE / 10000,
684 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
685 __INTEL_COMPILER_BUILD_DATE % 100);
686 #endif /* __INTEL_COMPILER_BUILD_DATE */
687 g_string_append_printf(str, "\n");
688 #elif defined(_MSC_FULL_VER)
689 # if _MSC_FULL_VER > 99999999
690 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
691 (_MSC_FULL_VER / 10000000) - 6,
692 (_MSC_FULL_VER / 100000) % 100);
693 # if (_MSC_FULL_VER % 100000) != 0
694 g_string_append_printf(str, " build %d",
695 _MSC_FULL_VER % 100000);
698 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
699 (_MSC_FULL_VER / 1000000) - 6,
700 (_MSC_FULL_VER / 10000) % 100);
701 # if (_MSC_FULL_VER % 10000) != 0
702 g_string_append_printf(str, " build %d",
703 _MSC_FULL_VER % 10000);
706 g_string_append_printf(str, "\n");
707 #elif defined(_MSC_VER)
708 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
709 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
710 (_MSC_VER / 100) - 6, _MSC_VER % 100);
711 #elif defined(__SUNPRO_C)
712 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
713 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
714 if ((__SUNPRO_C & 0xF) != 0)
715 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
716 g_string_append_printf(str, "\n");
723 * Get copyright information.
726 get_copyright_info(void)
729 "Copyright 1998-2012 Gerald Combs <gerald@wireshark.org> and contributors.\n"
730 "This is free software; see the source for copying conditions. There is NO\n"
731 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
736 * Get the major OS version.
738 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
740 get_os_major_version()
743 info.dwOSVersionInfoSize = sizeof info;
744 if (GetVersionEx(&info)) {
745 return info.dwMajorVersion;
757 * indent-tabs-mode: t
760 * ex: set shiftwidth=8 tabstop=8 noexpandtab:
761 * :indentSize=8:tabSize=8:noTabs=false: