bugfix: don't crash, if tag_save_literal == NULL
[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  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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 #ifdef HAVE_LIBPCAP
30 #include <pcap.h>
31 #endif /* HAVE_LIBPCAP */
32
33 #include <glib.h>
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include <errno.h>
38
39 #ifdef HAVE_LIBZ
40 #include <zlib.h>       /* to get the libz version number */
41 #endif
42
43 #ifdef HAVE_LIBPCRE
44 #include <pcre.h>       /* to get the libpcre version number */
45 #endif /* HAVE_LIBPCRE */
46
47 /*
48  * This has to come after the include of <pcap.h>, as the include of
49  * <pcap.h> might cause <winsock2.h> to be included, and if we've
50  * already included <winsock.h> as a result of including <windows.h>,
51  * we get a bunch of redefinitions.
52  */
53 #ifdef HAVE_WINDOWS_H
54 #include <windows.h>
55 #endif
56
57 #ifdef HAVE_SOME_SNMP
58
59 #ifdef HAVE_NET_SNMP
60 #include <net-snmp/version.h>
61 #endif /* HAVE_NET_SNMP */
62
63 #ifdef HAVE_UCD_SNMP
64 #include <ucd-snmp/version.h>
65 #endif /* HAVE_UCD_SNMP */
66
67 #endif /* HAVE_SOME_SNMP */
68
69 #ifdef HAVE_SYS_UTSNAME_H
70 #include <sys/utsname.h>
71 #endif
72
73 #include "version_info.h"
74 #include "pcap-util.h"
75
76 #include "svnversion.h"
77
78 #ifdef SVNVERSION
79         const char *svnversion = " (" SVNVERSION ")";
80 #else
81         const char *svnversion = "";
82 #endif
83
84
85 /*
86  * See whether the last line in the string goes past column 80; if so,
87  * replace the blank at the specified point with a newline.
88  */
89 static void
90 do_word_wrap(GString *str, gint point)
91 {
92         char *line_begin;
93
94         line_begin = strrchr(str->str, '\n');
95         if (line_begin == NULL)
96                 line_begin = str->str;
97         else
98                 line_begin++;
99         if (strlen(line_begin) > 80) {
100                 g_assert(str->str[point] == ' ');
101                 str->str[point] = '\n';
102         }
103 }       
104
105 /*
106  * Get various library compile-time versions and append them to
107  * the specified GString.
108  */
109 void
110 get_compiled_version_info(GString *str)
111 {
112         gint break_point;
113
114         g_string_append(str, "with ");
115         g_string_sprintfa(str,
116 #ifdef GLIB_MAJOR_VERSION
117             "GLib %d.%d.%d,", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
118             GLIB_MICRO_VERSION);
119 #else
120             "GLib (version unknown),");
121 #endif
122
123         g_string_append(str, " ");
124         break_point = str->len - 1;
125         get_compiled_pcap_version(str);
126         g_string_append(str, ",");
127         do_word_wrap(str, break_point);
128
129         g_string_append(str, " ");
130         break_point = str->len - 1;
131 #ifdef HAVE_LIBZ
132         g_string_append(str, "with libz ");
133 #ifdef ZLIB_VERSION
134         g_string_append(str, ZLIB_VERSION);
135 #else /* ZLIB_VERSION */
136         g_string_append(str, "(version unknown)");
137 #endif /* ZLIB_VERSION */
138 #else /* HAVE_LIBZ */
139         g_string_append(str, "without libz");
140 #endif /* HAVE_LIBZ */
141         g_string_append(str, ",");
142         do_word_wrap(str, break_point);
143
144         g_string_append(str, " ");
145         break_point = str->len - 1;
146 #ifdef HAVE_LIBPCRE
147         g_string_append(str, "with libpcre ");
148 #ifdef PCRE_MAJOR
149 #ifdef PCRE_MINOR
150         g_string_sprintfa(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
151 #else                   /* PCRE_MINOR */
152         g_string_sprintfa(str, "%u", PCRE_MAJOR);
153 #endif                  /* PCRE_MINOR */
154 #else           /* PCRE_MAJOR */
155         g_string_append(str, "(version unknown)");
156 #endif          /* PCRE_MAJOR */
157 #else   /* HAVE_LIBPCRE */
158         g_string_append(str, "without libpcre");
159 #endif  /* HAVE_LIBPCRE */
160
161         g_string_append(str, ",");
162         do_word_wrap(str, break_point);
163
164 /* Oh, this is pretty. */
165 /* Oh, ha.  you think that was pretty.  Try this:! --Wes */
166         g_string_append(str, " ");
167         break_point = str->len - 1;
168 #ifdef HAVE_SOME_SNMP
169
170 #ifdef HAVE_UCD_SNMP
171         g_string_append(str, "with UCD-SNMP ");
172         g_string_append(str, VersionInfo);
173 #endif /* HAVE_UCD_SNMP */
174
175 #ifdef HAVE_NET_SNMP
176         g_string_append(str, "with Net-SNMP ");
177         g_string_append(str, netsnmp_get_version());
178 #endif /* HAVE_NET_SNMP */
179
180 #else /* no SNMP library */
181         g_string_append(str, "without UCD-SNMP or Net-SNMP");
182 #endif /* HAVE_SOME_SNMP */
183         g_string_append(str, ",");
184         do_word_wrap(str, break_point);
185
186         g_string_append(str, " ");
187         break_point = str->len - 1;
188 #ifdef HAVE_GNU_ADNS
189         g_string_append(str, "with ADNS");
190 #else
191         g_string_append(str, "without ADNS");
192 #endif /* HAVE_GNU_ADNS */
193
194         g_string_append(str, ".");
195         do_word_wrap(str, break_point);
196
197 #ifndef HAVE_LIBPCRE
198         break_point = str->len - 1;
199         g_string_append(str,
200                         "\nNOTE: this build doesn't support the \"matches\" operator for Ethereal filter"
201                         "\nsyntax.");
202         do_word_wrap(str, break_point);
203 #endif  /* HAVE_LIBPCRE */
204 }
205
206 /*
207  * Get various library run-time versions, and the OS version, and append
208  * them to the specified GString.
209  */
210 void
211 get_runtime_version_info(GString *str)
212 {
213 #if defined(_WIN32)
214         OSVERSIONINFO info;
215 #elif defined(HAVE_SYS_UTSNAME_H)
216         struct utsname name;
217 #endif
218
219         get_runtime_pcap_version(str);
220
221         g_string_append(str, "on ");
222 #if defined(_WIN32)
223         info.dwOSVersionInfoSize = sizeof info;
224         if (!GetVersionEx(&info)) {
225                 /*
226                  * XXX - get the failure reason.
227                  */
228                 g_string_append(str, "unknown Windows version");
229                 return;
230         }
231         switch (info.dwPlatformId) {
232
233         case VER_PLATFORM_WIN32s:
234                 /* Shyeah, right. */
235                 g_string_sprintfa(str, "Windows 3.1 with Win32s");
236                 break;
237
238         case VER_PLATFORM_WIN32_WINDOWS:
239                 /* Windows OT */
240                 switch (info.dwMajorVersion) {
241
242                 case 4:
243                         /* 3 cheers for Microsoft marketing! */
244                         switch (info.dwMinorVersion) {
245
246                         case 0:
247                                 g_string_sprintfa(str, "Windows 95");
248                                 break;
249
250                         case 10:
251                                 g_string_sprintfa(str, "Windows 98");
252                                 break;
253
254                         case 90:
255                                 g_string_sprintfa(str, "Windows Me");
256                                 break;
257
258                         default:
259                                 g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
260                                     info.dwMajorVersion, info.dwMinorVersion);
261                                 break;
262                         }
263                         break;
264
265                 default:
266                         g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
267                             info.dwMajorVersion, info.dwMinorVersion);
268                         break;
269                 }
270                 break;
271
272         case VER_PLATFORM_WIN32_NT:
273                 /* Windows NT */
274                 switch (info.dwMajorVersion) {
275
276                 case 3:
277                 case 4:
278                         g_string_sprintfa(str, "Windows NT %lu.%lu",
279                             info.dwMajorVersion, info.dwMinorVersion);
280                         break;
281
282                 case 5:
283                         /* 3 cheers for Microsoft marketing! */
284                         switch (info.dwMinorVersion) {
285
286                         case 0:
287                                 g_string_sprintfa(str, "Windows 2000");
288                                 break;
289
290                         case 1:
291                                 g_string_sprintfa(str, "Windows XP");
292                                 break;
293
294                         case 2:
295                                 g_string_sprintfa(str, "Windows Server 2003");
296                                 break;
297
298                         default:
299                                 g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
300                                     info.dwMajorVersion, info.dwMinorVersion);
301                                 break;
302                         }
303                         break;
304
305                 default:
306                         g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
307                             info.dwMajorVersion, info.dwMinorVersion);
308                         break;
309                 }
310                 break;
311
312         default:
313                 g_string_sprintfa(str, "Unknown Windows platform %lu version %lu.%lu",
314                     info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
315                 break;
316         }
317         if (info.szCSDVersion[0] != '\0')
318                 g_string_sprintfa(str, " %s", info.szCSDVersion);
319         g_string_sprintfa(str, ", build %lu", info.dwBuildNumber);
320 #elif defined(HAVE_SYS_UTSNAME_H)
321         /*
322          * We have <sys/utsname.h>, so we assume we have "uname()".
323          */
324         if (uname(&name) < 0) {
325                 g_string_sprintfa(str, "unknown OS version (uname failed - %s)",
326                     strerror(errno));
327                 return;
328         }
329
330         if (strcmp(name.sysname, "AIX") == 0) {
331                 /*
332                  * Yay, IBM!  Thanks for doing something different
333                  * from most of the other UNIXes out there, and
334                  * making "name.version" apparently be the major
335                  * version number and "name.release" be the minor
336                  * version number.
337                  */
338                 g_string_sprintfa(str, "%s %s.%s", name.sysname, name.version,
339                     name.release);
340         } else {
341                 /*
342                  * XXX - get "version" on any other platforms?
343                  *
344                  * On Digital/Tru65 UNIX, it's something unknown.
345                  * On Solaris, it's some kind of build information.
346                  * On HP-UX, it appears to be some sort of subrevision
347                  * thing.
348                  */
349                 g_string_sprintfa(str, "%s %s", name.sysname, name.release);
350         }
351 #else
352         g_string_append(str, "an unknown OS");
353 #endif
354         g_string_append(str, ".");
355 }