1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System.Net.Sockets;
6 using System.Runtime.InteropServices;
7 
8 namespace System.Net.Test.Common
9 {
10     public static partial class Capability
11     {
12         // TODO: Using RtlGetVersion is temporary until issue #4741 gets resolved.
13         [DllImport("ntdll", CharSet = CharSet.Unicode)]
RtlGetVersion(ref RTL_OSVERSIONINFOW lpVersionInformation)14         private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOW lpVersionInformation);
15 
16         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
17         private struct RTL_OSVERSIONINFOW
18         {
19             internal uint dwOSVersionInfoSize;
20             internal uint dwMajorVersion;
21             internal uint dwMinorVersion;
22             internal uint dwBuildNumber;
23             internal uint dwPlatformId;
24             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
25             internal char[] szCSDVersion;
26         }
27 
SocketsReuseUnicastPortSupport()28         public static bool? SocketsReuseUnicastPortSupport()
29         {
30             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
31             {
32                 RTL_OSVERSIONINFOW v = default(RTL_OSVERSIONINFOW);
33                 v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOW>();
34                 RtlGetVersion(ref v);
35 
36                 if (v.dwMajorVersion == 10)
37                 {
38                     return true;
39                 }
40                 else if (v.dwMajorVersion == 6 && (v.dwMinorVersion == 2 || v.dwMinorVersion == 3))
41                 {
42                     // On Windows 8/Windows Server 2012 (major=6, minor=2) or Windows 8.1/Windows Server 2012 R2
43                     // (major=6, minor=3), this feature is not present unless a servicing patch is installed.
44                     // So, we return null to indicate that it is indeterminate whether the feature is active.
45                     return null;
46                 }
47                 else
48                 {
49                     return false;
50                 }
51             }
52 
53             return false;
54         }
55 
IPv6Support()56         public static bool IPv6Support()
57         {
58             return Socket.OSSupportsIPv6;
59         }
60 
IPv4Support()61         public static bool IPv4Support()
62         {
63             return Socket.OSSupportsIPv4;
64         }
65     }
66 }
67