Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@ -40,6 +40,9 @@
<Compile Include="$(CommonPath)\System\Net\Sockets\SocketType.cs">
<Link>Common\System\Net\Sockets\SocketType.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Net\IPAddressParserStatics.cs">
<Link>Common\System\Net\IPAddressParserStatics.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Net\IPEndPointStatics.cs">
<Link>Common\System\Net\IPEndPointStatics.cs</Link>
</Compile>

View File

@ -6,7 +6,7 @@ namespace System.Net
{
// Host information
/// <devdoc>
/// <para>Provides a container class for Internet host address information..</para>
/// <para>Provides a container class for Internet host address information.</para>
/// </devdoc>
public class IPHostEntry
{

View File

@ -141,6 +141,12 @@ namespace System.Net
public static unsafe IPHostEntry GetHostByName(string hostName)
{
if (hostName == "")
{
// To match documented behavior on Windows, if an empty string is passed in, use the local host's name.
hostName = Dns.GetHostName();
}
Interop.Sys.HostEntry entry;
int err = Interop.Sys.GetHostByName(hostName, &entry);
if (err != 0)
@ -167,6 +173,12 @@ namespace System.Net
public static unsafe SocketError TryGetAddrInfo(string name, out IPHostEntry hostinfo, out int nativeErrorCode)
{
if (name == "")
{
// To match documented behavior on Windows, if an empty string is passed in, use the local host's name.
name = Dns.GetHostName();
}
Interop.Sys.HostEntry entry;
int result = Interop.Sys.GetHostEntryForName(name, &entry);
if (result != 0)

View File

@ -172,7 +172,9 @@ namespace System.Net
public static IPHostEntry GetHostByAddr(IPAddress address)
{
// TODO #2891: Optimize this (or decide if this legacy code can be removed):
int addressAsInt = unchecked((int)address.GetAddress());
#pragma warning disable CS0618 // Address is marked obsolete
int addressAsInt = unchecked((int)address.Address);
#pragma warning restore CS0618
#if BIGENDIAN
// TODO #2891: above code needs testing for BIGENDIAN.

View File

@ -101,5 +101,23 @@ namespace System.Net.NameResolution.Tests
Assert.Equal(1, entry.AddressList.Length);
Assert.Equal(IPAddress.IPv6Loopback, entry.AddressList[0]);
}
[Fact]
public void DnsObsoleteGetHostByName_EmptyString_ReturnsHostName()
{
IPHostEntry entry = Dns.GetHostByName("");
// DNS labels should be compared as case insensitive for ASCII characters. See RFC 4343.
Assert.Contains(Dns.GetHostName(), entry.HostName, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void DnsObsoleteBeginEndGetHostByName_EmptyString_ReturnsHostName()
{
IPHostEntry entry = Dns.EndGetHostByName(Dns.BeginGetHostByName("", null, null));
// DNS labels should be compared as case insensitive for ASCII characters. See RFC 4343.
Assert.Contains(Dns.GetHostName(), entry.HostName, StringComparison.OrdinalIgnoreCase);
}
}
}

View File

@ -20,10 +20,20 @@ namespace System.Net.NameResolution.Tests
TestGetHostEntryAsync(() => Dns.GetHostEntryAsync(localIPAddress));
}
[Fact]
public void Dns_GetHostEntryAsync_HostString_Ok()
[Theory]
[InlineData("")]
[InlineData(TestSettings.LocalHost)]
public void Dns_GetHostEntry_HostString_Ok(string hostName)
{
TestGetHostEntryAsync(() => Dns.GetHostEntryAsync(TestSettings.LocalHost));
TestGetHostEntryAsync(() => Task.FromResult(Dns.GetHostEntry(hostName)));
}
[Theory]
[InlineData("")]
[InlineData(TestSettings.LocalHost)]
public void Dns_GetHostEntryAsync_HostString_Ok(string hostName)
{
TestGetHostEntryAsync(() => Dns.GetHostEntryAsync(hostName));
}
[Fact]
@ -81,34 +91,6 @@ namespace System.Net.NameResolution.Tests
await Assert.ThrowsAsync<ArgumentException>(() => Dns.GetHostEntryAsync(addressString));
}
public static IEnumerable<object[]> GetNoneAddresses()
{
yield return new object[] { IPAddress.None };
}
[PlatformSpecific(~TestPlatforms.OSX)] // macOS will resolve IPAddress.None to broadcasthost and produce a valid listing
[Theory]
[MemberData(nameof(GetNoneAddresses))]
public async Task Dns_GetHostEntryAsync_NoneIPAddress_Fail(IPAddress address)
{
string addressString = address.ToString();
await Assert.ThrowsAnyAsync<SocketException>(() => Dns.GetHostEntryAsync(address));
await Assert.ThrowsAnyAsync<SocketException>(() => Dns.GetHostEntryAsync(addressString));
}
[PlatformSpecific(TestPlatforms.OSX)] // macOS will resolve IPAddress.None to broadcasthost and produce a valid listing
[Theory]
[MemberData(nameof(GetNoneAddresses))]
public async Task Dns_GetHostEntryAsync_NoneIPAddress_Success(IPAddress address)
{
IPHostEntry result = await Dns.GetHostEntryAsync(address);
Assert.NotNull(result);
Assert.NotNull(result.AddressList);
Assert.Equal(1, result.AddressList.Length);
Assert.Equal(address, result.AddressList[0]);
}
[Fact]
public void DnsBeginGetHostEntry_BadName_Throws()
{

View File

@ -0,0 +1,11 @@
// 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.
namespace System.Net
{
internal static class Dns
{
public static string GetHostName() => string.Empty;
}
}

View File

@ -0,0 +1,27 @@
// 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.Diagnostics;
namespace System.Net
{
internal static class IPAddressFakeExtensions
{
public static bool TryWriteBytes(this IPAddress address, Span<byte> destination, out int bytesWritten)
{
byte[] bytes = address.GetAddressBytes();
if (bytes.Length >= destination.Length)
{
new ReadOnlySpan<byte>(bytes).CopyTo(destination);
bytesWritten = bytes.Length;
return true;
}
else
{
bytesWritten = 0;
return false;
}
}
}
}

View File

@ -26,6 +26,8 @@
<ItemGroup>
<Compile Include="NameResolutionPalTests.cs" />
<Compile Include="Fakes\DebugThreadTracking.cs" />
<Compile Include="Fakes\DnsFake.cs" />
<Compile Include="Fakes\IPAddressFakeExtensions.cs" />
<Compile Include="$(CommonPath)\System\Net\Logging\NetEventSource.Common.cs">
<Link>Common\System\Net\Logging\NetEventSource.cs</Link>
</Compile>
@ -41,6 +43,9 @@
<Compile Include="$(CommonPath)\System\Net\IPEndPointStatics.cs">
<Link>Common\System\Net\IPEndPointStatics.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Net\IPAddressParserStatics.cs">
<Link>Common\System\Net\IPAddressParserStatics.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Configuration.cs">
<Link>Common\System\Net\Configuration.cs</Link>
</Compile>
@ -65,10 +70,6 @@
<Compile Include="$(CommonPath)\System\Net\DebugSafeHandle.cs">
<Link>Common\System\Net\DebugSafeHandle.cs</Link>
</Compile>
<!-- System.Net.Internals -->
<Compile Include="$(CommonPath)\System\Net\Internals\IPAddressExtensions.cs">
<Link>Common\System\Net\Internals\IPAddressExtensions.cs</Link>
</Compile>
<!-- Interop -->
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
<Link>Interop\Windows\Interop.Libraries.cs</Link>
@ -170,4 +171,4 @@
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>