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