[filesystem.c] Add a cast to aviod a warning with VisualStudio 2017.
[metze/wireshark/wip.git] / wsutil / os_version_info.c
index 3553beb09ad53e55d6f597ed16c9e0b1a0d34235..4ad3986e7ac8f05532fc01385a3bbb18ec3db5f0 100644 (file)
 
 #include "config.h"
 
+#include <string.h>
 #include <errno.h>
 
 #ifdef HAVE_SYS_UTSNAME_H
 #include <sys/utsname.h>
 #endif
 
-#ifdef HAVE_OS_X_FRAMEWORKS
+#ifdef HAVE_MACOS_FRAMEWORKS
 #include <CoreFoundation/CoreFoundation.h>
 #include <wsutil/cfutils.h>
 #endif
@@ -45,10 +46,10 @@ typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
 
 /*
  * Handles the rather elaborate process of getting OS version information
- * from OS X (we want the OS X version, not the Darwin version, the latter
+ * from macOS (we want the macOS version, not the Darwin version, the latter
  * being easy to get with uname()).
  */
-#ifdef HAVE_OS_X_FRAMEWORKS
+#ifdef HAVE_MACOS_FRAMEWORKS
 
 /*
  * Fetch a string, as a UTF-8 C string, from a dictionary, given a key.
@@ -70,11 +71,14 @@ get_string_from_dictionary(CFPropertyListRef dict, CFStringRef key)
 }
 
 /*
- * Get the OS X version information, and append it to the GString.
+ * Get the macOS version information, and append it to the GString.
  * Return TRUE if we succeed, FALSE if we fail.
+ *
+ * XXX - this gives the OS name as "Mac OS X" even if Apple called/calls
+ * it "OS X" or "macOS".
  */
 static gboolean
-get_os_x_version_info(GString *str)
+get_macos_version_info(GString *str)
 {
        static const UInt8 server_version_plist_path[] =
            "/System/Library/CoreServices/ServerVersion.plist";
@@ -86,7 +90,7 @@ get_os_x_version_info(GString *str)
        char *string;
 
        /*
-        * On OS X, report the OS X version number as the OS, and put
+        * On macOS, report the macOS version number as the OS, and put
         * the Darwin information in parentheses.
         *
         * Alas, Gestalt() is deprecated in Mountain Lion, so the build
@@ -198,6 +202,7 @@ void
 get_os_version_info(GString *str)
 {
 #if defined(_WIN32)
+       HMODULE kernel_dll_handle;
        OSVERSIONINFOEX info;
        SYSTEM_INFO system_info;
        nativesi_func_ptr nativesi_func;
@@ -237,7 +242,15 @@ get_os_version_info(GString *str)
        memset(&system_info, '\0', sizeof system_info);
        /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
         * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
-       nativesi_func = (nativesi_func_ptr)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo");
+       kernel_dll_handle = GetModuleHandle(_T("kernel32.dll"));
+       if (kernel_dll_handle == NULL) {
+               /*
+                * XXX - get the failure reason.
+                */
+               g_string_append(str, "unknown Windows version");
+               return;
+       }
+       nativesi_func = (nativesi_func_ptr)GetProcAddress(kernel_dll_handle, "GetNativeSystemInfo");
        if(nativesi_func)
                nativesi_func(&system_info);
        else
@@ -350,9 +363,6 @@ get_os_version_info(GString *str)
                        case 3:
                                g_string_append_printf(str, is_nt_workstation ? "Windows 8.1" : "Windows Server 2012 R2");
                                break;
-                       case 4:
-                               g_string_append_printf(str, is_nt_workstation ? "Windows 10" : "Windows Server 10");
-                               break;
                        default:
                                g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
                                                       info.dwMajorVersion, info.dwMinorVersion);
@@ -360,6 +370,27 @@ get_os_version_info(GString *str)
                        }
                        break;
                }  /* case 6 */
+
+               case 10: {
+                       gboolean is_nt_workstation;
+
+                       if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
+                               g_string_append(str, "64-bit ");
+                       else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
+                               g_string_append(str, "32-bit ");
+                       is_nt_workstation = (info.wProductType == VER_NT_WORKSTATION);
+                       switch (info.dwMinorVersion) {
+                       case 0:
+                               g_string_append_printf(str, is_nt_workstation ? "Windows 10" : "Windows Server 2016");
+                               break;
+                       default:
+                               g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
+                                                      info.dwMajorVersion, info.dwMinorVersion);
+                               break;
+                       }
+                       break;
+               }  /* case 10 */
+
                default:
                        g_string_append_printf(str, "Windows NT, unknown version %lu.%lu",
                            info.dwMajorVersion, info.dwMinorVersion);
@@ -403,23 +434,23 @@ get_os_version_info(GString *str)
                 * On Solaris, it's some kind of build information.
                 * On HP-UX, it appears to be some sort of subrevision
                 * thing.
-                * On *BSD and Darwin/OS X, it's a long string giving
+                * On *BSD and Darwin/macOS, it's a long string giving
                 * a build date, config file name, etc., etc., etc..
                 */
-#ifdef HAVE_OS_X_FRAMEWORKS
+#ifdef HAVE_MACOS_FRAMEWORKS
                /*
-                * On Mac OS X, report the Mac OS X version number as
-                * the OS version if we can, and put the Darwin information
+                * On macOS, report the macOS version number as the OS
+                * version if we can, and put the Darwin information
                 * in parentheses.
                 */
-               if (get_os_x_version_info(str)) {
+               if (get_macos_version_info(str)) {
                        /* Success - append the Darwin information. */
                        g_string_append_printf(str, " (%s %s)", name.sysname, name.release);
                } else {
                        /* Failure - just use the Darwin information. */
                        g_string_append_printf(str, "%s %s", name.sysname, name.release);
                }
-#else /* HAVE_OS_X_FRAMEWORKS */
+#else /* HAVE_MACOS_FRAMEWORKS */
                /*
                 * XXX - on Linux, are there any APIs to get the distribution
                 * name and version number?  I think some distributions have
@@ -472,7 +503,7 @@ get_os_version_info(GString *str)
                 * releases.
                 */
                g_string_append_printf(str, "%s %s", name.sysname, name.release);
-#endif /* HAVE_OS_X_FRAMEWORKS */
+#endif /* HAVE_MACOS_FRAMEWORKS */
        }
 #else
        g_string_append(str, "an unknown OS");