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.
36 #include <zlib.h> /* to get the libz version number */
40 #include <pcre.h> /* to get the libpcre version number */
41 #endif /* HAVE_LIBPCRE */
46 #include <net-snmp/version.h>
47 #endif /* HAVE_NET_SNMP */
50 #include <ucd-snmp/version.h>
51 #endif /* HAVE_UCD_SNMP */
53 #endif /* HAVE_SOME_SNMP */
55 #if (defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBGNUTLS)) && defined(_WIN32)
56 #include <winposixtype.h>
61 #endif /* HAVE_LIBGCRYPT */
64 #include <gnutls/gnutls.h>
65 #endif /* HAVE_LIBGNUTLS */
67 #ifdef HAVE_SYS_UTSNAME_H
68 #include <sys/utsname.h>
71 #include "version_info.h"
72 #include "capture-pcap-util.h"
73 #include "epan/unicode-utils.h"
75 #include "svnversion.h"
86 const char *svnversion = " (" SVNVERSION ")";
88 const char *svnversion = "";
92 * Add a word wrap break point, and return its index.
95 add_word_wrap_break_point(GString *str)
97 g_string_append(str, " ");
102 * Add punctuation at the end of a phrase, and see whether the last line in
103 * the string goes past column 80; if so, replace the blank at the specified
104 * point with a newline.
107 end_item_and_break(GString *str, char *punct, gint point)
111 g_string_append(str, punct);
112 line_begin = strrchr(str->str, '\n');
113 if (line_begin == NULL)
114 line_begin = str->str;
117 if (strlen(line_begin) > 80) {
118 g_assert(str->str[point] == ' ');
119 str->str[point] = '\n';
124 * If the string doesn't end with a newline, append one.
127 end_string(GString *str)
131 point = strlen(str->str);
132 if (point == 0 || str->str[point - 1] != '\n')
133 g_string_append(str, "\n");
137 * Get various library compile-time versions and append them to
138 * the specified GString.
140 * "additional_info" is called at the end to append any additional
141 * information; this is required in order to, for example, put the
142 * Portaudio information at the end of the string, as we currently
143 * don't use Portaudio in TShark.
146 get_compiled_version_info(GString *str, void (*additional_info)(GString *))
151 g_string_append(str, "with ");
152 g_string_sprintfa(str,
153 #ifdef GLIB_MAJOR_VERSION
154 "GLib %d.%d.%d,", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
157 "GLib (version unknown),");
160 break_point = add_word_wrap_break_point(str);
161 get_compiled_pcap_version(str);
162 end_item_and_break(str, ",", break_point);
165 break_point = add_word_wrap_break_point(str);
167 g_string_append(str, "with libz ");
169 g_string_append(str, ZLIB_VERSION);
170 #else /* ZLIB_VERSION */
171 g_string_append(str, "(version unknown)");
172 #endif /* ZLIB_VERSION */
173 #else /* HAVE_LIBZ */
174 g_string_append(str, "without libz");
175 #endif /* HAVE_LIBZ */
177 /* Additional application-dependent information */
178 if (additional_info) {
179 end_item_and_break(str, ",", break_point);
180 break_point = add_word_wrap_break_point(str);
181 (*additional_info)(str);
183 end_item_and_break(str, ".", break_point);
186 break_point = str->len - 1;
188 "\nNOTE: this build doesn't support the \"matches\" operator for Wireshark filter syntax");
189 end_item_and_break(str, ".", break_point);
190 #endif /* HAVE_LIBPCRE */
196 * Get compile-time information used only by applications that use
200 get_epan_compiled_version_info(GString *str)
205 break_point = str->len - 1;
207 g_string_append(str, "with libpcre ");
210 g_string_sprintfa(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
211 #else /* PCRE_MINOR */
212 g_string_sprintfa(str, "%u", PCRE_MAJOR);
213 #endif /* PCRE_MINOR */
214 #else /* PCRE_MAJOR */
215 g_string_append(str, "(version unknown)");
216 #endif /* PCRE_MAJOR */
217 #else /* HAVE_LIBPCRE */
218 g_string_append(str, "without libpcre");
219 #endif /* HAVE_LIBPCRE */
221 end_item_and_break(str, ",", break_point);
224 /* Oh, this is pretty. */
225 /* Oh, ha. you think that was pretty. Try this:! --Wes */
226 break_point = add_word_wrap_break_point(str);
227 #ifdef HAVE_SOME_SNMP
230 g_string_append(str, "with UCD-SNMP ");
231 g_string_append(str, VersionInfo);
232 #endif /* HAVE_UCD_SNMP */
235 g_string_append(str, "with Net-SNMP ");
236 g_string_append(str, netsnmp_get_version());
237 #endif /* HAVE_NET_SNMP */
239 #else /* no SNMP library */
240 g_string_append(str, "without UCD-SNMP or Net-SNMP");
241 #endif /* HAVE_SOME_SNMP */
242 end_item_and_break(str, ",", break_point);
245 break_point = add_word_wrap_break_point(str);
247 g_string_append(str, "with ADNS");
249 g_string_append(str, "without ADNS");
250 #endif /* HAVE_GNU_ADNS */
251 end_item_and_break(str, ",", break_point);
254 break_point = add_word_wrap_break_point(str);
256 g_string_append(str, "with ");
257 g_string_append(str, LUA_VERSION);
259 g_string_append(str, "without Lua");
260 #endif /* HAVE_LUA */
261 end_item_and_break(str, ",", break_point);
264 break_point = add_word_wrap_break_point(str);
265 #ifdef HAVE_LIBGNUTLS
266 g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
268 g_string_append(str, "without GnuTLS");
269 #endif /* HAVE_LIBGNUTLS */
270 end_item_and_break(str, ",", break_point);
273 break_point = add_word_wrap_break_point(str);
274 #ifdef HAVE_LIBGCRYPT
275 g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
277 g_string_append(str, "without Gcrypt");
278 #endif /* HAVE_LIBGCRYPT */
279 end_item_and_break(str, ",", break_point);
282 /* XXX - I don't see how to get the version number, at least for KfW */
283 break_point = add_word_wrap_break_point(str);
285 #ifdef HAVE_MIT_KERBEROS
286 g_string_append(str, "with MIT Kerberos");
288 /* HAVE_HEIMDAL_KERBEROS */
289 g_string_append(str, "with Heimdal Kerberos");
292 g_string_append(str, "without Kerberos");
293 #endif /* HAVE_KERBEROS */
297 * Get various library run-time versions, and the OS version, and append
298 * them to the specified GString.
301 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
307 #elif defined(HAVE_SYS_UTSNAME_H)
311 g_string_append(str, "on ");
317 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
319 * for more than you ever wanted to know about determining the
320 * flavor of Windows on which you're running. Implementing more
321 * of that is left as an exercise to the reader - who should
322 * check any copyright information about code samples on MSDN
323 * before cutting and pasting into Wireshark.
325 * They should also note that you need an OSVERSIONINFOEX structure
326 * to get some of that information, and that not only is that
327 * structure not supported on older versions of Windows, you might
328 * not even be able to compile code that *uses* that structure with
329 * older versions of the SDK.
331 info.dwOSVersionInfoSize = sizeof info;
332 if (!GetVersionEx(&info)) {
334 * XXX - get the failure reason.
336 g_string_append(str, "unknown Windows version");
339 switch (info.dwPlatformId) {
341 case VER_PLATFORM_WIN32s:
343 g_string_sprintfa(str, "Windows 3.1 with Win32s");
346 case VER_PLATFORM_WIN32_WINDOWS:
348 switch (info.dwMajorVersion) {
351 /* 3 cheers for Microsoft marketing! */
352 switch (info.dwMinorVersion) {
355 g_string_sprintfa(str, "Windows 95");
359 g_string_sprintfa(str, "Windows 98");
363 g_string_sprintfa(str, "Windows Me");
367 g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
368 info.dwMajorVersion, info.dwMinorVersion);
374 g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
375 info.dwMajorVersion, info.dwMinorVersion);
380 case VER_PLATFORM_WIN32_NT:
382 switch (info.dwMajorVersion) {
386 g_string_sprintfa(str, "Windows NT %lu.%lu",
387 info.dwMajorVersion, info.dwMinorVersion);
391 /* 3 cheers for Microsoft marketing! */
392 switch (info.dwMinorVersion) {
395 g_string_sprintfa(str, "Windows 2000");
399 g_string_sprintfa(str, "Windows XP");
403 g_string_sprintfa(str, "Windows Server 2003");
407 g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
408 info.dwMajorVersion, info.dwMinorVersion);
414 g_string_sprintfa(str, "Windows Vista");
418 g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
419 info.dwMajorVersion, info.dwMinorVersion);
425 g_string_sprintfa(str, "Unknown Windows platform %lu version %lu.%lu",
426 info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
429 if (info.szCSDVersion[0] != '\0')
430 g_string_sprintfa(str, " %s", utf_16to8(info.szCSDVersion));
431 g_string_sprintfa(str, ", build %lu", info.dwBuildNumber);
432 #elif defined(HAVE_SYS_UTSNAME_H)
434 * We have <sys/utsname.h>, so we assume we have "uname()".
436 if (uname(&name) < 0) {
437 g_string_sprintfa(str, "unknown OS version (uname failed - %s)",
442 if (strcmp(name.sysname, "AIX") == 0) {
444 * Yay, IBM! Thanks for doing something different
445 * from most of the other UNIXes out there, and
446 * making "name.version" apparently be the major
447 * version number and "name.release" be the minor
450 g_string_sprintfa(str, "%s %s.%s", name.sysname, name.version,
454 * XXX - get "version" on any other platforms?
456 * On Digital/Tru65 UNIX, it's something unknown.
457 * On Solaris, it's some kind of build information.
458 * On HP-UX, it appears to be some sort of subrevision
461 g_string_sprintfa(str, "%s %s", name.sysname, name.release);
464 g_string_append(str, "an unknown OS");
467 break_point = add_word_wrap_break_point(str);
469 /* Additional application-dependent information */
470 if (additional_info) {
471 end_item_and_break(str, ",", break_point);
472 break_point = add_word_wrap_break_point(str);
473 (*additional_info)(str);
476 end_item_and_break(str, ".", break_point);
481 * See http://predef.sourceforge.net/precomp.html for
482 * information on various defined strings.
484 * GCC's __VERSION__ is a nice text string for humans to
485 * read. The page at predef.sourceforge.net largely
486 * describes numeric #defines that encode the version;
487 * if the compiler doesn't also offer a nice printable
488 * string, we should probably prettify the number somehow.
490 #if defined(__GNUC__) && defined(__VERSION__)
491 g_string_sprintfa(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
492 #elif defined(__HP_aCC)
493 g_string_sprintfa(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
494 #elif defined(__xlC__)
495 g_string_sprintfa(str, "\n\nBuilt using IBM XL C %d.%d\n",
496 (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
498 if ((__IBMC__ % 10) != 0)
499 g_string_sprintfa(str, " patch %d", __IBMC__ % 10);
500 #endif /* __IBMC__ */
501 g_string_sprintfa(str, "\n");
502 #elif defined(__INTEL_COMPILER)
503 g_string_sprintfa(str, "\n\nBuilt using Intel C %d.%d",
504 __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
505 if ((__INTEL_COMPILER % 10) != 0)
506 g_string_sprintfa(str, " patch %d", __INTEL_COMPILER % 10);
507 #ifdef __INTEL_COMPILER_BUILD_DATE
508 g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
509 __INTEL_COMPILER_BUILD_DATE / 10000,
510 (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
511 __INTEL_COMPILER_BUILD_DATE % 100);
512 #endif /* __INTEL_COMPILER_BUILD_DATE */
513 g_string_sprintfa(str, "\n");
514 #elif defined(_MSC_FULL_VER)
515 if (_MSC_FULL_VER > 99999999) {
516 g_string_sprintfa(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
517 (_MSC_FULL_VER / 10000000) - 6,
518 (_MSC_FULL_VER / 100000) % 100);
519 if ((_MSC_FULL_VER % 100000) != 0)
520 g_string_sprintfa(str, " patch %d",
521 _MSC_FULL_VER % 100000);
523 g_string_sprintfa(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
524 (_MSC_FULL_VER / 1000000) - 6,
525 (_MSC_FULL_VER / 10000) % 100);
526 if ((_MSC_FULL_VER % 10000) != 0)
527 g_string_sprintfa(str, " patch %d",
528 _MSC_FULL_VER % 10000);
530 g_string_sprintfa(str, "\n");
531 #elif defined(_MSC_VER)
532 /* _MSC_FULL_VER not defined, but _MSC_VER defined */
533 g_string_sprintfa(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
534 (_MSC_VER / 100) - 6, _MSC_VER % 100);
535 #elif defined(__SUNPRO_C)
536 g_string_sprintfa(str, "\n\nBuilt using Sun C %d.%d",
537 (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
538 if ((__SUNPRO_C & 0xF) != 0)
539 g_string_sprintfa(str, " patch %d", __SUNPRO_C & 0xF);
540 g_string_sprintfa(str, "\n");
547 * Get copyright information.
550 get_copyright_info(void)
553 "Copyright 1998-2006 Gerald Combs <gerald@wireshark.org> and contributors.\n"
554 "This is free software; see the source for copying conditions. There is NO\n"
555 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";