e3ad4eb8b1714a8f8b724f88ac582dfcc71ccb66
[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  * See whether the last line in the string goes past column 80; if so,
93  * replace the blank at the specified point with a newline.
94  */
95 static void
96 do_word_wrap(GString *str, gint point)
97 {
98         char *line_begin;
99
100         line_begin = strrchr(str->str, '\n');
101         if (line_begin == NULL)
102                 line_begin = str->str;
103         else
104                 line_begin++;
105         if (strlen(line_begin) > 80) {
106                 g_assert(str->str[point] == ' ');
107                 str->str[point] = '\n';
108         }
109 }
110
111 /*
112  * If the string doesn't end with a newline, append one.
113  */
114 static void
115 end_string(GString *str)
116 {
117         size_t point;
118
119         point = strlen(str->str);
120         if (point == 0 || str->str[point - 1] != '\n')
121                 g_string_append(str, "\n");
122 }
123
124 /*
125  * Get various library compile-time versions and append them to
126  * the specified GString.
127  */
128 void
129 get_compiled_version_info(GString *str)
130 {
131         gint break_point;
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         g_string_append(str, " ");
144         break_point = str->len - 1;
145         get_compiled_pcap_version(str);
146         g_string_append(str, ",");
147         do_word_wrap(str, break_point);
148
149         /* LIBZ */
150         g_string_append(str, " ");
151         break_point = str->len - 1;
152 #ifdef HAVE_LIBZ
153         g_string_append(str, "with libz ");
154 #ifdef ZLIB_VERSION
155         g_string_append(str, ZLIB_VERSION);
156 #else /* ZLIB_VERSION */
157         g_string_append(str, "(version unknown)");
158 #endif /* ZLIB_VERSION */
159 #else /* HAVE_LIBZ */
160         g_string_append(str, "without libz");
161 #endif /* HAVE_LIBZ */
162         g_string_append(str, ",");
163         do_word_wrap(str, break_point);
164
165         /* PCRE */
166         g_string_append(str, " ");
167         break_point = str->len - 1;
168 #ifdef HAVE_LIBPCRE
169         g_string_append(str, "with libpcre ");
170 #ifdef PCRE_MAJOR
171 #ifdef PCRE_MINOR
172         g_string_sprintfa(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
173 #else                   /* PCRE_MINOR */
174         g_string_sprintfa(str, "%u", PCRE_MAJOR);
175 #endif                  /* PCRE_MINOR */
176 #else           /* PCRE_MAJOR */
177         g_string_append(str, "(version unknown)");
178 #endif          /* PCRE_MAJOR */
179 #else   /* HAVE_LIBPCRE */
180         g_string_append(str, "without libpcre");
181 #endif  /* HAVE_LIBPCRE */
182
183         g_string_append(str, ",");
184         do_word_wrap(str, break_point);
185
186         /* SNMP */
187 /* Oh, this is pretty. */
188 /* Oh, ha.  you think that was pretty.  Try this:! --Wes */
189         g_string_append(str, " ");
190         break_point = str->len - 1;
191 #ifdef HAVE_SOME_SNMP
192
193 #ifdef HAVE_UCD_SNMP
194         g_string_append(str, "with UCD-SNMP ");
195         g_string_append(str, VersionInfo);
196 #endif /* HAVE_UCD_SNMP */
197
198 #ifdef HAVE_NET_SNMP
199         g_string_append(str, "with Net-SNMP ");
200         g_string_append(str, netsnmp_get_version());
201 #endif /* HAVE_NET_SNMP */
202
203 #else /* no SNMP library */
204         g_string_append(str, "without UCD-SNMP or Net-SNMP");
205 #endif /* HAVE_SOME_SNMP */
206         g_string_append(str, ",");
207         do_word_wrap(str, break_point);
208
209         /* ADNS */
210         g_string_append(str, " ");
211         break_point = str->len - 1;
212 #ifdef HAVE_GNU_ADNS
213         g_string_append(str, "with ADNS");
214 #else
215         g_string_append(str, "without ADNS");
216 #endif /* HAVE_GNU_ADNS */
217         g_string_append(str, ",");
218         do_word_wrap(str, break_point);
219
220         /* LUA */
221         g_string_append(str, " ");
222         break_point = str->len - 1;
223 #ifdef HAVE_LUA
224         g_string_append(str, "with ");
225         g_string_append(str, LUA_VERSION);
226 #else
227         g_string_append(str, "without Lua");
228 #endif /* HAVE_LUA */
229         g_string_append(str, ",");
230         do_word_wrap(str, break_point);
231
232         /* GnuTLS */
233         g_string_append(str, " ");
234         break_point = str->len - 1;
235 #ifdef HAVE_LIBGNUTLS
236         g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
237 #else
238         g_string_append(str, "without GnuTLS");
239 #endif /* HAVE_LIBGNUTLS */
240         g_string_append(str, ",");
241         do_word_wrap(str, break_point);
242
243         /* Gcrypt */
244         g_string_append(str, " ");
245         break_point = str->len - 1;
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         g_string_append(str, ",");
252         do_word_wrap(str, break_point);
253
254         /* Kerberos */
255         /* XXX - I don't see how to get the version number, at least for KfW */
256         g_string_append(str, " ");
257         break_point = str->len - 1;
258 #ifdef HAVE_KERBEROS
259 #ifdef HAVE_MIT_KERBEROS
260         g_string_append(str, "with MIT Kerberos");
261 #else
262         /* HAVE_HEIMDAL_KERBEROS */
263         g_string_append(str, "with Heimdal Kerberos");
264 #endif
265 #else
266         g_string_append(str, "without Kerberos");
267 #endif /* HAVE_KERBEROS */
268         g_string_append(str, ".");
269         do_word_wrap(str, break_point);
270
271 #ifndef HAVE_LIBPCRE
272         break_point = str->len - 1;
273         g_string_append(str,
274                         "\nNOTE: this build doesn't support the \"matches\" operator for Wireshark filter"
275                         "\nsyntax.");
276         do_word_wrap(str, break_point);
277 #endif  /* HAVE_LIBPCRE */
278
279         end_string(str);
280 }
281
282 /*
283  * Get various library run-time versions, and the OS version, and append
284  * them to the specified GString.
285  */
286 void
287 get_runtime_version_info(GString *str)
288 {
289 #if defined(_WIN32)
290         OSVERSIONINFO info;
291 #elif defined(HAVE_SYS_UTSNAME_H)
292         struct utsname name;
293 #endif
294
295         get_runtime_pcap_version(str);
296
297         g_string_append(str, "on ");
298 #if defined(_WIN32)
299         /*
300          * See
301          *
302          *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
303          *
304          * for more than you ever wanted to know about determining the
305          * flavor of Windows on which you're running.  Implementing more
306          * of that is left as an exercise to the reader - who should
307          * check any copyright information about code samples on MSDN
308          * before cutting and pasting into Wireshark.
309          *
310          * They should also note that you need an OSVERSIONINFOEX structure
311          * to get some of that information, and that not only is that
312          * structure not supported on older versions of Windows, you might
313          * not even be able to compile code that *uses* that structure with
314          * older versions of the SDK.
315          */
316         info.dwOSVersionInfoSize = sizeof info;
317         if (!GetVersionEx(&info)) {
318                 /*
319                  * XXX - get the failure reason.
320                  */
321                 g_string_append(str, "unknown Windows version");
322                 return;
323         }
324         switch (info.dwPlatformId) {
325
326         case VER_PLATFORM_WIN32s:
327                 /* Shyeah, right. */
328                 g_string_sprintfa(str, "Windows 3.1 with Win32s");
329                 break;
330
331         case VER_PLATFORM_WIN32_WINDOWS:
332                 /* Windows OT */
333                 switch (info.dwMajorVersion) {
334
335                 case 4:
336                         /* 3 cheers for Microsoft marketing! */
337                         switch (info.dwMinorVersion) {
338
339                         case 0:
340                                 g_string_sprintfa(str, "Windows 95");
341                                 break;
342
343                         case 10:
344                                 g_string_sprintfa(str, "Windows 98");
345                                 break;
346
347                         case 90:
348                                 g_string_sprintfa(str, "Windows Me");
349                                 break;
350
351                         default:
352                                 g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
353                                     info.dwMajorVersion, info.dwMinorVersion);
354                                 break;
355                         }
356                         break;
357
358                 default:
359                         g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
360                             info.dwMajorVersion, info.dwMinorVersion);
361                         break;
362                 }
363                 break;
364
365         case VER_PLATFORM_WIN32_NT:
366                 /* Windows NT */
367                 switch (info.dwMajorVersion) {
368
369                 case 3:
370                 case 4:
371                         g_string_sprintfa(str, "Windows NT %lu.%lu",
372                             info.dwMajorVersion, info.dwMinorVersion);
373                         break;
374
375                 case 5:
376                         /* 3 cheers for Microsoft marketing! */
377                         switch (info.dwMinorVersion) {
378
379                         case 0:
380                                 g_string_sprintfa(str, "Windows 2000");
381                                 break;
382
383                         case 1:
384                                 g_string_sprintfa(str, "Windows XP");
385                                 break;
386
387                         case 2:
388                                 g_string_sprintfa(str, "Windows Server 2003");
389                                 break;
390
391                         default:
392                                 g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
393                                     info.dwMajorVersion, info.dwMinorVersion);
394                                 break;
395                         }
396                         break;
397
398                 case 6:
399                         g_string_sprintfa(str, "Windows Vista");
400                         break;
401
402                 default:
403                         g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
404                             info.dwMajorVersion, info.dwMinorVersion);
405                         break;
406                 }
407                 break;
408
409         default:
410                 g_string_sprintfa(str, "Unknown Windows platform %lu version %lu.%lu",
411                     info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
412                 break;
413         }
414         if (info.szCSDVersion[0] != '\0')
415                 g_string_sprintfa(str, " %s", utf_16to8(info.szCSDVersion));
416         g_string_sprintfa(str, ", build %lu", info.dwBuildNumber);
417 #elif defined(HAVE_SYS_UTSNAME_H)
418         /*
419          * We have <sys/utsname.h>, so we assume we have "uname()".
420          */
421         if (uname(&name) < 0) {
422                 g_string_sprintfa(str, "unknown OS version (uname failed - %s)",
423                     strerror(errno));
424                 return;
425         }
426
427         if (strcmp(name.sysname, "AIX") == 0) {
428                 /*
429                  * Yay, IBM!  Thanks for doing something different
430                  * from most of the other UNIXes out there, and
431                  * making "name.version" apparently be the major
432                  * version number and "name.release" be the minor
433                  * version number.
434                  */
435                 g_string_sprintfa(str, "%s %s.%s", name.sysname, name.version,
436                     name.release);
437         } else {
438                 /*
439                  * XXX - get "version" on any other platforms?
440                  *
441                  * On Digital/Tru65 UNIX, it's something unknown.
442                  * On Solaris, it's some kind of build information.
443                  * On HP-UX, it appears to be some sort of subrevision
444                  * thing.
445                  */
446                 g_string_sprintfa(str, "%s %s", name.sysname, name.release);
447         }
448 #else
449         g_string_append(str, "an unknown OS");
450 #endif
451         g_string_append(str, ".");
452
453         end_string(str);
454 }
455
456 /*
457  * Get copyright information.
458  */
459 const char *
460 get_copyright_info(void)
461 {
462         return
463 "Copyright 1998-2006 Gerald Combs <gerald@wireshark.org> and contributors.\n"
464 "This is free software; see the source for copying conditions. There is NO\n"
465 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
466 }