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