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