2 * Routines to report version information for stuff used by Ethereal
4 * $Id: version_info.c,v 1.4 2004/05/22 04:15:01 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
31 #endif /* HAVE_LIBPCAP */
40 #include <zlib.h> /* to get the libz version number */
44 #include <pcre.h> /* to get the libpcre version number */
45 #endif /* HAVE_LIBPCRE */
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.
60 #include <net-snmp/version.h>
61 #endif /* HAVE_NET_SNMP */
64 #include <ucd-snmp/version.h>
65 #endif /* HAVE_UCD_SNMP */
67 #endif /* HAVE_SOME_SNMP */
69 #ifdef HAVE_SYS_UTSNAME_H
70 #include <sys/utsname.h>
73 #include "version_info.h"
74 #include "pcap-util.h"
77 * See whether the last line in the string goes past column 80; if so,
78 * replace the blank at the specified point with a newline.
81 do_word_wrap(GString *str, gint point)
85 line_begin = strrchr(str->str, '\n');
86 if (line_begin == NULL)
87 line_begin = str->str;
90 if (strlen(line_begin) > 80) {
91 g_assert(str->str[point] == ' ');
92 str->str[point] = '\n';
97 * Get various library compile-time versions and append them to
98 * the specified GString.
101 get_compiled_version_info(GString *str)
105 g_string_append(str, "with ");
106 g_string_sprintfa(str,
107 #ifdef GLIB_MAJOR_VERSION
108 "GLib %d.%d.%d,", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
111 "GLib (version unknown),");
114 g_string_append(str, " ");
115 break_point = str->len - 1;
116 get_compiled_pcap_version(str);
117 g_string_append(str, ",");
118 do_word_wrap(str, break_point);
120 g_string_append(str, " ");
121 break_point = str->len - 1;
123 g_string_append(str, "with libz ");
125 g_string_append(str, ZLIB_VERSION);
126 #else /* ZLIB_VERSION */
127 g_string_append(str, "(version unknown)");
128 #endif /* ZLIB_VERSION */
129 #else /* HAVE_LIBZ */
130 g_string_append(str, "without libz");
131 #endif /* HAVE_LIBZ */
132 g_string_append(str, ",");
133 do_word_wrap(str, break_point);
135 g_string_append(str, " ");
136 break_point = str->len - 1;
138 g_string_append(str, "with libpcre ");
141 g_string_sprintfa(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
142 #else /* PCRE_MINOR */
143 g_string_sprintfa(str, "%u", PCRE_MAJOR);
144 #endif /* PCRE_MINOR */
145 #else /* PCRE_MAJOR */
146 g_string_append(str, "(version unknown)");
147 #endif /* PCRE_MAJOR */
148 #else /* HAVE_LIBPCRE */
149 g_string_append(str, "without libpcre");
150 #endif /* HAVE_LIBPCRE */
152 g_string_append(str, ",");
153 do_word_wrap(str, break_point);
155 /* Oh, this is pretty. */
156 /* Oh, ha. you think that was pretty. Try this:! --Wes */
157 g_string_append(str, " ");
158 break_point = str->len - 1;
159 #ifdef HAVE_SOME_SNMP
162 g_string_append(str, "with UCD-SNMP ");
163 g_string_append(str, VersionInfo);
164 #endif /* HAVE_UCD_SNMP */
167 g_string_append(str, "with Net-SNMP ");
168 g_string_append(str, netsnmp_get_version());
169 #endif /* HAVE_NET_SNMP */
171 #else /* no SNMP library */
172 g_string_append(str, "without UCD-SNMP or Net-SNMP");
173 #endif /* HAVE_SOME_SNMP */
174 g_string_append(str, ",");
175 do_word_wrap(str, break_point);
177 g_string_append(str, " ");
178 break_point = str->len - 1;
180 g_string_append(str, "with ADNS");
182 g_string_append(str, "without ADNS");
183 #endif /* HAVE_GNU_ADNS */
185 g_string_append(str, ".");
186 do_word_wrap(str, break_point);
189 break_point = str->len - 1;
191 "\nNOTE: this build does not support the \"matches\" operator for Ethereal filter"
193 do_word_wrap(str, break_point);
194 #endif /* HAVE_LIBPCRE */
198 * Get various library run-time versions, and the OS version, and append
199 * them to the specified GString.
202 get_runtime_version_info(GString *str)
206 #elif defined(HAVE_SYS_UTSNAME_H)
210 get_runtime_pcap_version(str);
212 g_string_append(str, "on ");
214 info.dwOSVersionInfoSize = sizeof info;
215 if (!GetVersionEx(&info)) {
217 * XXX - get the failure reason.
219 g_string_append(str, "unknown Windows version");
222 switch (info.dwPlatformId) {
224 case VER_PLATFORM_WIN32s:
226 g_string_sprintfa(str, "Windows 3.1 with Win32s");
229 case VER_PLATFORM_WIN32_WINDOWS:
231 switch (info.dwMajorVersion) {
234 /* 3 cheers for Microsoft marketing! */
235 switch (info.dwMinorVersion) {
238 g_string_sprintfa(str, "Windows 95");
242 g_string_sprintfa(str, "Windows 98");
246 g_string_sprintfa(str, "Windows Me");
250 g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
251 info.dwMajorVersion, info.dwMinorVersion);
257 g_string_sprintfa(str, "Windows OT, unknown version %lu.%lu",
258 info.dwMajorVersion, info.dwMinorVersion);
263 case VER_PLATFORM_WIN32_NT:
265 switch (info.dwMajorVersion) {
269 g_string_sprintfa(str, "Windows NT %lu.%lu",
270 info.dwMajorVersion, info.dwMinorVersion);
274 /* 3 cheers for Microsoft marketing! */
275 switch (info.dwMinorVersion) {
278 g_string_sprintfa(str, "Windows 2000");
282 g_string_sprintfa(str, "Windows XP");
286 g_string_sprintfa(str, "Windows Server 2003");
290 g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
291 info.dwMajorVersion, info.dwMinorVersion);
297 g_string_sprintfa(str, "Windows NT, unknown version %lu.%lu",
298 info.dwMajorVersion, info.dwMinorVersion);
304 g_string_sprintfa(str, "Unknown Windows platform %lu version %lu.%lu",
305 info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
308 if (info.szCSDVersion[0] != '\0')
309 g_string_sprintfa(str, " %s", info.szCSDVersion);
310 g_string_sprintfa(str, ", build %lu", info.dwBuildNumber);
311 #elif defined(HAVE_SYS_UTSNAME_H)
313 * We have <sys/utsname.h>, so we assume we have "uname()".
315 if (uname(&name) < 0) {
316 g_string_sprintfa(str, "unknown OS version (uname failed - %s)",
321 if (strcmp(name.sysname, "AIX") == 0) {
323 * Yay, IBM! Thanks for doing something different
324 * from most of the other UNIXes out there, and
325 * making "name.version" apparently be the major
326 * version number and "name.release" be the minor
329 g_string_sprintfa(str, "%s %s.%s", name.sysname, name.version,
333 * XXX - get "version" on any other platforms?
335 * On Digital/Tru65 UNIX, it's something unknown.
336 * On Solaris, it's some kind of build information.
337 * On HP-UX, it appears to be some sort of subrevision
340 g_string_sprintfa(str, "%s %s", name.sysname, name.release);
343 g_string_append(str, "an unknown OS");
345 g_string_append(str, ".");