Attempt to fix Qt dependencies for SUSE.
[metze/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <glib.h>
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <errno.h>
33
34 #ifdef HAVE_LIBZ
35 #include <zlib.h>       /* to get the libz version number */
36 #endif
37
38 #ifdef HAVE_SYS_UTSNAME_H
39 #include <sys/utsname.h>
40 #endif
41
42 #include "version_info.h"
43 #include "capture-pcap-util.h"
44 #include <wsutil/unicode-utils.h>
45
46 #include "svnversion.h"
47
48 #ifdef HAVE_WINDOWS_H
49 #include <windows.h>
50 #endif
51
52 #ifdef HAVE_OS_X_FRAMEWORKS
53 #include <CoreFoundation/CoreFoundation.h>
54 #include "cfutils.h"
55 #endif
56
57 #ifdef HAVE_LIBCAP
58 # include <sys/capability.h>
59 #endif
60
61 #ifdef SVNVERSION
62         const char *wireshark_svnversion = " (" SVNVERSION " from " SVNPATH ")";
63 #else
64         const char *wireshark_svnversion = "";
65 #endif
66
67 /*
68  * If the string doesn't end with a newline, append one.
69  * Then word-wrap it to 80 columns.
70  */
71 static void
72 end_string(GString *str)
73 {
74         size_t point;
75         char *p, *q;
76
77         point = str->len;
78         if (point == 0 || str->str[point - 1] != '\n')
79                 g_string_append(str, "\n");
80         p = str->str;
81         while (*p != '\0') {
82                 q = strchr(p, '\n');
83                 if (q - p > 80) {
84                         /*
85                          * Break at or before this point.
86                          */
87                         q = p + 80;
88                         while (q > p && *q != ' ')
89                                 q--;
90                         if (q != p)
91                                 *q = '\n';
92                 }
93                 p = q + 1;
94         }
95 }
96
97 /*
98  * Get various library compile-time versions and append them to
99  * the specified GString.
100  *
101  * "additional_info" is called at the end to append any additional
102  * information; this is required in order to, for example, put the
103  * Portaudio information at the end of the string, as we currently
104  * don't use Portaudio in TShark.
105  */
106 void
107 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
108                           void (*append_info)(GString *))
109 {
110         if (sizeof(str) == 4)
111                 g_string_append(str, "(32-bit) ");
112         else
113                 g_string_append(str, "(64-bit) ");
114
115         if (prepend_info)
116                 (*prepend_info)(str);
117
118         /* GLIB */
119         g_string_append(str, "with ");
120         g_string_append_printf(str,
121 #ifdef GLIB_MAJOR_VERSION
122             "GLib %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
123             GLIB_MICRO_VERSION);
124 #else
125             "GLib (version unknown)");
126 #endif
127
128         /* Libpcap */
129         g_string_append(str, ", ");
130         get_compiled_pcap_version(str);
131
132         /* LIBZ */
133         g_string_append(str, ", ");
134 #ifdef HAVE_LIBZ
135         g_string_append(str, "with libz ");
136 #ifdef ZLIB_VERSION
137         g_string_append(str, ZLIB_VERSION);
138 #else /* ZLIB_VERSION */
139         g_string_append(str, "(version unknown)");
140 #endif /* ZLIB_VERSION */
141 #else /* HAVE_LIBZ */
142         g_string_append(str, "without libz");
143 #endif /* HAVE_LIBZ */
144
145 #ifndef _WIN32
146         /* This is UN*X-only. */
147         /* LIBCAP */
148         g_string_append(str, ", ");
149 #ifdef HAVE_LIBCAP
150         g_string_append(str, "with POSIX capabilities");
151 #ifdef _LINUX_CAPABILITY_VERSION
152         g_string_append(str, " (Linux)");
153 #endif /* _LINUX_CAPABILITY_VERSION */
154 #else /* HAVE_LIBCAP */
155         g_string_append(str, "without POSIX capabilities");
156 #endif /* HAVE_LIBCAP */
157 #endif /* _WIN32 */
158
159 #ifdef __linux__
160         /* This is a Linux-specific library. */
161         /* LIBNL */
162         g_string_append(str, ", ");
163 #if defined(HAVE_LIBNL1)
164         g_string_append(str, "with libnl 1");
165 #elif defined(HAVE_LIBNL2)
166         g_string_append(str, "with libnl 2");
167 #elif defined(HAVE_LIBNL3)
168         g_string_append(str, "with libnl 3");
169 #else /* no libnl */
170         g_string_append(str, "without libnl");
171 #endif /* libnl version */
172 #endif /* __linux__ */
173
174         /* Additional application-dependent information */
175         if (append_info)
176                 (*append_info)(str);
177         g_string_append(str, ".");
178
179         end_string(str);
180 }
181
182 #ifdef _WIN32
183 typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
184 #endif
185
186 /*
187  * Handles the rather elaborate process of getting OS version information
188  * from OS X (we want the OS X version, not the Darwin version, the latter
189  * being easy to get with uname()).
190  */
191 #ifdef HAVE_OS_X_FRAMEWORKS
192
193 /*
194  * Fetch a string, as a UTF-8 C string, from a dictionary, given a key.
195  */
196 static char *
197 get_string_from_dictionary(CFPropertyListRef dict, CFStringRef key)
198 {
199         CFStringRef cfstring;
200
201         cfstring = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)dict,
202             (const void *)key);
203         if (cfstring == NULL)
204                 return NULL;
205         if (CFGetTypeID(cfstring) != CFStringGetTypeID()) {
206                 /* It isn't a string.  Punt. */
207                 return NULL;
208         }
209         return CFString_to_C_string(cfstring);
210 }
211
212 /*
213  * Get the OS X version information, and append it to the GString.
214  * Return TRUE if we succeed, FALSE if we fail.
215  */
216 static gboolean
217 get_os_x_version_info(GString *str)
218 {
219         static const UInt8 server_version_plist_path[] =
220             "/System/Library/CoreServices/ServerVersion.plist";
221         static const UInt8 system_version_plist_path[] =
222             "/System/Library/CoreServices/SystemVersion.plist";
223         CFURLRef version_plist_file_url;
224         CFReadStreamRef version_plist_stream;
225         CFDictionaryRef version_dict;
226         char *string;
227
228         /*
229          * On OS X, report the OS X version number as the OS, and put
230          * the Darwin information in parentheses.
231          *
232          * Alas, Gestalt() is deprecated in Mountain Lion, so the build
233          * fails if you treat deprecation warnings as fatal.  I don't
234          * know of any replacement API, so we fall back on reading
235          * /System/Library/CoreServices/ServerVersion.plist if it
236          * exists, otherwise /System/Library/CoreServices/SystemVersion.plist,
237          * and using ProductUserVisibleVersion.  We also get the build
238          * version from ProductBuildVersion and the product name from
239          * ProductName.
240          */
241         version_plist_file_url = CFURLCreateFromFileSystemRepresentation(NULL,
242             server_version_plist_path, sizeof server_version_plist_path - 1,
243             false);
244         if (version_plist_file_url == NULL)
245                 return FALSE;
246         version_plist_stream = CFReadStreamCreateWithFile(NULL,
247             version_plist_file_url);
248         CFRelease(version_plist_file_url);
249         if (version_plist_stream == NULL)
250                 return FALSE;
251         if (!CFReadStreamOpen(version_plist_stream)) {
252                 CFRelease(version_plist_stream);
253
254                 /*
255                  * Try SystemVersion.plist.
256                  */
257                 version_plist_file_url = CFURLCreateFromFileSystemRepresentation(NULL,
258                     system_version_plist_path, sizeof system_version_plist_path - 1,
259                     false);
260                 if (version_plist_file_url == NULL)
261                         return FALSE;
262                 version_plist_stream = CFReadStreamCreateWithFile(NULL,
263                     version_plist_file_url);
264                 CFRelease(version_plist_file_url);
265                 if (version_plist_stream == NULL)
266                         return FALSE;
267                 if (!CFReadStreamOpen(version_plist_stream)) {
268                         CFRelease(version_plist_stream);
269                         return FALSE;
270                 }
271         }
272 #ifdef HAVE_CFPROPERTYLISTCREATEWITHSTREAM
273         version_dict = (CFDictionaryRef)CFPropertyListCreateWithStream(NULL,
274             version_plist_stream, 0, kCFPropertyListImmutable,
275             NULL, NULL);
276 #else
277         version_dict = (CFDictionaryRef)CFPropertyListCreateFromStream(NULL,
278             version_plist_stream, 0, kCFPropertyListImmutable,
279             NULL, NULL);
280 #endif
281         if (version_dict == NULL) {
282                 CFRelease(version_plist_stream);
283                 return FALSE;
284         }
285         if (CFGetTypeID(version_dict) != CFDictionaryGetTypeID()) {
286                 /* This is *supposed* to be a dictionary.  Punt. */
287                 CFRelease(version_dict);
288                 CFReadStreamClose(version_plist_stream);
289                 CFRelease(version_plist_stream);
290                 return FALSE;
291         }
292         /* Get the product name string. */
293         string = get_string_from_dictionary(version_dict,
294             CFSTR("ProductName"));
295         if (string == NULL) {
296                 CFRelease(version_dict);
297                 CFReadStreamClose(version_plist_stream);
298                 CFRelease(version_plist_stream);
299                 return FALSE;
300         }
301         g_string_append_printf(str, "%s", string);
302         g_free(string);
303
304         /* Get the OS version string. */
305         string = get_string_from_dictionary(version_dict,
306             CFSTR("ProductUserVisibleVersion"));
307         if (string == NULL) {
308                 CFRelease(version_dict);
309                 CFReadStreamClose(version_plist_stream);
310                 CFRelease(version_plist_stream);
311                 return FALSE;
312         }
313         g_string_append_printf(str, " %s", string);
314         g_free(string);
315
316         /* Get the build string */
317         string = get_string_from_dictionary(version_dict,
318             CFSTR("ProductBuildVersion"));
319         if (string == NULL) {
320                 CFRelease(version_dict);
321                 CFReadStreamClose(version_plist_stream);
322                 CFRelease(version_plist_stream);
323                 return FALSE;
324         }
325         g_string_append_printf(str, ", build %s", string);
326         g_free(string);
327         CFRelease(version_dict);
328         CFReadStreamClose(version_plist_stream);
329         CFRelease(version_plist_stream);
330         return TRUE;
331 }
332 #endif
333
334 /*
335  * Get the OS version, and append it to the GString
336  */
337 void get_os_version_info(GString *str)
338 {
339 #if defined(_WIN32)
340         OSVERSIONINFOEX info;
341         SYSTEM_INFO system_info;
342         nativesi_func_ptr nativesi_func;
343 #elif defined(HAVE_SYS_UTSNAME_H)
344         struct utsname name;
345 #endif
346
347 #if defined(_WIN32)
348         /*
349          * See
350          *
351          *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_the_system_version.asp
352          *
353          * for more than you ever wanted to know about determining the
354          * flavor of Windows on which you're running.  Implementing more
355          * of that is left as an exercise to the reader - who should
356          * check any copyright information about code samples on MSDN
357          * before cutting and pasting into Wireshark.
358          *
359          * They should also note that you need an OSVERSIONINFOEX structure
360          * to get some of that information, and that not only is that
361          * structure not supported on older versions of Windows, you might
362          * not even be able to compile code that *uses* that structure with
363          * older versions of the SDK.
364          */
365
366         memset(&info, '\0', sizeof info);
367         info.dwOSVersionInfoSize = sizeof info;
368         if (!GetVersionEx((OSVERSIONINFO *)&info)) {
369                 /*
370                  * XXX - get the failure reason.
371                  */
372                 g_string_append(str, "unknown Windows version");
373                 return;
374         }
375
376         memset(&system_info, '\0', sizeof system_info);
377         /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
378          * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
379         nativesi_func = (nativesi_func_ptr)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo");
380         if(nativesi_func)
381                 nativesi_func(&system_info);
382         else
383                 GetSystemInfo(&system_info);
384
385         switch (info.dwPlatformId) {
386
387         case VER_PLATFORM_WIN32s:
388                 /* Shyeah, right. */
389                 g_string_append_printf(str, "Windows 3.1 with Win32s");
390                 break;
391
392         case VER_PLATFORM_WIN32_WINDOWS:
393                 /* Windows OT */
394                 switch (info.dwMajorVersion) {
395
396                 case 4:
397                         /* 3 cheers for Microsoft marketing! */
398                         switch (info.dwMinorVersion) {
399
400                         case 0:
401                                 g_string_append_printf(str, "Windows 95");
402                                 break;
403
404                         case 10:
405                                 g_string_append_printf(str, "Windows 98");
406                                 break;
407
408                         case 90:
409                                 g_string_append_printf(str, "Windows Me");
410                                 break;
411
412                         default:
413                                 g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
414                                     info.dwMajorVersion, info.dwMinorVersion);
415                                 break;
416                         }
417                         break;
418
419                 default:
420                         g_string_append_printf(str, "Windows OT, unknown version %lu.%lu",
421                             info.dwMajorVersion, info.dwMinorVersion);
422                         break;
423                 }
424                 break;
425
426         case VER_PLATFORM_WIN32_NT:
427                 /* Windows NT */
428                 switch (info.dwMajorVersion) {
429
430                 case 3:
431                 case 4:
432                         g_string_append_printf(str, "Windows NT %lu.%lu",
433                             info.dwMajorVersion, info.dwMinorVersion);
434                         break;
435
436                 case 5:
437                         /* 3 cheers for Microsoft marketing! */
438                         switch (info.dwMinorVersion) {
439
440                         case 0:
441                                 g_string_append_printf(str, "Windows 2000");
442                                 break;
443
444                         case 1:
445                                 g_string_append_printf(str, "Windows XP");
446                                 break;
447
448                         case 2:
449                                 if ((info.wProductType == VER_NT_WORKSTATION) &&
450                                     (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {
451                                         g_string_append_printf(str, "Windows XP Professional x64 Edition");
452                                 } else {
453                                         g_string_append_printf(str, "Windows Server 2003");
454                                         if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
455                                                 g_string_append_printf(str, " x64 Edition");
456                                 }
457                                 break;
458
459                         default:
460                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
461                                                        info.dwMajorVersion, info.dwMinorVersion);
462                                 break;
463                         }
464                         break;
465
466                 case 6: {
467                         gboolean is_nt_workstation;
468
469                         if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
470                                 g_string_append(str, "64-bit ");
471                         else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
472                                 g_string_append(str, "32-bit ");
473 #ifndef VER_NT_WORKSTATION
474 #define VER_NT_WORKSTATION 0x01
475                         is_nt_workstation = ((info.wReserved[1] & 0xff) == VER_NT_WORKSTATION);
476 #else
477                         is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
478 #endif
479                         switch (info.dwMinorVersion) {
480                         case 0:
481                                 g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008");
482                                 break;
483                         case 1:
484                                 g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2");
485                                 break;
486                         case 2:
487                                 g_string_append_printf(str, is_nt_workstation ? "Windows 8" : "Windows Server 2012");
488                                 break;
489                         case 3:
490                                 g_string_append_printf(str, is_nt_workstation ? "Windows 8.1" : "Windows Server 2012 R2");
491                                 break;
492                         default:
493                                 g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
494                                                        info.dwMajorVersion, info.dwMinorVersion);
495                                 break;
496                         }
497                         break;
498                 }  /* case 6 */
499                 default:
500                         g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
501                             info.dwMajorVersion, info.dwMinorVersion);
502                         break;
503                 } /* info.dwMajorVersion */
504                 break;
505
506         default:
507                 g_string_append_printf(str, "Unknown Windows platform %lu version %lu.%lu",
508                     info.dwPlatformId, info.dwMajorVersion, info.dwMinorVersion);
509                 break;
510         }
511         if (info.szCSDVersion[0] != '\0')
512                 g_string_append_printf(str, " %s", utf_16to8(info.szCSDVersion));
513         g_string_append_printf(str, ", build %lu", info.dwBuildNumber);
514 #elif defined(HAVE_SYS_UTSNAME_H)
515         /*
516          * We have <sys/utsname.h>, so we assume we have "uname()".
517          */
518         if (uname(&name) < 0) {
519                 g_string_append_printf(str, "unknown OS version (uname failed - %s)",
520                     g_strerror(errno));
521                 return;
522         }
523
524         if (strcmp(name.sysname, "AIX") == 0) {
525                 /*
526                  * Yay, IBM!  Thanks for doing something different
527                  * from most of the other UNIXes out there, and
528                  * making "name.version" apparently be the major
529                  * version number and "name.release" be the minor
530                  * version number.
531                  */
532                 g_string_append_printf(str, "%s %s.%s", name.sysname, name.version,
533                     name.release);
534         } else {
535                 /*
536                  * XXX - get "version" on any other platforms?
537                  *
538                  * On Digital/Tru64 UNIX, it's something unknown.
539                  * On Solaris, it's some kind of build information.
540                  * On HP-UX, it appears to be some sort of subrevision
541                  * thing.
542                  * On *BSD and Darwin/OS X, it's a long string giving
543                  * a build date, config file name, etc., etc., etc..
544                  */
545 #ifdef HAVE_OS_X_FRAMEWORKS
546                 /*
547                  * On Mac OS X, report the Mac OS X version number as
548                  * the OS version if we can, and put the Darwin information
549                  * in parentheses.
550                  */
551                 if (get_os_x_version_info(str)) {
552                         /* Success - append the Darwin information. */
553                         g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
554                 } else {
555                         /* Failure - just use the Darwin information. */
556                         g_string_append_printf(str, "%s %s", name.sysname, name.release);
557                 }
558 #else /* HAVE_OS_X_FRAMEWORKS */
559                 /*
560                  * XXX - on Linux, are there any APIs to get the distribution
561                  * name and version number?  I think some distributions have
562                  * that.
563                  *
564                  * At least on Linux Standard Base-compliant distributions,
565                  * there's an "lsb_release" command.  However:
566                  *
567                  *      http://forums.fedoraforum.org/showthread.php?t=220885
568                  *
569                  * seems to suggest that if you don't have the redhat-lsb
570                  * package installed, you don't have lsb_release, and that
571                  * /etc/fedora-release has the release information on
572                  * Fedora.
573                  *
574                  *      http://linux.die.net/man/1/lsb_release
575                  *
576                  * suggests that there's an /etc/distrib-release file, but
577                  * it doesn't indicate whether "distrib" is literally
578                  * "distrib" or is the name for the distribution, and
579                  * also speaks of an /etc/debian_version file.
580                  *
581                  * "lsb_release" apparently parses /etc/lsb-release, which
582                  * has shell-style assignments, assigning to, among other
583                  * values, DISTRIB_ID (distributor/distribution name),
584                  * DISTRIB_RELEASE (release number of the distribution),
585                  * DISTRIB_DESCRIPTION (*might* be name followed by version,
586                  * but the manpage for lsb_release seems to indicate that's
587                  * not guaranteed), and DISTRIB_CODENAME (code name, e.g.
588                  * "licentious" for the Ubuntu Licentious Lemur release).
589                  * the lsb_release man page also speaks of the distrib-release
590                  * file, but Debian doesn't have one, and Ubuntu 7's
591                  * lsb_release command doesn't look for one.
592                  *
593                  * I've seen references to /etc/redhat-release as well.
594                  *
595                  * At least on my Ubuntu 7 system, /etc/debian_version
596                  * doesn't contain anything interesting (just some Debian
597                  * codenames).
598                  *
599                  * See also
600                  *
601                  *      http://bugs.python.org/issue1322
602                  *
603                  *      http://www.novell.com/coolsolutions/feature/11251.html
604                  *
605                  *      http://linuxmafia.com/faq/Admin/release-files.html
606                  *
607                  * and the Lib/Platform.py file in recent Python 2.x
608                  * releases.
609                  */
610                 g_string_append_printf(str, "%s %s", name.sysname, name.release);
611 #endif /* HAVE_OS_X_FRAMEWORKS */
612         }
613 #else
614         g_string_append(str, "an unknown OS");
615 #endif
616 }
617
618
619 /*
620  * Get the CPU info, and append it to the GString
621  */
622
623 #if defined(_MSC_VER)
624 static void
625 do_cpuid(int *CPUInfo, guint32 selector){
626         __cpuid(CPUInfo, selector);
627 }
628 #elif defined(__GNUC__)
629 #if defined(__x86_64__)  
630 static inline void
631 do_cpuid(guint32 *CPUInfo, int selector)
632 {
633         __asm__ __volatile__("cpuid"
634                                                 : "=a" (CPUInfo[0]),
635                                                         "=b" (CPUInfo[1]),
636                                                         "=c" (CPUInfo[2]),
637                                                         "=d" (CPUInfo[3])
638                                                 : "a"(selector));
639 }
640 #else /* (__i386__) */
641 /* would need a test if older proccesors have the cpuid instruction */
642 static void
643 do_cpuid(guint32 *CPUInfo, int selector _U_){
644         CPUInfo[0] = 0;
645 }
646
647 #endif /* defined(__x86_64__)*/
648 #else /* Other compilers */
649 static void
650 do_cpuid(guint32 *CPUInfo, int selector _U_){
651         CPUInfo[0] = 0;
652 }
653 #endif
654
655 /*
656  * Get CPU info on platforms where the cpuid instruction can be used skip 32 bit versions for GCC
657  *      http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/processor-identification-cpuid-instruction-note.pdf
658  * the get_cpuid() routine will return 0 in CPUInfo[0] if cpuinfo isn't available.
659  */
660
661 static void get_cpu_info(GString *str _U_)
662 {
663 #if defined(_MSC_VER)
664         int CPUInfo[4];
665 #else
666         guint32 CPUInfo[4];
667 #endif
668         char CPUBrandString[0x40];
669         unsigned nExIds;
670
671         /* http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx */
672
673         /* Calling __cpuid with 0x80000000 as the InfoType argument*/
674         /* gets the number of valid extended IDs.*/
675         do_cpuid(CPUInfo, 0x80000000);
676         nExIds = CPUInfo[0];
677
678         if( nExIds<0x80000005)
679                 return;
680         memset(CPUBrandString, 0, sizeof(CPUBrandString));
681
682         /* Interpret CPU brand string.*/
683         do_cpuid(CPUInfo, 0x80000002);
684         memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
685         do_cpuid(CPUInfo, 0x80000003);
686         memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
687         do_cpuid(CPUInfo, 0x80000004);
688         memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
689
690         g_string_append_printf(str, "\n%s", CPUBrandString);
691
692 }
693
694 static void get_mem_info(GString *str _U_)
695 {
696 #if defined(_WIN32)
697         MEMORYSTATUSEX statex;
698
699         statex.dwLength = sizeof (statex);
700         
701         if(GlobalMemoryStatusEx (&statex))
702                 g_string_append_printf(str, ", with ""%" G_GINT64_MODIFIER "d" "MB of physical memory.\n", statex.ullTotalPhys/(1024*1024));
703 #endif
704
705 }
706
707 /*
708  * Get various library run-time versions, and the OS version, and append
709  * them to the specified GString.
710  */
711 void
712 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
713 {
714 #ifndef _WIN32
715         gchar *lang;
716 #endif
717
718         g_string_append(str, "on ");
719
720         get_os_version_info(str);
721
722 #ifndef _WIN32
723         /* Locale */
724         if ((lang = getenv ("LANG")) != NULL)
725                 g_string_append_printf(str, ", with locale %s", lang);
726         else
727                 g_string_append(str, ", without locale");
728 #endif
729
730         /* Libpcap */
731         g_string_append(str, ", ");
732         get_runtime_pcap_version(str);
733
734         /* zlib */
735 #if defined(HAVE_LIBZ) && !defined(_WIN32)
736         g_string_append_printf(str, ", with libz %s", zlibVersion());
737 #endif
738
739         /* Additional application-dependent information */
740         if (additional_info)
741                 (*additional_info)(str);
742
743         g_string_append(str, ".");
744
745         /* CPU Info */
746         get_cpu_info(str);
747
748         /* Get info about installed memory Windows only */
749         get_mem_info(str);
750
751         /* Compiler info */
752
753         /*
754          * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
755          * information on various defined strings.
756          *
757          * GCC's __VERSION__ is a nice text string for humans to
758          * read.  The page at sourceforge.net largely describes
759          * numeric #defines that encode the version; if the compiler
760          * doesn't also offer a nice printable string, we try prettifying
761          * the number somehow.
762          */
763 #if defined(__GNUC__) && defined(__VERSION__)
764         /*
765          * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
766          * distinguish between them.
767          */
768 #if defined(__clang__)
769         g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
770 #elif defined(__llvm__)
771         g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
772 #else /* boring old GCC */
773         g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
774 #endif /* llvm */
775 #elif defined(__HP_aCC)
776         g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
777 #elif defined(__xlC__)
778         g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
779             (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
780 #ifdef __IBMC__
781         if ((__IBMC__ % 10) != 0)
782                 g_string_append_printf(str, " patch %d", __IBMC__ % 10);
783 #endif /* __IBMC__ */
784         g_string_append_printf(str, "\n");
785 #elif defined(__INTEL_COMPILER)
786         g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
787             __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
788         if ((__INTEL_COMPILER % 10) != 0)
789                 g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
790 #ifdef __INTEL_COMPILER_BUILD_DATE
791         g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
792             __INTEL_COMPILER_BUILD_DATE / 10000,
793             (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
794             __INTEL_COMPILER_BUILD_DATE % 100);
795 #endif /* __INTEL_COMPILER_BUILD_DATE */
796         g_string_append_printf(str, "\n");
797 #elif defined(_MSC_FULL_VER)
798 # if _MSC_FULL_VER > 99999999
799         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
800                                (_MSC_FULL_VER / 10000000) - 6,
801                                (_MSC_FULL_VER / 100000) % 100);
802 #  if (_MSC_FULL_VER % 100000) != 0
803         g_string_append_printf(str, " build %d",
804                                _MSC_FULL_VER % 100000);
805 #  endif
806 # else
807         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
808                                (_MSC_FULL_VER / 1000000) - 6,
809                                (_MSC_FULL_VER / 10000) % 100);
810 #  if (_MSC_FULL_VER % 10000) != 0
811         g_string_append_printf(str, " build %d",
812                                _MSC_FULL_VER % 10000);
813 #  endif
814 # endif
815         g_string_append_printf(str, "\n");
816 #elif defined(_MSC_VER)
817         /* _MSC_FULL_VER not defined, but _MSC_VER defined */
818         g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
819             (_MSC_VER / 100) - 6, _MSC_VER % 100);
820 #elif defined(__SUNPRO_C)
821         g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
822             (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
823         if ((__SUNPRO_C & 0xF) != 0)
824                 g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
825         g_string_append_printf(str, "\n");
826 #endif
827
828         end_string(str);
829 }
830
831 /*
832  * Get copyright information.
833  */
834 const char *
835 get_copyright_info(void)
836 {
837         return
838 "Copyright 1998-2013 Gerald Combs <gerald@wireshark.org> and contributors.\n"
839 "This is free software; see the source for copying conditions. There is NO\n"
840 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
841 }
842
843 #if defined(_WIN32)
844 /*
845  * Get the major OS version.
846  */
847 /* XXX - Should this return the minor version as well, e.g. 0x00050002? */
848 guint32
849 get_os_major_version()
850 {
851         OSVERSIONINFO info;
852         info.dwOSVersionInfoSize = sizeof info;
853         if (GetVersionEx(&info)) {
854                 return info.dwMajorVersion;
855         }
856         return 0;
857 }
858 #endif
859
860 /*
861  * Editor modelines
862  *
863  * Local Variables:
864  * c-basic-offset: 8
865  * tab-width: 8
866  * indent-tabs-mode: t
867  * End:
868  *
869  * ex: set shiftwidth=8 tabstop=8 noexpandtab:
870  * :indentSize=8:tabSize=8:noTabs=false:
871  */