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