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.
30 #include <Python.h> /* to get the Python version number (PY_VERSION) */
41 #include <zlib.h> /* to get the libz version number */
45 #include <pcre.h> /* to get the libpcre version number */
46 #endif /* HAVE_LIBPCRE */
48 #ifdef HAVE_SYS_UTSNAME_H
49 #include <sys/utsname.h>
52 #include "version_info.h"
53 #include "capture-pcap-util.h"
54 #include <wsutil/unicode-utils.h>
56 #include "svnversion.h"
62 #ifdef HAVE_OS_X_FRAMEWORKS
63 #include <CoreServices/CoreServices.h>
67 # include <sys/capability.h>
71 #include <epan/geoip_db.h>
75 const char *wireshark_svnversion = " (" SVNVERSION " from " SVNPATH ")";
77 const char *wireshark_svnversion = "";
81 * If the string doesn't end with a newline, append one.
82 * Then word-wrap it to 80 columns.
85 end_string(GString *str)
91 if (point == 0 || str->str[point - 1] != '\n')
92 g_string_append(str, "\n");
98 * Break at or before this point.
101 while (q > p && *q != ' ')
111 * Get various library compile-time versions and append them to
112 * the specified GString.
114 * "additional_info" is called at the end to append any additional
115 * information; this is required in order to, for example, put the
116 * Portaudio information at the end of the string, as we currently
117 * don't use Portaudio in TShark.
120 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
121 void (*append_info)(GString *))
123 if (sizeof(str) == 4)
124 g_string_append(str, "(32-bit) ");
126 g_string_append(str, "(64-bit) ");
129 (*prepend_info)(str);
132 g_string_append(str, "with ");
133 g_string_append_printf(str,
134 #ifdef GLIB_MAJOR_VERSION
135 "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
138 "GLib (version unknown)");
142 g_string_append(str, ", ");
143 get_compiled_pcap_version(str);
146 g_string_append(str, ", ");
148 g_string_append(str, "with libz ");
150 g_string_append(str, ZLIB_VERSION);
151 #else /* ZLIB_VERSION */
152 g_string_append(str, "(version unknown)");
153 #endif /* ZLIB_VERSION */
154 #else /* HAVE_LIBZ */
155 g_string_append(str, "without libz");
156 #endif /* HAVE_LIBZ */
159 g_string_append(str, ", ");
161 g_string_append(str, "with POSIX capabilities");
162 #ifdef _LINUX_CAPABILITY_VERSION
163 g_string_append(str, " (Linux)");
164 #endif /* _LINUX_CAPABILITY_VERSION */
165 #else /* HAVE_LIBCAP */
166 g_string_append(str, "without POSIX capabilities");
167 #endif /* HAVE_LIBCAP */
169 /* Additional application-dependent information */
172 g_string_append(str, ".");
174 #if !defined(HAVE_LIBPCRE) && !GLIB_CHECK_VERSION(2,14,0)
176 "\nNOTE: this build doesn't support the \"matches\" operator for Wireshark filter syntax");
177 g_string_append(str, ".");
178 #endif /* HAVE_LIBPCRE */
184 * Get various library run-time versions, and the OS version, and append
185 * them to the specified GString.
188 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
191 OSVERSIONINFOEX info;
192 SYSTEM_INFO system_info;
193 #elif defined(HAVE_SYS_UTSNAME_H)
196 #if HAVE_OS_X_FRAMEWORKS
197 SInt32 macosx_ver, macosx_major_ver, macosx_minor_ver, macosx_bugfix_ver;
200 g_string_append(str, "on ");
206 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
208 * for more than you ever wanted to know about determining the
209 * flavor of Windows on which you're running. Implementing more
210 * of that is left as an exercise to the reader - who should
211 * check any copyright information about code samples on MSDN
212 * before cutting and pasting into Wireshark.
214 * They should also note that you need an OSVERSIONINFOEX structure
215 * to get some of that information, and that not only is that
216 * structure not supported on older versions of Windows, you might
217 * not even be able to compile code that *uses* that structure with
218 * older versions of the SDK.
221 memset(&info, '\0', sizeof info);
222 info.dwOSVersionInfoSize = sizeof info;
223 if (!GetVersionEx((OSVERSIONINFO *)&info)) {
225 * XXX - get the failure reason.
227 g_string_append(str, "unknown Windows version");
231 memset(&system_info, '\0', sizeof system_info);
232 GetSystemInfo(&system_info); /* only for W2K or greater .... (which is what we support) */
234 switch (info.dwPlatformId) {
236 case VER_PLATFORM_WIN32s:
238 g_string_append_printf(str, "Windows 3.1 with Win32s");
241 case VER_PLATFORM_WIN32_WINDOWS:
243 switch (info.dwMajorVersion) {
246 /* 3 cheers for Microsoft marketing! */
247 switch (info.dwMinorVersion) {
250 g_string_append_printf(str, "Windows 95");
254 g_string_append_printf(str, "Windows 98");
258 g_string_append_printf(str, "Windows Me");
262 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
263 info.dwMajorVersion, info.dwMinorVersion);
269 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
270 info.dwMajorVersion, info.dwMinorVersion);
275 case VER_PLATFORM_WIN32_NT:
277 switch (info.dwMajorVersion) {
281 g_string_append_printf(str, "Windows NT %lu.%lu",
282 info.dwMajorVersion, info.dwMinorVersion);
286 /* 3 cheers for Microsoft marketing! */
287 switch (info.dwMinorVersion) {
290 g_string_append_printf(str, "Windows 2000");
294 g_string_append_printf(str, "Windows XP");
298 if ((info.wProductType == VER_NT_WORKSTATION) &&
299 (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
300 g_string_append_printf(str, "Windows XP Professional x64 Edition");
302 g_string_append_printf(str, "Windows Server 2003");
303 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
304 g_string_append_printf(str, " x64 Edition");
309 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
310 info.dwMajorVersion, info.dwMinorVersion);
316 gboolean is_nt_workstation;
318 if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
319 g_string_append(str, "64-bit ");
320 else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
321 g_string_append(str, "32-bit ");
322 #ifndef VER_NT_WORKSTATION
323 #define VER_NT_WORKSTATION 0x01
324 is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
326 is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
328 switch (info.dwMinorVersion) {
330 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
333 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
336 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
337 info.dwMajorVersion, info.dwMinorVersion);
343 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
344 info.dwMajorVersion, info.dwMinorVersion);
346 } /* info.dwMajorVersion */
350 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
351 info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
354 if (info.szCSDVersion[0] != '\0')
355 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
356 g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
357 #elif defined(HAVE_SYS_UTSNAME_H)
359 * We have <sys/utsname.h>, so we assume we have "uname()".
361 if (uname(&name) < 0) {
362 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
367 if (strcmp(name.sysname, "AIX") == 0) {
369 * Yay, IBM! Thanks for doing something different
370 * from most of the other UNIXes out there, and
371 * making "name.version" apparently be the major
372 * version number and "name.release" be the minor
375 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
379 * XXX - get "version" on any other platforms?
381 * On Digital/Tru64 UNIX, it's something unknown.
382 * On Solaris, it's some kind of build information.
383 * On HP-UX, it appears to be some sort of subrevision
385 * On *BSD and Darwin/OS X, it's a long string giving
386 * a build date, config file name, etc., etc., etc..
388 #ifdef HAVE_OS_X_FRAMEWORKS
390 * On Mac OS X, report the Mac OS X version number as
391 * the OS, and put the Darwin information in parentheses.
393 * XXX - can we get the build name? There's no API to
394 * get it; it's currently in
395 * /System/Library/CoreServices/SystemVersion.plist
396 * but there's no guarantee that it will continue to
399 Gestalt(gestaltSystemVersion, &macosx_ver);
401 /* The following functions are only available in Mac OS 10.4+ */
402 if(macosx_ver >= 0x1040) {
403 Gestalt(gestaltSystemVersionMajor, &macosx_major_ver);
404 Gestalt(gestaltSystemVersionMinor, &macosx_minor_ver);
405 Gestalt(gestaltSystemVersionBugFix, &macosx_bugfix_ver);
407 g_string_append_printf(str, "Mac OS %ld.%ld.%ld",
408 (long)macosx_major_ver,
409 (long)macosx_minor_ver,
410 (long)macosx_bugfix_ver);
412 g_string_append_printf(str, "Mac OS X < 10.4 [%lx]",
414 /* See Apple's Gestalt Manager Reference for meanings
415 * of the macosx_ver values. */
417 g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
418 #else /* HAVE_OS_X_FRAMEWORKS */
420 * XXX - on Linux, are there any APIs to get the distribution
421 * name and version number? I think some distributions have
424 * At least on Linux Standard Base-compliant distributions,
425 * there's an "lsb_release" command. However:
427 * http://forums.fedoraforum.org/showthread.php?t=220885
429 * seems to suggest that if you don't have the redhat-lsb
430 * package installed, you don't have lsb_release, and that
431 * /etc/fedora-release has the release information on
434 * http://linux.die.net/man/1/lsb_release
436 * suggests that there's an /etc/distrib-release file, but
437 * it doesn't indicate whether "distrib" is literally
438 * "distrib" or is the name for the distribution, and
439 * also speaks of an /etc/debian_version file.
441 * "lsb_release" apparently parses /etc/lsb-release, which
442 * has shell-style assignments, assigning to, among other
443 * values, DISTRIB_ID (distributor/distribution name),
444 * DISTRIB_RELEASE (release number of the distribution),
445 * DISTRIB_DESCRIPTION (*might* be name followed by version,
446 * but the manpage for lsb_release seems to indicate that's
447 * not guaranteed), and DISTRIB_CODENAME (code name, e.g.
448 * "licentious" for the Ubuntu Licentious Lemur release).
449 * the lsb_release man page also speaks of the distrib-release
450 * file, but Debian doesn't have one, and Ubuntu 7's
451 * lsb_release command doesn't look for one.
453 * I've seen references to /etc/redhat-release as well.
455 * At least on my Ubuntu 7 system, /etc/debian_version
456 * doesn't contain anything interesting (just some Debian
461 * http://bugs.python.org/issue1322
463 * http://www.novell.com/coolsolutions/feature/11251.html
465 * http://linuxmafia.com/faq/Admin/release-files.html
467 * and the Lib/Platform.py file in recent Python 2.x
470 g_string_append_printf(str, "%s %s", name.sysname, name.release);
471 #endif /* HAVE_OS_X_FRAMEWORKS */
474 g_string_append(str, "an unknown OS");
478 g_string_append(str, ", ");
479 get_runtime_pcap_version(str);
482 #if defined(HAVE_LIBZ) && !defined(_WIN32)
483 g_string_append_printf(str, ", with libz %s", zlibVersion());
486 /* Additional application-dependent information */
488 (*additional_info)(str);
490 g_string_append(str, ".");
495 * See http://predef.sourceforge.net/precomp.html for
496 * information on various defined strings.
498 * GCC's __VERSION__ is a nice text string for humans to
499 * read. The page at predef.sourceforge.net largely
500 * describes numeric #defines that encode the version;
501 * if the compiler doesn't also offer a nice printable
502 * string, we should probably prettify the number somehow.
504 #if defined(__GNUC__) && defined(__VERSION__)
505 #if defined(__clang__)
506 g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
507 #elif defined(__llvm__)
508 g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
509 #else /* boring old GCC */
510 g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
512 #elif defined(__HP_aCC)
513 g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
514 #elif defined(__xlC__)
515 g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
516 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
518 if ((__IBMC__ % 10) != 0)
519 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
520 #endif /* __IBMC__ */
521 g_string_append_printf(str, "\n");
522 #elif defined(__INTEL_COMPILER)
523 g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
524 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
525 if ((__INTEL_COMPILER % 10) != 0)
526 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
527 #ifdef __INTEL_COMPILER_BUILD_DATE
528 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
529 __INTEL_COMPILER_BUILD_DATE / 10000,
530 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
531 __INTEL_COMPILER_BUILD_DATE % 100);
532 #endif /* __INTEL_COMPILER_BUILD_DATE */
533 g_string_append_printf(str, "\n");
534 #elif defined(_MSC_FULL_VER)
535 if (_MSC_FULL_VER > 99999999) {
536 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
537 (_MSC_FULL_VER / 10000000) - 6,
538 (_MSC_FULL_VER / 100000) % 100);
539 if ((_MSC_FULL_VER % 100000) != 0)
540 g_string_append_printf(str, " build %d",
541 _MSC_FULL_VER % 100000);
543 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
544 (_MSC_FULL_VER / 1000000) - 6,
545 (_MSC_FULL_VER / 10000) % 100);
546 if ((_MSC_FULL_VER % 10000) != 0)
547 g_string_append_printf(str, " build %d",
548 _MSC_FULL_VER % 10000);
550 g_string_append_printf(str, "\n");
551 #elif defined(_MSC_VER)
552 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
553 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
554 (_MSC_VER / 100) - 6, _MSC_VER % 100);
555 #elif defined(__SUNPRO_C)
556 g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
557 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
558 if ((__SUNPRO_C & 0xF) != 0)
559 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
560 g_string_append_printf(str, "\n");
567 * Get copyright information.
570 get_copyright_info(void)
573 "Copyright 1998-2010 Gerald Combs <gerald@wireshark.org> and contributors.\n"
574 "This is free software; see the source for copying conditions. There is NO\n"
575 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
580 * Get the major OS version.
582 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
584 get_os_major_version()
587 info.dwOSVersionInfoSize = sizeof info;
588 if (GetVersionEx(&info)) {
589 return info.dwMajorVersion;
601 * indent-tabs-mode: t
604 * ex: set shiftwidth=8 tabstop=8 noexpandtab
605 * :indentSize=8:tabSize=8:noTabs=false: