packet-applemidi.c:296:33: error: unused variable ‘p_conv_data’
[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 <stdio.h>
33 #include <string.h>
34 #include <errno.h>
35
36 #ifdef HAVE_LIBZ
37 #include <zlib.h>       /* to get the libz version number */
38 #endif
39
40 #ifdef HAVE_SYS_UTSNAME_H
41 #include <sys/utsname.h>
42 #endif
43
44 #include "version_info.h"
45 #include "capture-pcap-util.h"
46 #include <wsutil/unicode-utils.h>
47
48 #include "svnversion.h"
49
50 #ifdef HAVE_WINDOWS_H
51 #include <windows.h>
52 #endif
53
54 #ifdef HAVE_OS_X_FRAMEWORKS
55 #include <CoreServices/CoreServices.h>
56 #endif
57
58 #ifdef HAVE_LIBCAP
59 # include <sys/capability.h>
60 #endif
61
62 #ifdef SVNVERSION
63         const char *wireshark_svnversion = " (" SVNVERSION " from " SVNPATH ")";
64 #else
65         const char *wireshark_svnversion = "";
66 #endif
67
68 /*
69  * If the string doesn't end with a newline, append one.
70  * Then word-wrap it to 80 columns.
71  */
72 static void
73 end_string(GString *str)
74 {
75         size_t point;
76         char *p, *q;
77
78         point = str->len;
79         if (point == 0 || str->str[point - 1] != '\n')
80                 g_string_append(str, "\n");
81         p = str->str;
82         while (*p != '\0') {
83                 q = strchr(p, '\n');
84                 if (q - p > 80) {
85                         /*
86                          * Break at or before this point.
87                          */
88                         q = p + 80;
89                         while (q > p && *q != ' ')
90                                 q--;
91                         if (q != p)
92                                 *q = '\n';
93                 }
94                 p = q + 1;
95         }
96 }
97
98 /*
99  * Get various library compile-time versions and append them to
100  * the specified GString.
101  *
102  * "additional_info" is called at the end to append any additional
103  * information; this is required in order to, for example, put the
104  * Portaudio information at the end of the string, as we currently
105  * don't use Portaudio in TShark.
106  */
107 void
108 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
109                           void (*append_info)(GString *))
110 {
111         if (sizeof(str) == 4)
112                 g_string_append(str, "(32-bit) ");
113         else
114                 g_string_append(str, "(64-bit) ");
115
116         if (prepend_info)
117                 (*prepend_info)(str);
118
119         /* GLIB */
120         g_string_append(str, "with ");
121         g_string_append_printf(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         /* Libpcap */
130         g_string_append(str, ", ");
131         get_compiled_pcap_version(str);
132
133         /* LIBZ */
134         g_string_append(str, ", ");
135 #ifdef HAVE_LIBZ
136         g_string_append(str, "with libz ");
137 #ifdef ZLIB_VERSION
138         g_string_append(str, ZLIB_VERSION);
139 #else /* ZLIB_VERSION */
140         g_string_append(str, "(version unknown)");
141 #endif /* ZLIB_VERSION */
142 #else /* HAVE_LIBZ */
143         g_string_append(str, "without libz");
144 #endif /* HAVE_LIBZ */
145
146         /* LIBCAP */
147         g_string_append(str, ", ");
148 #ifdef HAVE_LIBCAP
149         g_string_append(str, "with POSIX capabilities");
150 #ifdef _LINUX_CAPABILITY_VERSION
151         g_string_append(str, " (Linux)");
152 #endif /* _LINUX_CAPABILITY_VERSION */
153 #else /* HAVE_LIBCAP */
154         g_string_append(str, "without POSIX capabilities");
155 #endif /* HAVE_LIBCAP */
156
157         /* Additional application-dependent information */
158         if (append_info)
159                 (*append_info)(str);
160         g_string_append(str, ".");
161
162         end_string(str);
163 }
164
165 #ifdef _WIN32
166 typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
167 #endif
168
169 /*
170  * Get the OS version, and append it to the GString
171  */
172 void get_os_version_info(GString *str)
173 {
174 #if defined(_WIN32)
175         OSVERSIONINFOEX info;
176         SYSTEM_INFO system_info;
177         nativesi_func_ptr nativesi_func;
178 #elif defined(HAVE_SYS_UTSNAME_H)
179         struct utsname name;
180 #endif
181 #if HAVE_OS_X_FRAMEWORKS
182         SInt32 macosx_ver, macosx_major_ver, macosx_minor_ver, macosx_bugfix_ver;
183 #endif
184
185 #if defined(_WIN32)
186         /*
187          * See
188          *
189          *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
190          *
191          * for more than you ever wanted to know about determining the
192          * flavor of Windows on which you're running.  Implementing more
193          * of that is left as an exercise to the reader - who should
194          * check any copyright information about code samples on MSDN
195          * before cutting and pasting into Wireshark.
196          *
197          * They should also note that you need an OSVERSIONINFOEX structure
198          * to get some of that information, and that not only is that
199          * structure not supported on older versions of Windows, you might
200          * not even be able to compile code that *uses* that structure with
201          * older versions of the SDK.
202          */
203
204         memset(&info, '\0', sizeof info);
205         info.dwOSVersionInfoSize = sizeof info;
206         if (!GetVersionEx((OSVERSIONINFO *)&info)) {
207                 /*
208                  * XXX - get the failure reason.
209                  */
210                 g_string_append(str, "unknown Windows version");
211                 return;
212         }
213
214         memset(&system_info, '\0', sizeof system_info);
215         /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
216          * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
217         nativesi_func = (nativesi_func_ptr)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo");
218         if(nativesi_func)
219                 nativesi_func(&system_info);
220         else
221                 GetSystemInfo(&system_info);
222
223         switch (info.dwPlatformId) {
224
225         case VER_PLATFORM_WIN32s:
226                 /* Shyeah, right. */
227                 g_string_append_printf(str, "Windows 3.1 with Win32s");
228                 break;
229
230         case VER_PLATFORM_WIN32_WINDOWS:
231                 /* Windows OT */
232                 switch (info.dwMajorVersion) {
233
234                 case 4:
235                         /* 3 cheers for Microsoft marketing! */
236                         switch (info.dwMinorVersion) {
237
238                         case 0:
239                                 g_string_append_printf(str, "Windows 95");
240                                 break;
241
242                         case 10:
243                                 g_string_append_printf(str, "Windows 98");
244                                 break;
245
246                         case 90:
247                                 g_string_append_printf(str, "Windows Me");
248                                 break;
249
250                         default:
251                                 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
252                                     info.dwMajorVersion, info.dwMinorVersion);
253                                 break;
254                         }
255                         break;
256
257                 default:
258                         g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
259                             info.dwMajorVersion, info.dwMinorVersion);
260                         break;
261                 }
262                 break;
263
264         case VER_PLATFORM_WIN32_NT:
265                 /* Windows NT */
266                 switch (info.dwMajorVersion) {
267
268                 case 3:
269                 case 4:
270                         g_string_append_printf(str, "Windows NT %lu.%lu",
271                             info.dwMajorVersion, info.dwMinorVersion);
272                         break;
273
274                 case 5:
275                         /* 3 cheers for Microsoft marketing! */
276                         switch (info.dwMinorVersion) {
277
278                         case 0:
279                                 g_string_append_printf(str, "Windows 2000");
280                                 break;
281
282                         case 1:
283                                 g_string_append_printf(str, "Windows XP");
284                                 break;
285
286                         case 2:
287                                 if ((info.wProductType == VER_NT_WORKSTATION) &&
288                                     (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
289                                         g_string_append_printf(str, "Windows XP Professional x64 Edition");
290                                 } else {
291                                         g_string_append_printf(str, "Windows Server 2003");
292                                         if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
293                                                 g_string_append_printf(str, " x64 Edition");
294                                 }
295                                 break;
296
297                         default:
298                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
299                                                        info.dwMajorVersion, info.dwMinorVersion);
300                                 break;
301                         }
302                         break;
303
304                 case 6: {
305                         gboolean is_nt_workstation;
306
307                         if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
308                                 g_string_append(str, "64-bit ");
309                         else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
310                                 g_string_append(str, "32-bit ");
311 #ifndef VER_NT_WORKSTATION
312 #define VER_NT_WORKSTATION 0x01
313                         is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
314 #else
315                         is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
316 #endif
317                         switch (info.dwMinorVersion) {
318                         case 0:
319                                 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
320                                 break;
321                         case 1:
322                                 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
323                                 break;
324                         default:
325                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
326                                                        info.dwMajorVersion, info.dwMinorVersion);
327                                 break;
328                         }
329                         break;
330                 }  /* case 6 */
331                 default:
332                         g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
333                             info.dwMajorVersion, info.dwMinorVersion);
334                         break;
335                 } /* info.dwMajorVersion */
336                 break;
337
338         default:
339                 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
340                     info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
341                 break;
342         }
343         if (info.szCSDVersion[0] != '\0')
344                 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
345         g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
346 #elif defined(HAVE_SYS_UTSNAME_H)
347         /*
348          * We have <sys/utsname.h>, so we assume we have "uname()".
349          */
350         if (uname(&name) < 0) {
351                 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
352                     g_strerror(errno));
353                 return;
354         }
355
356         if (strcmp(name.sysname, "AIX") == 0) {
357                 /*
358                  * Yay, IBM!  Thanks for doing something different
359                  * from most of the other UNIXes out there, and
360                  * making "name.version" apparently be the major
361                  * version number and "name.release" be the minor
362                  * version number.
363                  */
364                 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
365                     name.release);
366         } else {
367                 /*
368                  * XXX - get "version" on any other platforms?
369                  *
370                  * On Digital/Tru64 UNIX, it's something unknown.
371                  * On Solaris, it's some kind of build information.
372                  * On HP-UX, it appears to be some sort of subrevision
373                  * thing.
374                  * On *BSD and Darwin/OS X, it's a long string giving
375                  * a build date, config file name, etc., etc., etc..
376                  */
377 #ifdef HAVE_OS_X_FRAMEWORKS
378                 /*
379                  * On Mac OS X, report the Mac OS X version number as
380                  * the OS, and put the Darwin information in parentheses.
381                  *
382                  * XXX - can we get the build name?  There's no API to
383                  * get it; it's currently in
384                  * /System/Library/CoreServices/SystemVersion.plist
385                  * but there's no guarantee that it will continue to
386                  * be there.
387                  */
388                 Gestalt(gestaltSystemVersion, &macosx_ver);
389
390                 /* The following functions are only available in Mac OS 10.4+ */
391                 if(macosx_ver >= 0x1040) {
392                         Gestalt(gestaltSystemVersionMajor, &macosx_major_ver);
393                         Gestalt(gestaltSystemVersionMinor, &macosx_minor_ver);
394                         Gestalt(gestaltSystemVersionBugFix, &macosx_bugfix_ver);
395
396                         g_string_append_printf(str, "Mac OS %ld.%ld.%ld",
397                                           (long)macosx_major_ver,
398                                           (long)macosx_minor_ver,
399                                           (long)macosx_bugfix_ver);
400                 } else {
401                         g_string_append_printf(str, "Mac OS X < 10.4 [%lx]",
402                                           (long)macosx_ver);
403                         /* See Apple's Gestalt Manager Reference for meanings
404                          * of the macosx_ver values. */
405                 }
406                 g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
407 #else /* HAVE_OS_X_FRAMEWORKS */
408                 /*
409                  * XXX - on Linux, are there any APIs to get the distribution
410                  * name and version number?  I think some distributions have
411                  * that.
412                  *
413                  * At least on Linux Standard Base-compliant distributions,
414                  * there's an "lsb_release" command.  However:
415                  *
416                  *      http://forums.fedoraforum.org/showthread.php?t=220885
417                  *
418                  * seems to suggest that if you don't have the redhat-lsb
419                  * package installed, you don't have lsb_release, and that
420                  * /etc/fedora-release has the release information on
421                  * Fedora.
422                  *
423                  *      http://linux.die.net/man/1/lsb_release
424                  *
425                  * suggests that there's an /etc/distrib-release file, but
426                  * it doesn't indicate whether "distrib" is literally
427                  * "distrib" or is the name for the distribution, and
428                  * also speaks of an /etc/debian_version file.
429                  *
430                  * "lsb_release" apparently parses /etc/lsb-release, which
431                  * has shell-style assignments, assigning to, among other
432                  * values, DISTRIB_ID (distributor/distribution name),
433                  * DISTRIB_RELEASE (release number of the distribution),
434                  * DISTRIB_DESCRIPTION (*might* be name followed by version,
435                  * but the manpage for lsb_release seems to indicate that's
436                  * not guaranteed), and DISTRIB_CODENAME (code name, e.g.
437                  * "licentious" for the Ubuntu Licentious Lemur release).
438                  * the lsb_release man page also speaks of the distrib-release
439                  * file, but Debian doesn't have one, and Ubuntu 7's
440                  * lsb_release command doesn't look for one.
441                  *
442                  * I've seen references to /etc/redhat-release as well.
443                  *
444                  * At least on my Ubuntu 7 system, /etc/debian_version
445                  * doesn't contain anything interesting (just some Debian
446                  * codenames).
447                  *
448                  * See also
449                  *
450                  *      http://bugs.python.org/issue1322
451                  *
452                  *      http://www.novell.com/coolsolutions/feature/11251.html
453                  *
454                  *      http://linuxmafia.com/faq/Admin/release-files.html
455                  *
456                  * and the Lib/Platform.py file in recent Python 2.x
457                  * releases.
458                  */
459                 g_string_append_printf(str, "%s %s", name.sysname, name.release);
460 #endif /* HAVE_OS_X_FRAMEWORKS */
461         }
462 #else
463         g_string_append(str, "an unknown OS");
464 #endif
465 }
466
467
468 /*
469  * Get various library run-time versions, and the OS version, and append
470  * them to the specified GString.
471  */
472 void
473 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
474 {
475 #ifndef _WIN32
476         gchar *lang;
477 #endif
478
479         g_string_append(str, "on ");
480
481         get_os_version_info(str);
482
483 #ifndef _WIN32
484         /* Locale */
485         if ((lang = getenv ("LANG")) != NULL)
486                 g_string_append_printf(str, ", with locale %s", lang);
487         else
488                 g_string_append(str, ", without locale");
489 #endif
490
491         /* Libpcap */
492         g_string_append(str, ", ");
493         get_runtime_pcap_version(str);
494
495         /* zlib */
496 #if defined(HAVE_LIBZ) && !defined(_WIN32)
497         g_string_append_printf(str, ", with libz %s", zlibVersion());
498 #endif
499
500         /* Additional application-dependent information */
501         if (additional_info)
502                 (*additional_info)(str);
503
504         g_string_append(str, ".");
505
506         /* Compiler info */
507
508         /*
509          * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
510          * information on various defined strings.
511          *
512          * GCC's __VERSION__ is a nice text string for humans to
513          * read.  The page at sourceforge.net largely describes
514          * numeric #defines that encode the version; if the compiler
515          * doesn't also offer a nice printable string, we try prettifying
516          * the number somehow.
517          */
518 #if defined(__GNUC__) && defined(__VERSION__)
519         /*
520          * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
521          * distinguish between them.
522          */
523 #if defined(__clang__)
524         g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
525 #elif defined(__llvm__)
526         g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
527 #else /* boring old GCC */
528         g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
529 #endif /* llvm */
530 #elif defined(__HP_aCC)
531         g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
532 #elif defined(__xlC__)
533         g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
534             (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
535 #ifdef __IBMC__
536         if ((__IBMC__ % 10) != 0)
537                 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
538 #endif /* __IBMC__ */
539         g_string_append_printf(str, "\n");
540 #elif defined(__INTEL_COMPILER)
541         g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
542             __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
543         if ((__INTEL_COMPILER % 10) != 0)
544                 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
545 #ifdef __INTEL_COMPILER_BUILD_DATE
546         g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
547             __INTEL_COMPILER_BUILD_DATE / 10000,
548             (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
549             __INTEL_COMPILER_BUILD_DATE % 100);
550 #endif /* __INTEL_COMPILER_BUILD_DATE */
551         g_string_append_printf(str, "\n");
552 #elif defined(_MSC_FULL_VER)
553 # if _MSC_FULL_VER > 99999999
554         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
555                                (_MSC_FULL_VER / 10000000) - 6,
556                                (_MSC_FULL_VER / 100000) % 100);
557 #  if (_MSC_FULL_VER % 100000) != 0
558         g_string_append_printf(str, " build %d",
559                                _MSC_FULL_VER % 100000);
560 #  endif
561 # else
562         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
563                                (_MSC_FULL_VER / 1000000) - 6,
564                                (_MSC_FULL_VER / 10000) % 100);
565 #  if (_MSC_FULL_VER % 10000) != 0
566         g_string_append_printf(str, " build %d",
567                                _MSC_FULL_VER % 10000);
568 #  endif
569 # endif
570         g_string_append_printf(str, "\n");
571 #elif defined(_MSC_VER)
572         /* _MSC_FULL_VER not defined, but _MSC_VER defined */
573         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
574             (_MSC_VER / 100) - 6, _MSC_VER % 100);
575 #elif defined(__SUNPRO_C)
576         g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
577             (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
578         if ((__SUNPRO_C & 0xF) != 0)
579                 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
580         g_string_append_printf(str, "\n");
581 #endif
582
583         end_string(str);
584 }
585
586 /*
587  * Get copyright information.
588  */
589 const char *
590 get_copyright_info(void)
591 {
592         return
593 "Copyright 1998-2012 Gerald Combs <gerald@wireshark.org> and contributors.\n"
594 "This is free software; see the source for copying conditions. There is NO\n"
595 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
596 }
597
598 #if defined(_WIN32)
599 /*
600  * Get the major OS version.
601  */
602 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
603 guint32
604 get_os_major_version()
605 {
606         OSVERSIONINFO info;
607         info.dwOSVersionInfoSize = sizeof info;
608         if (GetVersionEx(&info)) {
609                 return info.dwMajorVersion;
610         }
611         return 0;
612 }
613 #endif
614
615 /*
616  * Editor modelines
617  *
618  * Local Variables:
619  * c-basic-offset: 8
620  * tab-width: 8
621  * indent-tabs-mode: t
622  * End:
623  *
624  * ex: set shiftwidth=8 tabstop=8 noexpandtab:
625  * :indentSize=8:tabSize=8:noTabs=false:
626  */