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