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