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