Add a routine to return a version string including VCS information.
[metze/wireshark/wip.git] / version_info.c
1 /* version_info.c
2  * Routines to report version information for stuff used by Wireshark
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <glib.h>
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #ifdef HAVE_LIBZ
31 #include <zlib.h>       /* to get the libz version number */
32 #endif
33
34 #include "version_info.h"
35 #include "capture-pcap-util.h"
36 #include <wsutil/os_version_info.h>
37 #include <wsutil/compiler_info.h>
38 #include <wsutil/cpu_info.h>
39 #include <wsutil/mem_info.h>
40
41 #ifdef HAVE_LIBCAP
42 # include <sys/capability.h>
43 #endif
44
45 /*
46  * If the string doesn't end with a newline, append one.
47  * Then word-wrap it to 80 columns.
48  */
49 static void
50 end_string(GString *str)
51 {
52         size_t point;
53         char *p, *q;
54
55         point = str->len;
56         if (point == 0 || str->str[point - 1] != '\n')
57                 g_string_append(str, "\n");
58         p = str->str;
59         while (*p != '\0') {
60                 q = strchr(p, '\n');
61                 if (q - p > 80) {
62                         /*
63                          * Break at or before this point.
64                          */
65                         q = p + 80;
66                         while (q > p && *q != ' ')
67                                 q--;
68                         if (q != p)
69                                 *q = '\n';
70                 }
71                 p = q + 1;
72         }
73 }
74
75 /*
76  * Get various library compile-time versions and append them to
77  * the specified GString.
78  *
79  * "additional_info" is called at the end to append any additional
80  * information; this is required in order to, for example, put the
81  * Portaudio information at the end of the string, as we currently
82  * don't use Portaudio in TShark.
83  */
84 void
85 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
86                           void (*append_info)(GString *))
87 {
88         if (sizeof(str) == 4)
89                 g_string_append(str, "(32-bit) ");
90         else
91                 g_string_append(str, "(64-bit) ");
92
93         if (prepend_info)
94                 (*prepend_info)(str);
95
96         /* GLIB */
97         g_string_append(str, "with ");
98         g_string_append_printf(str,
99 #ifdef GLIB_MAJOR_VERSION
100             "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
101             GLIB_MICRO_VERSION);
102 #else
103             "GLib (version unknown)");
104 #endif
105
106         /* Libpcap */
107         g_string_append(str, ", ");
108         get_compiled_pcap_version(str);
109
110         /* LIBZ */
111         g_string_append(str, ", ");
112 #ifdef HAVE_LIBZ
113         g_string_append(str, "with libz ");
114 #ifdef ZLIB_VERSION
115         g_string_append(str, ZLIB_VERSION);
116 #else /* ZLIB_VERSION */
117         g_string_append(str, "(version unknown)");
118 #endif /* ZLIB_VERSION */
119 #else /* HAVE_LIBZ */
120         g_string_append(str, "without libz");
121 #endif /* HAVE_LIBZ */
122
123 #ifndef _WIN32
124         /* This is UN*X-only. */
125         /* LIBCAP */
126         g_string_append(str, ", ");
127 #ifdef HAVE_LIBCAP
128         g_string_append(str, "with POSIX capabilities");
129 #ifdef _LINUX_CAPABILITY_VERSION
130         g_string_append(str, " (Linux)");
131 #endif /* _LINUX_CAPABILITY_VERSION */
132 #else /* HAVE_LIBCAP */
133         g_string_append(str, "without POSIX capabilities");
134 #endif /* HAVE_LIBCAP */
135 #endif /* _WIN32 */
136
137 #ifdef __linux__
138         /* This is a Linux-specific library. */
139         /* LIBNL */
140         g_string_append(str, ", ");
141 #if defined(HAVE_LIBNL1)
142         g_string_append(str, "with libnl 1");
143 #elif defined(HAVE_LIBNL2)
144         g_string_append(str, "with libnl 2");
145 #elif defined(HAVE_LIBNL3)
146         g_string_append(str, "with libnl 3");
147 #else /* no libnl */
148         g_string_append(str, "without libnl");
149 #endif /* libnl version */
150 #endif /* __linux__ */
151
152         /* Additional application-dependent information */
153         if (append_info)
154                 (*append_info)(str);
155         g_string_append(str, ".");
156
157         end_string(str);
158 }
159
160 /*
161  * Get various library run-time versions, and the OS version, and append
162  * them to the specified GString.
163  */
164 void
165 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
166 {
167 #ifndef _WIN32
168         gchar *lang;
169 #endif
170
171         g_string_append(str, "on ");
172
173         get_os_version_info(str);
174
175 #ifndef _WIN32
176         /* Locale */
177         if ((lang = getenv ("LANG")) != NULL)
178                 g_string_append_printf(str, ", with locale %s", lang);
179         else
180                 g_string_append(str, ", without locale");
181 #endif
182
183         /* Libpcap */
184         g_string_append(str, ", ");
185         get_runtime_pcap_version(str);
186
187         /* zlib */
188 #if defined(HAVE_LIBZ) && !defined(_WIN32)
189         g_string_append_printf(str, ", with libz %s", zlibVersion());
190 #endif
191
192         /* Additional application-dependent information */
193         if (additional_info)
194                 (*additional_info)(str);
195
196         g_string_append(str, ".");
197
198         /* CPU Info */
199         get_cpu_info(str);
200
201         /* Get info about installed memory Windows only */
202         get_mem_info(str);
203
204         /* Compiler info */
205         get_compiler_info(str);
206
207         end_string(str);
208 }
209
210 /*
211  * Editor modelines
212  *
213  * Local Variables:
214  * c-basic-offset: 8
215  * tab-width: 8
216  * indent-tabs-mode: t
217  * End:
218  *
219  * ex: set shiftwidth=8 tabstop=8 noexpandtab:
220  * :indentSize=8:tabSize=8:noTabs=false:
221  */