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