Imported Upstream version 5.20.0.180

Former-commit-id: ff953ca879339fe1e1211f7220f563e1342e66cb
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-02-04 20:11:37 +00:00
parent 0e2d47d1c8
commit 0510252385
3360 changed files with 83827 additions and 39243 deletions

View File

@@ -30,6 +30,7 @@
using System;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
@@ -326,7 +327,7 @@ namespace System.Net.NetworkInformation {
internal sealed class LinuxNetworkChange : INetworkChange {
[Flags]
enum EventType {
enum EventType : int {
Availability = 1 << 0,
Address = 1 << 1,
}
@@ -485,20 +486,25 @@ namespace System.Net.NetworkInformation {
}
}
#if MONOTOUCH || MONODROID
const string LIBNAME = "__Internal";
#else
const string LIBNAME = "MonoPosixHelper";
#endif
[DllImport (LIBNAME, CallingConvention=CallingConvention.Cdecl)]
#if MONODROID
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern IntPtr CreateNLSocket ();
[DllImport (LIBNAME, CallingConvention=CallingConvention.Cdecl)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern EventType ReadEvents (IntPtr sock, IntPtr buffer, int count, int size);
[DllImport (LIBNAME, CallingConvention=CallingConvention.Cdecl)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern IntPtr CloseNLSocket (IntPtr sock);
#else
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr CreateNLSocket ();
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
static extern EventType ReadEvents (IntPtr sock, IntPtr buffer, int count, int size);
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr CloseNLSocket (IntPtr sock);
#endif
}
#endif

View File

@@ -79,6 +79,25 @@ namespace System.Net.NetworkInformation {
return c;
}
public static Win32IPAddressCollection FromSocketAddress (Win32_SOCKET_ADDRESS addr)
{
Win32IPAddressCollection c = new Win32IPAddressCollection ();
if (addr.Sockaddr != IntPtr.Zero)
c.InternalAdd (addr.GetIPAddress ());
return c;
}
public static Win32IPAddressCollection FromWinsServer (IntPtr ptr)
{
Win32IPAddressCollection c = new Win32IPAddressCollection ();
Win32_IP_ADAPTER_WINS_SERVER_ADDRESS a;
for (IntPtr p = ptr; p != IntPtr.Zero; p = a.Next) {
a = (Win32_IP_ADAPTER_WINS_SERVER_ADDRESS) Marshal.PtrToStructure (p, typeof (Win32_IP_ADAPTER_WINS_SERVER_ADDRESS));
c.InternalAdd (a.Address.GetIPAddress ());
}
return c;
}
void AddSubsequentlyString (IntPtr head)
{
Win32_IP_ADDR_STRING a;

View File

@@ -44,13 +44,11 @@ namespace System.Net.NetworkInformation {
public override IPv4InterfaceProperties GetIPv4Properties ()
{
Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
return new Win32IPv4InterfaceProperties (v4info, mib4);
return new Win32IPv4InterfaceProperties (addr, mib4);
}
public override IPv6InterfaceProperties GetIPv6Properties ()
{
Win32_IP_ADAPTER_INFO v6info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib6.Index);
return new Win32IPv6InterfaceProperties (mib6);
}
@@ -74,10 +72,9 @@ namespace System.Net.NetworkInformation {
public override IPAddressCollection DhcpServerAddresses {
get {
Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
// FIXME: should ipv6 DhcpServer be considered?
try {
return new Win32IPAddressCollection (v4info.DhcpServer);
return Win32IPAddressCollection.FromSocketAddress (addr.Dhcpv4Server);
} catch (IndexOutOfRangeException) {
return Win32IPAddressCollection.Empty;
}
@@ -96,28 +93,17 @@ namespace System.Net.NetworkInformation {
get {
var col = new GatewayIPAddressInformationCollection ();
try {
Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
// FIXME: should ipv6 DhcpServer be considered?
var a = v4info.GatewayList;
if (!String.IsNullOrEmpty (a.IpAddress)) {
col.InternalAdd(new SystemGatewayIPAddressInformation(IPAddress.Parse (a.IpAddress)));
AddSubsequently (a.Next, col);
Win32_IP_ADAPTER_GATEWAY_ADDRESS a;
for (IntPtr p = addr.FirstGatewayAddress; p != IntPtr.Zero; p = a.Next) {
a = (Win32_IP_ADAPTER_GATEWAY_ADDRESS) Marshal.PtrToStructure (p, typeof (Win32_IP_ADAPTER_GATEWAY_ADDRESS));
col.InternalAdd (new SystemGatewayIPAddressInformation (a.Address.GetIPAddress ()));
}
} catch (IndexOutOfRangeException) {}
return col;
}
}
static void AddSubsequently (IntPtr head, GatewayIPAddressInformationCollection col)
{
Win32_IP_ADDR_STRING a;
for (IntPtr p = head; p != IntPtr.Zero; p = a.Next) {
a = (Win32_IP_ADDR_STRING) Marshal.PtrToStructure (p, typeof (Win32_IP_ADDR_STRING));
col.InternalAdd (new SystemGatewayIPAddressInformation (IPAddress.Parse (a.IpAddress)));
}
}
public override bool IsDnsEnabled {
get { return Win32NetworkInterface.FixedInfo.EnableDns != 0; }
}
@@ -147,7 +133,6 @@ namespace System.Net.NetworkInformation {
public override UnicastIPAddressInformationCollection UnicastAddresses {
get {
try {
Win32_IP_ADAPTER_INFO ai = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
// FIXME: should ipv6 DhcpServer be considered?
return Win32FromUnicast (addr.FirstUnicastAddress);
} catch (IndexOutOfRangeException) {
@@ -170,9 +155,7 @@ namespace System.Net.NetworkInformation {
public override IPAddressCollection WinsServersAddresses {
get {
try {
Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
// FIXME: should ipv6 DhcpServer be considered?
return new Win32IPAddressCollection (v4info.PrimaryWinsServer, v4info.SecondaryWinsServer);
return Win32IPAddressCollection.FromWinsServer (addr.FirstWinsServerAddress);
} catch (IndexOutOfRangeException) {
return Win32IPAddressCollection.Empty;
}

View File

@@ -36,13 +36,13 @@ namespace System.Net.NetworkInformation {
[DllImport ("iphlpapi.dll")]
static extern int GetPerAdapterInfo (int IfIndex, Win32_IP_PER_ADAPTER_INFO pPerAdapterInfo, ref int pOutBufLen);
Win32_IP_ADAPTER_INFO ainfo;
Win32_IP_ADAPTER_ADDRESSES addr;
Win32_IP_PER_ADAPTER_INFO painfo;
Win32_MIB_IFROW mib;
public Win32IPv4InterfaceProperties (Win32_IP_ADAPTER_INFO ainfo, Win32_MIB_IFROW mib)
public Win32IPv4InterfaceProperties (Win32_IP_ADAPTER_ADDRESSES addr, Win32_MIB_IFROW mib)
{
this.ainfo = ainfo;
this.addr = addr;
this.mib = mib;
// get per-adapter info.
@@ -67,7 +67,7 @@ namespace System.Net.NetworkInformation {
}
public override bool IsDhcpEnabled {
get { return ainfo.DhcpEnabled != 0; }
get { return addr.DhcpEnabled; }
}
public override bool IsForwardingEnabled {
@@ -80,7 +80,7 @@ namespace System.Net.NetworkInformation {
}
public override bool UsesWins {
get { return ainfo.HaveWins; }
get { return addr.FirstWinsServerAddress != IntPtr.Zero; }
}
}

View File

@@ -49,9 +49,12 @@ namespace System.Net.NetworkInformation {
{
IntPtr ptr = IntPtr.Zero;
int len = 0;
GetAdaptersAddresses (0, 0, IntPtr.Zero, ptr, ref len);
uint flags = Win32_IP_ADAPTER_ADDRESSES.GAA_FLAG_INCLUDE_WINS_INFO | Win32_IP_ADAPTER_ADDRESSES.GAA_FLAG_INCLUDE_GATEWAYS;
GetAdaptersAddresses (0, flags, IntPtr.Zero, ptr, ref len);
if (Marshal.SizeOf (typeof (Win32_IP_ADAPTER_ADDRESSES)) > len)
throw new NetworkInformationException ();
ptr = Marshal.AllocHGlobal(len);
int ret = GetAdaptersAddresses (0, 0, IntPtr.Zero, ptr, ref len);
int ret = GetAdaptersAddresses (0, flags, IntPtr.Zero, ptr, ref len);
if (ret != 0)
throw new NetworkInformationException (ret);
@@ -105,14 +108,6 @@ namespace System.Net.NetworkInformation {
[DllImport ("iphlpapi.dll", SetLastError = true)]
static extern int GetIfEntry (ref Win32_MIB_IFROW row);
public static Win32_IP_ADAPTER_INFO GetAdapterInfoByIndex (int index)
{
foreach (Win32_IP_ADAPTER_INFO info in GetAdaptersInfo ())
if (info.Index == index)
return info;
throw new IndexOutOfRangeException ("No adapter found for index " + index);
}
static Win32_IP_ADAPTER_INFO [] GetAdaptersInfo ()
{
int len = 0;

View File

@@ -109,15 +109,37 @@ namespace System.Net.NetworkInformation
public NetworkInterfaceType IfType;
public OperationalStatus OperStatus;
public int Ipv6IfIndex;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 16 * 4)]
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 16)]
public uint [] ZoneIndices;
public IntPtr FirstPrefix; // to PIP_ADAPTER_PREFIX
public UInt64 TransmitLinkSpeed;
public UInt64 ReceiveLinkSpeed;
public IntPtr FirstWinsServerAddress; // to PIP_ADAPTER_WINS_SERVER_ADDRESS_LH
public IntPtr FirstGatewayAddress; // to PIP_ADAPTER_GATEWAY_ADDRESS_LH
public uint Ipv4Metric;
public uint Ipv6Metric;
public UInt64 Luid;
public Win32_SOCKET_ADDRESS Dhcpv4Server;
public uint CompartmentId;
public UInt64 NetworkGuid;
public int ConnectionType;
public int TunnelType;
public Win32_SOCKET_ADDRESS Dhcpv6Server;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = MAX_DHCPV6_DUID_LENGTH)]
public byte [] Dhcpv6ClientDuid;
public ulong Dhcpv6ClientDuidLength;
public ulong Dhcpv6Iaid;
public IntPtr FirstDnsSuffix; // to PIP_ADAPTER_DNS_SUFFIX
// Note that Vista-only members and XP-SP1-only member are
// omitted.
//Flags For GetAdapterAddresses
public const int GAA_FLAG_INCLUDE_WINS_INFO = 0x0040;
public const int GAA_FLAG_INCLUDE_GATEWAYS = 0x0080;
const int MAX_ADAPTER_ADDRESS_LENGTH = 8;
const int MAX_DHCPV6_DUID_LENGTH = 130;
const int IP_ADAPTER_DDNS_ENABLED = 1;
const int IP_ADAPTER_DHCP_ENABLED = 4;
const int IP_ADAPTER_RECEIVE_ONLY = 8;
const int IP_ADAPTER_NO_MULTICAST = 0x10;
@@ -125,6 +147,10 @@ namespace System.Net.NetworkInformation
get { return (Flags & IP_ADAPTER_DDNS_ENABLED) != 0; }
}
public bool DhcpEnabled {
get { return (Flags & IP_ADAPTER_DHCP_ENABLED) != 0; }
}
public bool IsReceiveOnly {
get { return (Flags & IP_ADAPTER_RECEIVE_ONLY) != 0; }
}
@@ -255,6 +281,22 @@ namespace System.Net.NetworkInformation
public Win32_SOCKET_ADDRESS Address;
}
[StructLayout (LayoutKind.Sequential)]
struct Win32_IP_ADAPTER_GATEWAY_ADDRESS
{
public Win32LengthFlagsUnion LengthFlags;
public IntPtr Next; // to Win32_IP_ADAPTER_GATEWAY_ADDRESS
public Win32_SOCKET_ADDRESS Address;
}
[StructLayout (LayoutKind.Sequential)]
struct Win32_IP_ADAPTER_WINS_SERVER_ADDRESS
{
public Win32LengthFlagsUnion LengthFlags;
public IntPtr Next; // to Win32_IP_ADAPTER_WINS_SERVER_ADDRESS
public Win32_SOCKET_ADDRESS Address;
}
[StructLayout (LayoutKind.Sequential)]
struct Win32_IP_ADAPTER_UNICAST_ADDRESS
{