From Anders: Fix wrong tag numbers.
[obnox/wireshark/wip.git] / version_info.c
1 /* version_info.c
2  * Routines to report version information for stuff used by Wireshark
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <errno.h>
35
36 #ifdef HAVE_PYTHON
37 #include <Python.h> /* to get the Python version number (PY_VERSION) */
38 #endif
39
40 #ifdef HAVE_LIBZ
41 #include <zlib.h>       /* to get the libz version number */
42 #endif
43
44 #ifdef HAVE_LIBPCRE
45 #include <pcre.h>       /* to get the libpcre version number */
46 #endif /* HAVE_LIBPCRE */
47
48 #if (defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBGNUTLS)) && defined(_WIN32)
49 #include <winposixtype.h>
50 #endif
51
52 #ifdef HAVE_LIBGCRYPT
53 #include <gcrypt.h>
54 #endif /* HAVE_LIBGCRYPT */
55
56 #ifdef HAVE_LIBGNUTLS
57 #include <gnutls/gnutls.h>
58 #endif /* HAVE_LIBGNUTLS */
59
60 #ifdef HAVE_SYS_UTSNAME_H
61 #include <sys/utsname.h>
62 #endif
63
64 #include "version_info.h"
65 #include "capture-pcap-util.h"
66 #include <wsutil/unicode-utils.h>
67
68 #include "svnversion.h"
69
70 #ifdef HAVE_WINDOWS_H
71 #include <windows.h>
72 #endif
73
74 #ifdef HAVE_C_ARES
75 #include <ares_version.h>
76 #endif
77
78 #ifdef HAVE_LUA_5_1
79 #include <lua.h>
80 #endif
81
82 #ifdef HAVE_LIBSMI
83 #include <smi.h>
84 #endif
85
86 #ifdef HAVE_OS_X_FRAMEWORKS
87 #include <CoreServices/CoreServices.h>
88 #endif
89
90 #ifdef HAVE_LIBCAP
91 # include <sys/capability.h>
92 #endif
93
94 #ifdef HAVE_GEOIP
95 #include <epan/geoip_db.h>
96 #endif
97
98 #ifdef SVNVERSION
99         const char *wireshark_svnversion = " (" SVNVERSION ")";
100 #else
101         const char *wireshark_svnversion = "";
102 #endif
103
104 /*
105  * If the string doesn't end with a newline, append one.
106  * Then word-wrap it to 80 columns.
107  */
108 static void
109 end_string(GString *str)
110 {
111         size_t point;
112         char *p, *q;
113
114         point = strlen(str->str);
115         if (point == 0 || str->str[point - 1] != '\n')
116                 g_string_append(str, "\n");
117         p = str->str;
118         while (*p != '\0') {
119                 q = strchr(p, '\n');
120                 if (q - p > 80) {
121                         /*
122                          * Break at or before this point.
123                          */
124                         q = p + 80;
125                         while (q > p && *q != ' ')
126                                 q--;
127                         if (q != p)
128                                 *q = '\n';
129                 }
130                 p = q + 1;
131         }
132 }
133
134 /*
135  * Get various library compile-time versions and append them to
136  * the specified GString.
137  *
138  * "additional_info" is called at the end to append any additional
139  * information; this is required in order to, for example, put the
140  * Portaudio information at the end of the string, as we currently
141  * don't use Portaudio in TShark.
142  */
143 void
144 get_compiled_version_info(GString *str, void (*additional_info)(GString *))
145 {
146         /* GLIB */
147         g_string_append(str, "with ");
148         g_string_append_printf(str,
149 #ifdef GLIB_MAJOR_VERSION
150             "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
151             GLIB_MICRO_VERSION);
152 #else
153             "GLib (version unknown)");
154 #endif
155
156         /* Libpcap */
157         g_string_append(str, ", ");
158         get_compiled_pcap_version(str);
159
160         /* LIBZ */
161         g_string_append(str, ", ");
162 #ifdef HAVE_LIBZ
163         g_string_append(str, "with libz ");
164 #ifdef ZLIB_VERSION
165         g_string_append(str, ZLIB_VERSION);
166 #else /* ZLIB_VERSION */
167         g_string_append(str, "(version unknown)");
168 #endif /* ZLIB_VERSION */
169 #else /* HAVE_LIBZ */
170         g_string_append(str, "without libz");
171 #endif /* HAVE_LIBZ */
172
173         /* LIBCAP */
174         g_string_append(str, ", ");
175 #ifdef HAVE_LIBCAP
176         g_string_append(str, "with POSIX capabilities");
177 #ifdef _LINUX_CAPABILITY_VERSION
178         g_string_append(str, " (Linux)");
179 #endif /* _LINUX_CAPABILITY_VERSION */
180 #else /* HAVE_LIBCAP */
181         g_string_append(str, "without POSIX capabilities");
182 #endif /* HAVE_LIBCAP */
183
184         /* Additional application-dependent information */
185         if (additional_info)
186                 (*additional_info)(str);
187         g_string_append(str, ".");
188
189 #ifndef HAVE_LIBPCRE
190         g_string_append(str,
191         "\nNOTE: this build doesn't support the \"matches\" operator for Wireshark filter syntax");
192         g_string_append(str, ".");
193 #endif  /* HAVE_LIBPCRE */
194
195         end_string(str);
196 }
197
198 /*
199  * Get compile-time information used only by applications that use
200  * libwireshark.
201  */
202 void
203 get_epan_compiled_version_info(GString *str)
204 {
205         /* PCRE */
206         g_string_append(str, ", ");
207 #ifdef HAVE_LIBPCRE
208         g_string_append(str, "with libpcre ");
209 #ifdef PCRE_MAJOR
210 #ifdef PCRE_MINOR
211         g_string_append_printf(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
212 #else                   /* PCRE_MINOR */
213         g_string_append_printf(str, "%u", PCRE_MAJOR);
214 #endif                  /* PCRE_MINOR */
215 #else           /* PCRE_MAJOR */
216         g_string_append(str, "(version unknown)");
217 #endif          /* PCRE_MAJOR */
218 #else   /* HAVE_LIBPCRE */
219         g_string_append(str, "without libpcre");
220 #endif  /* HAVE_LIBPCRE */
221
222         /* SNMP */
223         g_string_append(str, ", ");
224 #ifdef HAVE_LIBSMI
225         g_string_append(str, "with SMI " SMI_VERSION_STRING);
226 #else /* no SNMP library */
227         g_string_append(str, "without SMI");
228 #endif /* _SMI_H */
229
230         /* c-ares */
231         g_string_append(str, ", ");
232 #ifdef HAVE_C_ARES
233         g_string_append(str, "with c-ares " ARES_VERSION_STR);
234 #else
235         g_string_append(str, "without c-ares");
236
237         /* ADNS - only add if no c-ares */
238         g_string_append(str, ", ");
239 #ifdef HAVE_GNU_ADNS
240         g_string_append(str, "with ADNS");
241 #else
242         g_string_append(str, "without ADNS");
243 #endif /* HAVE_GNU_ADNS */
244 #endif /* HAVE_C_ARES */
245
246         /* LUA */
247         g_string_append(str, ", ");
248 #ifdef HAVE_LUA_5_1
249         g_string_append(str, "with ");
250         g_string_append(str, LUA_VERSION);
251 #else
252         g_string_append(str, "without Lua");
253 #endif /* HAVE_LUA_5_1 */
254
255         g_string_append(str, ", ");
256 #ifdef HAVE_PYTHON
257         g_string_append(str, "with Python");
258 #ifdef PY_VERSION
259         g_string_append(str, " " PY_VERSION);
260 #endif /* PY_VERSION */
261 #else
262         g_string_append(str, "without Python");
263 #endif /* HAVE_PYTHON */
264
265         /* GnuTLS */
266         g_string_append(str, ", ");
267 #ifdef HAVE_LIBGNUTLS
268         g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
269 #else
270         g_string_append(str, "without GnuTLS");
271 #endif /* HAVE_LIBGNUTLS */
272
273         /* Gcrypt */
274         g_string_append(str, ", ");
275 #ifdef HAVE_LIBGCRYPT
276         g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
277 #else
278         g_string_append(str, "without Gcrypt");
279 #endif /* HAVE_LIBGCRYPT */
280
281         /* Kerberos */
282         /* XXX - I don't see how to get the version number, at least for KfW */
283         g_string_append(str, ", ");
284 #ifdef HAVE_KERBEROS
285 #ifdef HAVE_MIT_KERBEROS
286         g_string_append(str, "with MIT Kerberos");
287 #else
288         /* HAVE_HEIMDAL_KERBEROS */
289         g_string_append(str, "with Heimdal Kerberos");
290 #endif
291 #else
292         g_string_append(str, "without Kerberos");
293 #endif /* HAVE_KERBEROS */
294
295         /* GeoIP */
296         g_string_append(str, ", ");
297 #ifdef HAVE_GEOIP
298         g_string_append(str, "with GeoIP");
299 #else
300         g_string_append(str, "without GeoIP");
301 #endif /* HAVE_GEOIP */
302
303 }
304
305 /*
306  * Get various library run-time versions, and the OS version, and append
307  * them to the specified GString.
308  */
309 void
310 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
311 {
312 #if defined(_WIN32)
313         OSVERSIONINFOEX info;
314 #elif defined(HAVE_SYS_UTSNAME_H)
315         struct utsname name;
316 #endif
317 #if HAVE_OS_X_FRAMEWORKS
318         SInt32 macosx_ver, macosx_major_ver, macosx_minor_ver, macosx_bugfix_ver;
319 #endif
320
321         g_string_append(str, "on ");
322
323 #if defined(_WIN32)
324         /*
325          * See
326          *
327          *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
328          *
329          * for more than you ever wanted to know about determining the
330          * flavor of Windows on which you're running.  Implementing more
331          * of that is left as an exercise to the reader - who should
332          * check any copyright information about code samples on MSDN
333          * before cutting and pasting into Wireshark.
334          *
335          * They should also note that you need an OSVERSIONINFOEX structure
336          * to get some of that information, and that not only is that
337          * structure not supported on older versions of Windows, you might
338          * not even be able to compile code that *uses* that structure with
339          * older versions of the SDK.
340          */
341         info.dwOSVersionInfoSize = sizeof info;
342         if (!GetVersionEx((OSVERSIONINFO *)&info)) {
343                 /*
344                  * XXX - get the failure reason.
345                  */
346                 g_string_append(str, "unknown Windows version");
347                 return;
348         }
349         switch (info.dwPlatformId) {
350
351         case VER_PLATFORM_WIN32s:
352                 /* Shyeah, right. */
353                 g_string_append_printf(str, "Windows 3.1 with Win32s");
354                 break;
355
356         case VER_PLATFORM_WIN32_WINDOWS:
357                 /* Windows OT */
358                 switch (info.dwMajorVersion) {
359
360                 case 4:
361                         /* 3 cheers for Microsoft marketing! */
362                         switch (info.dwMinorVersion) {
363
364                         case 0:
365                                 g_string_append_printf(str, "Windows 95");
366                                 break;
367
368                         case 10:
369                                 g_string_append_printf(str, "Windows 98");
370                                 break;
371
372                         case 90:
373                                 g_string_append_printf(str, "Windows Me");
374                                 break;
375
376                         default:
377                                 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
378                                     info.dwMajorVersion, info.dwMinorVersion);
379                                 break;
380                         }
381                         break;
382
383                 default:
384                         g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
385                             info.dwMajorVersion, info.dwMinorVersion);
386                         break;
387                 }
388                 break;
389
390         case VER_PLATFORM_WIN32_NT:
391                 /* Windows NT */
392                 switch (info.dwMajorVersion) {
393
394                 case 3:
395                 case 4:
396                         g_string_append_printf(str, "Windows NT %lu.%lu",
397                             info.dwMajorVersion, info.dwMinorVersion);
398                         break;
399
400                 case 5:
401                         /* 3 cheers for Microsoft marketing! */
402                         switch (info.dwMinorVersion) {
403
404                         case 0:
405                                 g_string_append_printf(str, "Windows 2000");
406                                 break;
407
408                         case 1:
409                                 g_string_append_printf(str, "Windows XP");
410                                 break;
411
412                         case 2:
413                                 g_string_append_printf(str, "Windows Server 2003");
414                                 break;
415
416                         default:
417                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
418                                     info.dwMajorVersion, info.dwMinorVersion);
419                                 break;
420                         }
421                         break;
422
423                 case 6:
424 #ifndef VER_NT_WORKSTATION
425 #define VER_NT_WORKSTATION 0x01
426                         if ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION)
427 #else
428                         if (info.wProductType == VER_NT_WORKSTATION)
429 #endif
430                                 g_string_append_printf(str, "Windows Vista");
431                         else
432                                 g_string_append_printf(str, "Windows Server 2008");
433                         break;
434
435                 default:
436                         g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
437                             info.dwMajorVersion, info.dwMinorVersion);
438                         break;
439                 }
440                 break;
441
442         default:
443                 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
444                     info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
445                 break;
446         }
447         if (info.szCSDVersion[0] != '\0')
448                 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
449         g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
450 #elif defined(HAVE_SYS_UTSNAME_H)
451         /*
452          * We have <sys/utsname.h>, so we assume we have "uname()".
453          */
454         if (uname(&name) < 0) {
455                 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
456                     strerror(errno));
457                 return;
458         }
459
460         if (strcmp(name.sysname, "AIX") == 0) {
461                 /*
462                  * Yay, IBM!  Thanks for doing something different
463                  * from most of the other UNIXes out there, and
464                  * making "name.version" apparently be the major
465                  * version number and "name.release" be the minor
466                  * version number.
467                  */
468                 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
469                     name.release);
470         } else {
471                 /*
472                  * XXX - get "version" on any other platforms?
473                  *
474                  * On Digital/Tru64 UNIX, it's something unknown.
475                  * On Solaris, it's some kind of build information.
476                  * On HP-UX, it appears to be some sort of subrevision
477                  * thing.
478                  */
479                 g_string_append_printf(str, "%s %s", name.sysname, name.release);
480 #ifdef HAVE_OS_X_FRAMEWORKS
481                 Gestalt(gestaltSystemVersion, &macosx_ver);
482
483                 /* The following functions are only available in MacOS 10.4+ */
484                 if(macosx_ver >= 0x1040) {
485                         Gestalt(gestaltSystemVersionMajor, &macosx_major_ver);
486                         Gestalt(gestaltSystemVersionMinor, &macosx_minor_ver);
487                         Gestalt(gestaltSystemVersionBugFix, &macosx_bugfix_ver);
488
489                         g_string_append_printf(str, " (MacOS %ld.%ld.%ld)",
490                                           (long)macosx_major_ver,
491                                           (long)macosx_minor_ver,
492                                           (long)macosx_bugfix_ver);
493                 } else {
494                         g_string_append_printf(str, " (MacOS X < 10.4 [%lx])",
495                                           (long)macosx_ver);
496                         /* See Apple's Gestalt Manager Reference for meanings
497                          * of the macosx_ver values. */
498                 }
499 #endif /* HAVE_OS_X_FRAMEWORKS */
500         }
501 #else
502         g_string_append(str, "an unknown OS");
503 #endif
504
505         /* Libpcap */
506         g_string_append(str, ", ");
507         get_runtime_pcap_version(str);
508
509     /* GnuTLS */
510 #ifdef HAVE_LIBGNUTLS
511         g_string_append_printf(str, ", GnuTLS %s", gnutls_check_version(NULL));
512 #endif /* HAVE_LIBGNUTLS */
513
514         /* Gcrypt */
515 #ifdef HAVE_LIBGCRYPT
516         g_string_append_printf(str, ", Gcrypt %s", gcry_check_version(NULL));
517 #endif /* HAVE_LIBGCRYPT */
518
519         /* Additional application-dependent information */
520         if (additional_info)
521                 (*additional_info)(str);
522
523         g_string_append(str, ".");
524
525         /* Compiler info */
526
527         /*
528          * See http://predef.sourceforge.net/precomp.html for
529          * information on various defined strings.
530          *
531          * GCC's __VERSION__ is a nice text string for humans to
532          * read.  The page at predef.sourceforge.net largely
533          * describes numeric #defines that encode the version;
534          * if the compiler doesn't also offer a nice printable
535          * string, we should probably prettify the number somehow.
536          */
537 #if defined(__GNUC__) && defined(__VERSION__)
538         g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
539 #elif defined(__HP_aCC)
540         g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
541 #elif defined(__xlC__)
542         g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
543             (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
544 #ifdef __IBMC__
545         if ((__IBMC__ % 10) != 0)
546                 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
547 #endif /* __IBMC__ */
548         g_string_append_printf(str, "\n");
549 #elif defined(__INTEL_COMPILER)
550         g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
551             __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
552         if ((__INTEL_COMPILER % 10) != 0)
553                 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
554 #ifdef __INTEL_COMPILER_BUILD_DATE
555         g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
556             __INTEL_COMPILER_BUILD_DATE / 10000,
557             (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
558             __INTEL_COMPILER_BUILD_DATE % 100);
559 #endif /* __INTEL_COMPILER_BUILD_DATE */
560         g_string_append_printf(str, "\n");
561 #elif defined(_MSC_FULL_VER)
562         if (_MSC_FULL_VER > 99999999) {
563                 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
564                     (_MSC_FULL_VER / 10000000) - 6,
565                     (_MSC_FULL_VER / 100000) % 100);
566                 if ((_MSC_FULL_VER % 100000) != 0)
567                         g_string_append_printf(str, " build %d",
568                             _MSC_FULL_VER % 100000);
569         } else {
570                 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
571                     (_MSC_FULL_VER / 1000000) - 6,
572                     (_MSC_FULL_VER / 10000) % 100);
573                 if ((_MSC_FULL_VER % 10000) != 0)
574                         g_string_append_printf(str, " build %d",
575                             _MSC_FULL_VER % 10000);
576         }
577         g_string_append_printf(str, "\n");
578 #elif defined(_MSC_VER)
579         /* _MSC_FULL_VER not defined, but _MSC_VER defined */
580         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
581             (_MSC_VER / 100) - 6, _MSC_VER % 100);
582 #elif defined(__SUNPRO_C)
583         g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
584             (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
585         if ((__SUNPRO_C & 0xF) != 0)
586                 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
587         g_string_append_printf(str, "\n");
588 #endif
589
590         end_string(str);
591 }
592
593 /*
594  * Get copyright information.
595  */
596 const char *
597 get_copyright_info(void)
598 {
599         return
600 "Copyright 1998-2009 Gerald Combs <gerald@wireshark.org> and contributors.\n"
601 "This is free software; see the source for copying conditions. There is NO\n"
602 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
603 }
604
605 #if defined(_WIN32)
606 /*
607  * Get the major OS version.
608  */
609 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
610 guint32
611 get_os_major_version()
612 {
613         OSVERSIONINFO info;
614         info.dwOSVersionInfoSize = sizeof info;
615         if (GetVersionEx(&info)) {
616                 return info.dwMajorVersion;
617         }
618         return 0;
619 }
620 #endif
621
622 /*
623  * Editor modelines
624  *
625  * Local Variables:
626  * c-basic-offset: 8
627  * tab-width: 8
628  * indent-tabs-mode: t
629  * End:
630  *
631  * ex: set shiftwidth=8 tabstop=8 noexpandtab
632  * :indentSize=8:tabSize=8:noTabs=false:
633  */