Imported Upstream version 6.4.0.137

Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-07-26 19:53:28 +00:00
parent e9207cf623
commit ef583813eb
2712 changed files with 74169 additions and 40587 deletions

View File

@@ -498,6 +498,7 @@ namespace System.Security.Authentication
Tls = 192,
Tls11 = 768,
Tls12 = 3072,
Tls13 = 12288,
[Obsolete("This value has been deprecated. It is no longer supported. http://go.microsoft.com/fwlink/?linkid=14202")]
Default = Ssl3 | Tls
}

View File

@@ -15,12 +15,14 @@ namespace System.Net
/// Provides an Internet Protocol (IP) address.
/// </para>
/// </devdoc>
#if MONO
[Serializable]
#endif
public class IPAddress
{
public static readonly IPAddress Any = new IPAddress(0x0000000000000000);
public static readonly IPAddress Loopback = new IPAddress(0x000000000100007F);
public static readonly IPAddress Broadcast = new IPAddress(0x00000000FFFFFFFF);
public static readonly IPAddress Any = new ReadOnlyIPAddress(0x0000000000000000);
public static readonly IPAddress Loopback = new ReadOnlyIPAddress(0x000000000100007F);
public static readonly IPAddress Broadcast = new ReadOnlyIPAddress(0x00000000FFFFFFFF);
public static readonly IPAddress None = Broadcast;
internal const long LoopbackMask = 0x00000000000000FF;
@@ -51,19 +53,6 @@ namespace System.Net
/// </summary>
private int _hashCode;
// Maximum length of address literals (potentially including a port number)
// generated by any address-to-string conversion routine. This length can
// be used when declaring buffers used with getnameinfo, WSAAddressToString,
// inet_ntoa, etc. We just provide one define, rather than one per api,
// to avoid confusion.
//
// The totals are derived from the following data:
// 15: IPv4 address
// 45: IPv6 address including embedded IPv4 address
// 11: Scope Id
// 2: Brackets around IPv6 address when port is present
// 6: Port (including colon)
// 1: Terminating null byte
internal const int NumberOfLabels = IPAddressParserStatics.IPv6AddressBytes / 2;
private bool IsIPv4
@@ -76,7 +65,7 @@ namespace System.Net
get { return _numbers != null; }
}
internal uint PrivateAddress
private uint PrivateAddress
{
get
{
@@ -516,7 +505,7 @@ namespace System.Net
}
}
[Obsolete("This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. http://go.microsoft.com/fwlink/?linkid=14202")]
[Obsolete("This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. https://go.microsoft.com/fwlink/?linkid=14202")]
public long Address
{
get
@@ -546,6 +535,10 @@ namespace System.Net
{
if (PrivateAddress != value)
{
if (this is ReadOnlyIPAddress)
{
throw new SocketException(SocketError.OperationNotSupported);
}
PrivateAddress = unchecked((uint)value);
}
}
@@ -609,8 +602,8 @@ namespace System.Net
int hashCode;
if (IsIPv6)
{
const int addressAndScopeIdLength = IPAddressParserStatics.IPv6AddressBytes + sizeof(uint);
Span<byte> addressAndScopeIdSpan = stackalloc byte[addressAndScopeIdLength];
const int AddressAndScopeIdLength = IPAddressParserStatics.IPv6AddressBytes + sizeof(uint);
Span<byte> addressAndScopeIdSpan = stackalloc byte[AddressAndScopeIdLength];
MemoryMarshal.AsBytes(new ReadOnlySpan<ushort>(_numbers)).CopyTo(addressAndScopeIdSpan);
Span<byte> scopeIdSpan = addressAndScopeIdSpan.Slice(IPAddressParserStatics.IPv6AddressBytes);
@@ -623,12 +616,9 @@ namespace System.Net
}
else
{
Span<uint> addressOrScopeIdSpan = stackalloc uint[1];
addressOrScopeIdSpan[0] = _addressOrScopeId;
// For IPv4 addresses, we use Marvin on the integer representation of the Address.
hashCode = Marvin.ComputeHash32(
MemoryMarshal.AsBytes(addressOrScopeIdSpan),
MemoryMarshal.AsBytes(MemoryMarshal.CreateReadOnlySpan(ref _addressOrScopeId, 1)),
Marvin.DefaultSeed);
}
@@ -671,7 +661,12 @@ namespace System.Net
return new IPAddress(address);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static byte[] ThrowAddressNullException() => throw new ArgumentNullException("address");
private sealed class ReadOnlyIPAddress : IPAddress
{
public ReadOnlyIPAddress(long newAddress) : base(newAddress)
{ }
}
}
}

View File

@@ -16,7 +16,7 @@ namespace System.Net
internal static unsafe IPAddress Parse(ReadOnlySpan<char> ipSpan, bool tryParse)
{
if (ipSpan.IndexOf(':') >= 0)
if (ipSpan.Contains(':'))
{
// The address is parsed as IPv6 if and only if it contains a colon. This is valid because
// we don't support/parse a port specification at the end of an IPv4 address.
@@ -47,6 +47,13 @@ namespace System.Net
return new string(addressString, 0, charsWritten);
}
internal static unsafe void IPv4AddressToString(uint address, StringBuilder destination)
{
char* addressString = stackalloc char[MaxIPv4StringLength];
int charsWritten = IPv4AddressToStringHelper(address, addressString);
destination.Append(addressString, charsWritten);
}
internal static unsafe bool IPv4AddressToString(uint address, Span<char> formatted, out int charsWritten)
{
if (formatted.Length < MaxIPv4StringLength)
@@ -124,7 +131,7 @@ namespace System.Net
{
buffer.Append(':');
}
buffer.Append(IPAddressParser.IPv4AddressToString(ExtractIPv4Address(address)));
IPv4AddressToString(ExtractIPv4Address(address), buffer);
}
else
{
@@ -218,7 +225,11 @@ namespace System.Net
if (c < '0' || c > '9')
{
scope = 0;
#if MONO // zoneId can be a string, see https://github.com/dotnet/corefx/issues/27529
return true;
#else
return false;
#endif
}
result = (result * 10) + (c - '0');
if (result > uint.MaxValue)
@@ -245,7 +256,8 @@ namespace System.Net
private static void AppendSections(ushort[] address, int fromInclusive, int toExclusive, StringBuilder buffer)
{
// Find the longest sequence of zeros to be combined into a "::"
(int zeroStart, int zeroEnd) = IPv6AddressHelper.FindCompressionRange(address, fromInclusive, toExclusive);
ReadOnlySpan<ushort> addressSpan = new ReadOnlySpan<ushort>(address, fromInclusive, toExclusive - fromInclusive);
(int zeroStart, int zeroEnd) = IPv6AddressHelper.FindCompressionRange(addressSpan);
bool needsColon = false;
// Output all of the numbers before the zero sequence