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.
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 <CoreFoundation/CoreFoundation.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 */
158 g_string_append(str, ", ");
159 #if defined(HAVE_LIBNL1)
160 g_string_append(str, "with libnl 1");
161 #elif defined(HAVE_LIBNL2)
162 g_string_append(str, "with libnl 2");
163 #elif defined(HAVE_LIBNL3)
164 g_string_append(str, "with libnl 3");
166 g_string_append(str, "without libnl");
169 /* Additional application-dependent information */
172 g_string_append(str, ".");
178 typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
182 * Handles the rather elaborate process of getting OS version information
183 * from OS X (we want the OS X version, not the Darwin version, the latter
184 * being easy to get with uname()).
186 #ifdef HAVE_OS_X_FRAMEWORKS
189 * Fetch a string, as a UTF-8 C string, from a dictionary, given a key.
192 get_string_from_dictionary(CFPropertyListRef dict, CFStringRef key)
194 CFStringRef cfstring;
198 cfstring = CFDictionaryGetValue(dict, key);
199 if (cfstring == NULL)
201 if (CFGetTypeID(cfstring) != CFStringGetTypeID()) {
202 /* It isn't a string. Punt. */
205 string_len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstring),
206 kCFStringEncodingUTF8);
207 string = g_malloc(string_len + 1);
208 if (!CFStringGetCString(cfstring, string, string_len + 1,
209 kCFStringEncodingUTF8)) {
217 * Get the OS X version information, and append it to the GString.
218 * Return TRUE if we succeed, FALSE if we fail.
221 get_os_x_version_info(GString *str)
223 static const char system_version_plist_path[] =
224 "/System/Library/CoreServices/SystemVersion.plist";
225 CFURLRef system_version_plist_file_url;
226 CFReadStreamRef system_version_plist_stream;
227 CFDictionaryRef system_version_dict;
231 * On OS X, report the OS X version number as the OS, and put
232 * the Darwin information in parentheses.
234 * Alas, Gestalt() is deprecated in Mountain Lion, so the build
235 * fails if you treat deprecation warnings as fatal. I don't
236 * know of any replacement API, so we fall back on reading
237 * /System/Library/CoreServices/SystemVersion.plist
238 * and using ProductUserVisibleVersion. We also get the build
239 * version from ProductBuildVersion.
241 * XXX - on OS X Server, do we need to read the server plist in
242 * /System/Library/CoreServices/ServerVersion.plist - i.e., if
243 * it exists, use it rather than SystemVersion.plist?
245 system_version_plist_file_url = CFURLCreateFromFileSystemRepresentation(NULL,
246 system_version_plist_path, sizeof system_version_plist_path - 1,
248 if (system_version_plist_file_url == NULL)
250 system_version_plist_stream = CFReadStreamCreateWithFile(NULL,
251 system_version_plist_file_url);
252 CFRelease(system_version_plist_file_url);
253 if (system_version_plist_stream == NULL)
255 if (!CFReadStreamOpen(system_version_plist_stream)) {
256 CFRelease(system_version_plist_stream);
259 #ifdef HAVE_CFPROPERTYLISTCREATEWITHSTREAM
260 system_version_dict = CFPropertyListCreateWithStream(NULL,
261 system_version_plist_stream, 0, kCFPropertyListImmutable,
264 system_version_dict = CFPropertyListCreateFromStream(NULL,
265 system_version_plist_stream, 0, kCFPropertyListImmutable,
268 if (system_version_dict == NULL)
270 if (CFGetTypeID(system_version_dict) != CFDictionaryGetTypeID()) {
271 /* This is *supposed* to be a dictionary. Punt. */
272 CFRelease(system_version_dict);
273 CFReadStreamClose(system_version_plist_stream);
274 CFRelease(system_version_plist_stream);
277 /* Get the OS version string. */
278 string = get_string_from_dictionary(system_version_dict,
279 CFSTR("ProductUserVisibleVersion"));
280 if (string == NULL) {
281 CFRelease(system_version_dict);
282 CFReadStreamClose(system_version_plist_stream);
283 CFRelease(system_version_plist_stream);
286 g_string_append_printf(str, "OS X %s", string);
289 /* Get the build string */
290 string = get_string_from_dictionary(system_version_dict,
291 CFSTR("ProductBuildVersion"));
292 if (string == NULL) {
293 CFRelease(system_version_dict);
294 CFReadStreamClose(system_version_plist_stream);
295 CFRelease(system_version_plist_stream);
298 g_string_append_printf(str, ", build %s", string);
300 CFRelease(system_version_dict);
301 CFReadStreamClose(system_version_plist_stream);
302 CFRelease(system_version_plist_stream);
308 * Get the OS version, and append it to the GString
310 void get_os_version_info(GString *str)
313 OSVERSIONINFOEX info;
314 SYSTEM_INFO system_info;
315 nativesi_func_ptr nativesi_func;
316 #elif defined(HAVE_SYS_UTSNAME_H)
324 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
326 * for more than you ever wanted to know about determining the
327 * flavor of Windows on which you're running. Implementing more
328 * of that is left as an exercise to the reader - who should
329 * check any copyright information about code samples on MSDN
330 * before cutting and pasting into Wireshark.
332 * They should also note that you need an OSVERSIONINFOEX structure
333 * to get some of that information, and that not only is that
334 * structure not supported on older versions of Windows, you might
335 * not even be able to compile code that *uses* that structure with
336 * older versions of the SDK.
339 memset(&info, '\0', sizeof info);
340 info.dwOSVersionInfoSize = sizeof info;
341 if (!GetVersionEx((OSVERSIONINFO *)&info)) {
343 * XXX - get the failure reason.
345 g_string_append(str, "unknown Windows version");
349 memset(&system_info, '\0', sizeof system_info);
350 /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
351 * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
352 nativesi_func = (nativesi_func_ptr)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo");
354 nativesi_func(&system_info);
356 GetSystemInfo(&system_info);
358 switch (info.dwPlatformId) {
360 case VER_PLATFORM_WIN32s:
362 g_string_append_printf(str, "Windows 3.1 with Win32s");
365 case VER_PLATFORM_WIN32_WINDOWS:
367 switch (info.dwMajorVersion) {
370 /* 3 cheers for Microsoft marketing! */
371 switch (info.dwMinorVersion) {
374 g_string_append_printf(str, "Windows 95");
378 g_string_append_printf(str, "Windows 98");
382 g_string_append_printf(str, "Windows Me");
386 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
387 info.dwMajorVersion, info.dwMinorVersion);
393 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
394 info.dwMajorVersion, info.dwMinorVersion);
399 case VER_PLATFORM_WIN32_NT:
401 switch (info.dwMajorVersion) {
405 g_string_append_printf(str, "Windows NT %lu.%lu",
406 info.dwMajorVersion, info.dwMinorVersion);
410 /* 3 cheers for Microsoft marketing! */
411 switch (info.dwMinorVersion) {
414 g_string_append_printf(str, "Windows 2000");
418 g_string_append_printf(str, "Windows XP");
422 if ((info.wProductType == VER_NT_WORKSTATION) &&
423 (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
424 g_string_append_printf(str, "Windows XP Professional x64 Edition");
426 g_string_append_printf(str, "Windows Server 2003");
427 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
428 g_string_append_printf(str, " x64 Edition");
433 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
434 info.dwMajorVersion, info.dwMinorVersion);
440 gboolean is_nt_workstation;
442 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
443 g_string_append(str, "64-bit ");
444 else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
445 g_string_append(str, "32-bit ");
446 #ifndef VER_NT_WORKSTATION
447 #define VER_NT_WORKSTATION 0x01
448 is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
450 is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
452 switch (info.dwMinorVersion) {
454 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
457 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
460 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
461 info.dwMajorVersion, info.dwMinorVersion);
467 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
468 info.dwMajorVersion, info.dwMinorVersion);
470 } /* info.dwMajorVersion */
474 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
475 info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
478 if (info.szCSDVersion[0] != '\0')
479 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
480 g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
481 #elif defined(HAVE_SYS_UTSNAME_H)
483 * We have <sys/utsname.h>, so we assume we have "uname()".
485 if (uname(&name) < 0) {
486 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
491 if (strcmp(name.sysname, "AIX") == 0) {
493 * Yay, IBM! Thanks for doing something different
494 * from most of the other UNIXes out there, and
495 * making "name.version" apparently be the major
496 * version number and "name.release" be the minor
499 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
503 * XXX - get "version" on any other platforms?
505 * On Digital/Tru64 UNIX, it's something unknown.
506 * On Solaris, it's some kind of build information.
507 * On HP-UX, it appears to be some sort of subrevision
509 * On *BSD and Darwin/OS X, it's a long string giving
510 * a build date, config file name, etc., etc., etc..
512 #ifdef HAVE_OS_X_FRAMEWORKS
514 * On Mac OS X, report the Mac OS X version number as
515 * the OS version if we can, and put the Darwin information
518 if (get_os_x_version_info(str)) {
519 /* Success - append the Darwin information. */
520 g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
522 /* Failure - just use the Darwin information. */
523 g_string_append_printf(str, "%s %s", name.sysname, name.release);
525 #else /* HAVE_OS_X_FRAMEWORKS */
527 * XXX - on Linux, are there any APIs to get the distribution
528 * name and version number? I think some distributions have
531 * At least on Linux Standard Base-compliant distributions,
532 * there's an "lsb_release" command. However:
534 * http://forums.fedoraforum.org/showthread.php?t=220885
536 * seems to suggest that if you don't have the redhat-lsb
537 * package installed, you don't have lsb_release, and that
538 * /etc/fedora-release has the release information on
541 * http://linux.die.net/man/1/lsb_release
543 * suggests that there's an /etc/distrib-release file, but
544 * it doesn't indicate whether "distrib" is literally
545 * "distrib" or is the name for the distribution, and
546 * also speaks of an /etc/debian_version file.
548 * "lsb_release" apparently parses /etc/lsb-release, which
549 * has shell-style assignments, assigning to, among other
550 * values, DISTRIB_ID (distributor/distribution name),
551 * DISTRIB_RELEASE (release number of the distribution),
552 * DISTRIB_DESCRIPTION (*might* be name followed by version,
553 * but the manpage for lsb_release seems to indicate that's
554 * not guaranteed), and DISTRIB_CODENAME (code name, e.g.
555 * "licentious" for the Ubuntu Licentious Lemur release).
556 * the lsb_release man page also speaks of the distrib-release
557 * file, but Debian doesn't have one, and Ubuntu 7's
558 * lsb_release command doesn't look for one.
560 * I've seen references to /etc/redhat-release as well.
562 * At least on my Ubuntu 7 system, /etc/debian_version
563 * doesn't contain anything interesting (just some Debian
568 * http://bugs.python.org/issue1322
570 * http://www.novell.com/coolsolutions/feature/11251.html
572 * http://linuxmafia.com/faq/Admin/release-files.html
574 * and the Lib/Platform.py file in recent Python 2.x
577 g_string_append_printf(str, "%s %s", name.sysname, name.release);
578 #endif /* HAVE_OS_X_FRAMEWORKS */
581 g_string_append(str, "an unknown OS");
587 * Get various library run-time versions, and the OS version, and append
588 * them to the specified GString.
591 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
597 g_string_append(str, "on ");
599 get_os_version_info(str);
603 if ((lang = getenv ("LANG")) != NULL)
604 g_string_append_printf(str, ", with locale %s", lang);
606 g_string_append(str, ", without locale");
610 g_string_append(str, ", ");
611 get_runtime_pcap_version(str);
614 #if defined(HAVE_LIBZ) && !defined(_WIN32)
615 g_string_append_printf(str, ", with libz %s", zlibVersion());
618 /* Additional application-dependent information */
620 (*additional_info)(str);
622 g_string_append(str, ".");
627 * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
628 * information on various defined strings.
630 * GCC's __VERSION__ is a nice text string for humans to
631 * read. The page at sourceforge.net largely describes
632 * numeric #defines that encode the version; if the compiler
633 * doesn't also offer a nice printable string, we try prettifying
634 * the number somehow.
636 #if defined(__GNUC__) && defined(__VERSION__)
638 * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
639 * distinguish between them.
641 #if defined(__clang__)
642 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
643 #elif defined(__llvm__)
644 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
645 #else /* boring old GCC */
646 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
648 #elif defined(__HP_aCC)
649 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
650 #elif defined(__xlC__)
651 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
652 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
654 if ((__IBMC__ % 10) != 0)
655 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
656 #endif /* __IBMC__ */
657 g_string_append_printf(str, "\n");
658 #elif defined(__INTEL_COMPILER)
659 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
660 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
661 if ((__INTEL_COMPILER % 10) != 0)
662 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
663 #ifdef __INTEL_COMPILER_BUILD_DATE
664 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
665 __INTEL_COMPILER_BUILD_DATE / 10000,
666 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
667 __INTEL_COMPILER_BUILD_DATE % 100);
668 #endif /* __INTEL_COMPILER_BUILD_DATE */
669 g_string_append_printf(str, "\n");
670 #elif defined(_MSC_FULL_VER)
671 # if _MSC_FULL_VER > 99999999
672 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
673 (_MSC_FULL_VER / 10000000) - 6,
674 (_MSC_FULL_VER / 100000) % 100);
675 # if (_MSC_FULL_VER % 100000) != 0
676 g_string_append_printf(str, " build %d",
677 _MSC_FULL_VER % 100000);
680 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
681 (_MSC_FULL_VER / 1000000) - 6,
682 (_MSC_FULL_VER / 10000) % 100);
683 # if (_MSC_FULL_VER % 10000) != 0
684 g_string_append_printf(str, " build %d",
685 _MSC_FULL_VER % 10000);
688 g_string_append_printf(str, "\n");
689 #elif defined(_MSC_VER)
690 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
691 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
692 (_MSC_VER / 100) - 6, _MSC_VER % 100);
693 #elif defined(__SUNPRO_C)
694 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
695 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
696 if ((__SUNPRO_C & 0xF) != 0)
697 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
698 g_string_append_printf(str, "\n");
705 * Get copyright information.
708 get_copyright_info(void)
711 "Copyright 1998-2012 Gerald Combs <gerald@wireshark.org> and contributors.\n"
712 "This is free software; see the source for copying conditions. There is NO\n"
713 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
718 * Get the major OS version.
720 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
722 get_os_major_version()
725 info.dwOSVersionInfoSize = sizeof info;
726 if (GetVersionEx(&info)) {
727 return info.dwMajorVersion;
739 * indent-tabs-mode: t
742 * ex: set shiftwidth=8 tabstop=8 noexpandtab:
743 * :indentSize=8:tabSize=8:noTabs=false: