Add info as to 32/64 bit and also if "Windows 7" to runtime version info.
[metze/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 " from " SVNPATH ")";
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         SYSTEM_INFO system_info;
315 #elif defined(HAVE_SYS_UTSNAME_H)
316         struct utsname name;
317 #endif
318 #if HAVE_OS_X_FRAMEWORKS
319         SInt32 macosx_ver, macosx_major_ver, macosx_minor_ver, macosx_bugfix_ver;
320 #endif
321
322         g_string_append(str, "on ");
323
324 #if defined(_WIN32)
325         /*
326          * See
327          *
328          *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
329          *
330          * for more than you ever wanted to know about determining the
331          * flavor of Windows on which you're running.  Implementing more
332          * of that is left as an exercise to the reader - who should
333          * check any copyright information about code samples on MSDN
334          * before cutting and pasting into Wireshark.
335          *
336          * They should also note that you need an OSVERSIONINFOEX structure
337          * to get some of that information, and that not only is that
338          * structure not supported on older versions of Windows, you might
339          * not even be able to compile code that *uses* that structure with
340          * older versions of the SDK.
341          */
342
343         memset(&info, '\0', sizeof info);
344         info.dwOSVersionInfoSize = sizeof info;
345         if (!GetVersionEx((OSVERSIONINFO *)&info)) {
346                 /*
347                  * XXX - get the failure reason.
348                  */
349                 g_string_append(str, "unknown Windows version");
350                 return;
351         }
352
353         memset(&system_info, '\0', sizeof system_info);
354         GetSystemInfo(&system_info);    /* only for W2K or greater .... (which is what we suuport) */
355
356         switch (info.dwPlatformId) {
357
358         case VER_PLATFORM_WIN32s:
359                 /* Shyeah, right. */
360                 g_string_append_printf(str, "Windows 3.1 with Win32s");
361                 break;
362
363         case VER_PLATFORM_WIN32_WINDOWS:
364                 /* Windows OT */
365                 switch (info.dwMajorVersion) {
366
367                 case 4:
368                         /* 3 cheers for Microsoft marketing! */
369                         switch (info.dwMinorVersion) {
370
371                         case 0:
372                                 g_string_append_printf(str, "Windows 95");
373                                 break;
374
375                         case 10:
376                                 g_string_append_printf(str, "Windows 98");
377                                 break;
378
379                         case 90:
380                                 g_string_append_printf(str, "Windows Me");
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                 default:
391                         g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
392                             info.dwMajorVersion, info.dwMinorVersion);
393                         break;
394                 }
395                 break;
396
397         case VER_PLATFORM_WIN32_NT:
398                 /* Windows NT */
399                 switch (info.dwMajorVersion) {
400
401                 case 3:
402                 case 4:
403                         g_string_append_printf(str, "Windows NT %lu.%lu",
404                             info.dwMajorVersion, info.dwMinorVersion);
405                         break;
406
407                 case 5:
408                         /* 3 cheers for Microsoft marketing! */
409                         switch (info.dwMinorVersion) {
410
411                         case 0:
412                                 g_string_append_printf(str, "Windows 2000");
413                                 break;
414
415                         case 1:
416                                 g_string_append_printf(str, "Windows XP");
417                                 break;
418
419                         case 2:
420                                 if ((info.wProductType == VER_NT_WORKSTATION) &&
421                                     (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
422                                         g_string_append_printf(str, "Windows XP Professional x64 Edition");
423                                 } else {
424                                         g_string_append_printf(str, "Windows Server 2003");
425                                         if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
426                                                 g_string_append_printf(str, " X64 Edition");
427                                 }
428                                 break;
429
430                         default:
431                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
432                                     info.dwMajorVersion, info.dwMinorVersion);
433                                 break;
434                         }
435                         break;
436
437                 case 6: {
438                         gboolean is_nt_workstation;
439
440                         if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
441                                 g_string_append(str, "64-bit ");
442                         else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
443                                 g_string_append(str, "32-bit ");
444 #ifndef VER_NT_WORKSTATION
445 #define VER_NT_WORKSTATION 0x01
446                         is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
447 #else
448                         is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
449 #endif
450                         switch (info.dwMinorVersion) {
451                         case 0:
452                                 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
453                                 break;
454                         case 1:
455                                 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
456                                 break;
457                         default:
458                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
459                                                        info.dwMajorVersion, info.dwMinorVersion);
460                                 break;
461                         }
462                         break;
463                 }  /* case 6 */
464                 default:
465                         g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
466                             info.dwMajorVersion, info.dwMinorVersion);
467                         break;
468                 } /* info.dwMajorVersion */
469                 break;
470
471         default:
472                 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
473                     info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
474                 break;
475         }
476         if (info.szCSDVersion[0] != '\0')
477                 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
478         g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
479 #elif defined(HAVE_SYS_UTSNAME_H)
480         /*
481          * We have <sys/utsname.h>, so we assume we have "uname()".
482          */
483         if (uname(&name) < 0) {
484                 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
485                     strerror(errno));
486                 return;
487         }
488
489         if (strcmp(name.sysname, "AIX") == 0) {
490                 /*
491                  * Yay, IBM!  Thanks for doing something different
492                  * from most of the other UNIXes out there, and
493                  * making "name.version" apparently be the major
494                  * version number and "name.release" be the minor
495                  * version number.
496                  */
497                 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
498                     name.release);
499         } else {
500                 /*
501                  * XXX - get "version" on any other platforms?
502                  *
503                  * On Digital/Tru64 UNIX, it's something unknown.
504                  * On Solaris, it's some kind of build information.
505                  * On HP-UX, it appears to be some sort of subrevision
506                  * thing.
507                  */
508                 g_string_append_printf(str, "%s %s", name.sysname, name.release);
509 #ifdef HAVE_OS_X_FRAMEWORKS
510                 Gestalt(gestaltSystemVersion, &macosx_ver);
511
512                 /* The following functions are only available in MacOS 10.4+ */
513                 if(macosx_ver >= 0x1040) {
514                         Gestalt(gestaltSystemVersionMajor, &macosx_major_ver);
515                         Gestalt(gestaltSystemVersionMinor, &macosx_minor_ver);
516                         Gestalt(gestaltSystemVersionBugFix, &macosx_bugfix_ver);
517
518                         g_string_append_printf(str, " (MacOS %ld.%ld.%ld)",
519                                           (long)macosx_major_ver,
520                                           (long)macosx_minor_ver,
521                                           (long)macosx_bugfix_ver);
522                 } else {
523                         g_string_append_printf(str, " (MacOS X < 10.4 [%lx])",
524                                           (long)macosx_ver);
525                         /* See Apple's Gestalt Manager Reference for meanings
526                          * of the macosx_ver values. */
527                 }
528 #endif /* HAVE_OS_X_FRAMEWORKS */
529         }
530 #else
531         g_string_append(str, "an unknown OS");
532 #endif
533
534         /* Libpcap */
535         g_string_append(str, ", ");
536         get_runtime_pcap_version(str);
537
538     /* GnuTLS */
539 #ifdef HAVE_LIBGNUTLS
540         g_string_append_printf(str, ", GnuTLS %s", gnutls_check_version(NULL));
541 #endif /* HAVE_LIBGNUTLS */
542
543         /* Gcrypt */
544 #ifdef HAVE_LIBGCRYPT
545         g_string_append_printf(str, ", Gcrypt %s", gcry_check_version(NULL));
546 #endif /* HAVE_LIBGCRYPT */
547
548         /* Additional application-dependent information */
549         if (additional_info)
550                 (*additional_info)(str);
551
552         g_string_append(str, ".");
553
554         /* Compiler info */
555
556         /*
557          * See http://predef.sourceforge.net/precomp.html for
558          * information on various defined strings.
559          *
560          * GCC's __VERSION__ is a nice text string for humans to
561          * read.  The page at predef.sourceforge.net largely
562          * describes numeric #defines that encode the version;
563          * if the compiler doesn't also offer a nice printable
564          * string, we should probably prettify the number somehow.
565          */
566 #if defined(__GNUC__) && defined(__VERSION__)
567         g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
568 #elif defined(__HP_aCC)
569         g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
570 #elif defined(__xlC__)
571         g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
572             (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
573 #ifdef __IBMC__
574         if ((__IBMC__ % 10) != 0)
575                 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
576 #endif /* __IBMC__ */
577         g_string_append_printf(str, "\n");
578 #elif defined(__INTEL_COMPILER)
579         g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
580             __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
581         if ((__INTEL_COMPILER % 10) != 0)
582                 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
583 #ifdef __INTEL_COMPILER_BUILD_DATE
584         g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
585             __INTEL_COMPILER_BUILD_DATE / 10000,
586             (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
587             __INTEL_COMPILER_BUILD_DATE % 100);
588 #endif /* __INTEL_COMPILER_BUILD_DATE */
589         g_string_append_printf(str, "\n");
590 #elif defined(_MSC_FULL_VER)
591         if (_MSC_FULL_VER > 99999999) {
592                 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
593                     (_MSC_FULL_VER / 10000000) - 6,
594                     (_MSC_FULL_VER / 100000) % 100);
595                 if ((_MSC_FULL_VER % 100000) != 0)
596                         g_string_append_printf(str, " build %d",
597                             _MSC_FULL_VER % 100000);
598         } else {
599                 g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
600                     (_MSC_FULL_VER / 1000000) - 6,
601                     (_MSC_FULL_VER / 10000) % 100);
602                 if ((_MSC_FULL_VER % 10000) != 0)
603                         g_string_append_printf(str, " build %d",
604                             _MSC_FULL_VER % 10000);
605         }
606         g_string_append_printf(str, "\n");
607 #elif defined(_MSC_VER)
608         /* _MSC_FULL_VER not defined, but _MSC_VER defined */
609         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
610             (_MSC_VER / 100) - 6, _MSC_VER % 100);
611 #elif defined(__SUNPRO_C)
612         g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
613             (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
614         if ((__SUNPRO_C & 0xF) != 0)
615                 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
616         g_string_append_printf(str, "\n");
617 #endif
618
619         end_string(str);
620 }
621
622 /*
623  * Get copyright information.
624  */
625 const char *
626 get_copyright_info(void)
627 {
628         return
629 "Copyright 1998-2009 Gerald Combs <gerald@wireshark.org> and contributors.\n"
630 "This is free software; see the source for copying conditions. There is NO\n"
631 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
632 }
633
634 #if defined(_WIN32)
635 /*
636  * Get the major OS version.
637  */
638 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
639 guint32
640 get_os_major_version()
641 {
642         OSVERSIONINFO info;
643         info.dwOSVersionInfoSize = sizeof info;
644         if (GetVersionEx(&info)) {
645                 return info.dwMajorVersion;
646         }
647         return 0;
648 }
649 #endif
650
651 /*
652  * Editor modelines
653  *
654  * Local Variables:
655  * c-basic-offset: 8
656  * tab-width: 8
657  * indent-tabs-mode: t
658  * End:
659  *
660  * ex: set shiftwidth=8 tabstop=8 noexpandtab
661  * :indentSize=8:tabSize=8:noTabs=false:
662  */