clean win code
authorMarco Rossignoli <marco.rossignoli@gmail.com>
Thu, 8 Feb 2018 10:26:43 +0000 (11:26 +0100)
committerMarco Rossignoli <marco.rossignoli@gmail.com>
Thu, 8 Feb 2018 10:26:43 +0000 (11:26 +0100)
Commit migrated from https://github.com/dotnet/corefx/commit/4bb1dc2994cfb2680f97c45021d2a778b5f8f008

src/libraries/Common/src/Interop/Windows/Winsock/Interop.gethostbyname.cs [deleted file]
src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj
src/libraries/System.Net.NameResolution/src/System/Net/DNS.cs
src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs
src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs

diff --git a/src/libraries/Common/src/Interop/Windows/Winsock/Interop.gethostbyname.cs b/src/libraries/Common/src/Interop/Windows/Winsock/Interop.gethostbyname.cs
deleted file mode 100644 (file)
index ec141b5..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
-    internal static partial class Winsock
-    {
-        [DllImport(Interop.Libraries.Ws2_32, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true, SetLastError = true)]
-        internal static extern IntPtr gethostbyname(
-                                              [In] string host
-                                              );
-    }
-}
index ef34f96..62423e4 100644 (file)
@@ -5,7 +5,7 @@
     <AssemblyName>System.Net.NameResolution</AssemblyName>
     <ProjectGuid>{1714448C-211E-48C1-8B7E-4EE667D336A1}</ProjectGuid>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-  </PropertyGroup>   
+  </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap-Windows_NT-Debug|AnyCPU'" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap-Windows_NT-Release|AnyCPU'" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Windows_NT-Debug|AnyCPU'" />
@@ -91,9 +91,6 @@
     <Compile Include="$(CommonPath)\Interop\Windows\Winsock\Interop.gethostbyaddr.cs">
       <Link>Interop\Windows\Winsock\Interop.gethostbyaddr.cs</Link>
     </Compile>
-    <Compile Include="$(CommonPath)\Interop\Windows\Winsock\Interop.gethostbyname.cs">
-      <Link>Interop\Windows\Winsock\Interop.gethostbyname.cs</Link>
-    </Compile>
     <Compile Include="$(CommonPath)\Interop\Windows\Winsock\Interop.gethostname.cs">
       <Link>Interop\Windows\Winsock\Interop.gethostname.cs</Link>
     </Compile>
     <Reference Include="System.Threading.Tasks" />
   </ItemGroup>
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project>
+</Project>
\ No newline at end of file
index 68aaf0f..d10e0c5 100644 (file)
@@ -38,10 +38,10 @@ namespace System.Net
             {
                 return NameResolutionUtilities.GetUnresolvedAnswer(address);
             }
-            return InternalGetHostByName(hostName, false);
+            return InternalGetHostByName(hostName);
         }
 
-        private static IPHostEntry InternalGetHostByName(string hostName, bool includeIPv6)
+        private static IPHostEntry InternalGetHostByName(string hostName)
         {
             if (NetEventSource.IsEnabled) NetEventSource.Enter(null, hostName);
             IPHostEntry ipHostEntry = null;
@@ -59,7 +59,7 @@ namespace System.Net
             {
                 throw SocketExceptionFactory.CreateSocketException(errorCode, nativeErrorCode);
             }
-           
+
             if (NetEventSource.IsEnabled) NetEventSource.Exit(null, ipHostEntry);
             return ipHostEntry;
         } // GetHostByName
@@ -219,7 +219,7 @@ namespace System.Net
             }
             else
             {
-                ipHostEntry = InternalGetHostByName(hostName, false);
+                ipHostEntry = InternalGetHostByName(hostName);
             }
 
             if (NetEventSource.IsEnabled) NetEventSource.Exit(null, ipHostEntry);
@@ -261,7 +261,7 @@ namespace System.Net
                 }
                 else
                 {
-                    hostEntry = InternalGetHostByName(result.hostName, result.includeIPv6);
+                    hostEntry = InternalGetHostByName(result.hostName);
                 }
             }
             catch (OutOfMemoryException)
@@ -446,7 +446,7 @@ namespace System.Net
             }
             else
             {
-                ipHostEntry = InternalGetHostByName(hostNameOrAddress, true);
+                ipHostEntry = InternalGetHostByName(hostNameOrAddress);
             }
 
             if (NetEventSource.IsEnabled) NetEventSource.Exit(null, ipHostEntry);
@@ -500,7 +500,7 @@ namespace System.Net
             {
                 // InternalGetHostByName works with IP addresses (and avoids a reverse-lookup), but we need
                 // explicit handling in order to do the ArgumentException and guarantee the behavior.
-                addresses = InternalGetHostByName(hostNameOrAddress, true).AddressList;
+                addresses = InternalGetHostByName(hostNameOrAddress).AddressList;
             }
 
             if (NetEventSource.IsEnabled) NetEventSource.Exit(null, addresses);
index 36a69f8..bd8cb8a 100644 (file)
@@ -141,34 +141,6 @@ namespace System.Net
             return HostEntry;
         } // NativeToHostEntry
 
-        public static IPHostEntry GetHostByName(string hostName)
-        {
-            //
-            // IPv6 disabled: use gethostbyname() to obtain DNS information.
-            //
-            IntPtr nativePointer =
-                Interop.Winsock.gethostbyname(
-                    hostName);
-
-            if (nativePointer == IntPtr.Zero)
-            {
-                // Need to do this first since if we wait the last error code might be overwritten.
-                SocketException socketException = new SocketException();
-
-                IPAddress address;
-                if (IPAddress.TryParse(hostName, out address))
-                {
-                    IPHostEntry ipHostEntry = NameResolutionUtilities.GetUnresolvedAnswer(address);
-                    if (NetEventSource.IsEnabled) NetEventSource.Exit(null, ipHostEntry);
-                    return ipHostEntry;
-                }
-
-                throw socketException;
-            }
-
-            return NativeToHostEntry(nativePointer);
-        }
-
         public static IPHostEntry GetHostByAddr(IPAddress address)
         {
             // TODO #2891: Optimize this (or decide if this legacy code can be removed):
index 2de0216..cde1a96 100644 (file)
@@ -23,88 +23,12 @@ namespace System.Net.NameResolution.PalTests
         }
 
         [Fact]
-        public void GetHostByName_LocalHost()
-        {
-            IPHostEntry hostEntry = NameResolutionPal.GetHostByName("localhost");
-            Assert.NotNull(hostEntry);
-            Assert.NotNull(hostEntry.HostName);
-            Assert.NotNull(hostEntry.AddressList);
-            Assert.NotNull(hostEntry.Aliases);
-        }
-
-        public static object[][] InvalidHostNames = new object[][] {
-            new object[] { ":" },
-            new object[] { "..." }
-        };
-
-        [Theory, MemberData(nameof(InvalidHostNames))]
-        public void GetHostByName_InvalidHostName_Throws(string hostName)
-        {
-            Assert.ThrowsAny<SocketException>(() => NameResolutionPal.GetHostByName(hostName));
-        }
-
-        [ActiveIssue(20245, TestPlatforms.AnyUnix)]
-        [Fact]
-        public void GetHostByName_HostName()
-        {
-            string hostName = NameResolutionPal.GetHostName();
-            Assert.NotNull(hostName);
-
-            IPHostEntry hostEntry = NameResolutionPal.GetHostByName(hostName);
-            Assert.NotNull(hostEntry);
-            Assert.NotNull(hostEntry.HostName);
-            Assert.NotNull(hostEntry.AddressList);
-            Assert.NotNull(hostEntry.Aliases);
-        }
-
-        [Fact]
         public void GetHostByAddr_LocalHost()
         {
             Assert.NotNull(NameResolutionPal.GetHostByAddr(new IPAddress(0x0100007f)));
         }
 
         [Fact]
-        public void GetHostByName_LocalHost_GetHostByAddr()
-        {
-            IPHostEntry hostEntry1 = NameResolutionPal.GetHostByName("localhost");
-            Assert.NotNull(hostEntry1);
-            IPHostEntry hostEntry2 = NameResolutionPal.GetHostByAddr(hostEntry1.AddressList[0]);
-            Assert.NotNull(hostEntry2);
-
-            IPAddress[] list1 = hostEntry1.AddressList;
-            IPAddress[] list2 = hostEntry2.AddressList;
-
-            for (int i = 0; i < list1.Length; i++)
-            {
-                Assert.NotEqual(-1, Array.IndexOf(list2, list1[i]));
-            }
-        }
-
-        [Fact]
-        public void GetHostByName_HostName_GetHostByAddr()
-        {
-            IPHostEntry hostEntry1 = NameResolutionPal.GetHostByName(System.Net.Test.Common.Configuration.Http.Http2Host);
-            Assert.NotNull(hostEntry1);
-
-            IPAddress[] list1 = hostEntry1.AddressList;
-            Assert.InRange(list1.Length, 1, Int32.MaxValue);
-
-            foreach (IPAddress addr1 in list1)
-            {
-                IPHostEntry hostEntry2 = NameResolutionPal.GetHostByAddr(addr1);
-                Assert.NotNull(hostEntry2);
-
-                IPAddress[] list2 = hostEntry2.AddressList;
-                Assert.InRange(list2.Length, 1, list1.Length);
-
-                foreach (IPAddress addr2 in list2)
-                {
-                    Assert.NotEqual(-1, Array.IndexOf(list1, addr2));
-                }
-            }
-        }
-
-        [Fact]
         public void TryGetAddrInfo_LocalHost()
         {
             IPHostEntry hostEntry;