X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FSystem.Net.NetworkInformation%2FNetworkInterface.cs;h=d1bf2e763b08f02eb55c7bd576b58c423bbacf9d;hb=2b26601921e81cb719bc8df5156375c62c4620ab;hp=2177ecf43c2792f0e1681fb95f40005c6702fc80;hpb=40d516ff7b83371c9e78893db0106aeee6177f4f;p=mono.git diff --git a/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs b/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs index 2177ecf43c2..d1bf2e763b0 100644 --- a/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs +++ b/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs @@ -41,15 +41,11 @@ using System.IO; using System.Globalization; namespace System.Net.NetworkInformation { - public abstract class NetworkInterface { + static class SystemNetworkInterface { static readonly NetworkInterfaceFactory nif = NetworkInterfaceFactory.Create (); - protected NetworkInterface () - { - } - - public static NetworkInterface [] GetAllNetworkInterfaces () + public static NetworkInterface [] GetNetworkInterfaces () { try { return nif.GetAllNetworkInterfaces (); @@ -58,36 +54,28 @@ namespace System.Net.NetworkInformation { } } - [MonoTODO("Always returns true")] - public static bool GetIsNetworkAvailable () + public static bool InternalGetIsNetworkAvailable () { + // TODO: return true; } - - public static int LoopbackInterfaceIndex { + + public static int InternalLoopbackInterfaceIndex { get { return nif.GetLoopbackInterfaceIndex (); } } + public static int InternalIPv6LoopbackInterfaceIndex { + get { + throw new NotImplementedException (); + } + } + public static IPAddress GetNetMask (IPAddress address) { return nif.GetNetMask (address); } - - public abstract IPInterfaceProperties GetIPProperties (); - public abstract IPv4InterfaceStatistics GetIPv4Statistics (); - public abstract PhysicalAddress GetPhysicalAddress (); - public abstract bool Supports (NetworkInterfaceComponent networkInterfaceComponent); - - public abstract string Description { get; } - public abstract string Id { get; } - public abstract bool IsReceiveOnly { get; } - public abstract string Name { get; } - public abstract NetworkInterfaceType NetworkInterfaceType { get; } - public abstract OperationalStatus OperationalStatus { get; } - public abstract long Speed { get; } - public abstract bool SupportsMulticast { get; } } abstract class NetworkInterfaceFactory @@ -450,9 +438,14 @@ namespace System.Net.NetworkInformation { #if !MOBILE class Win32NetworkInterfaceAPI : NetworkInterfaceFactory { - [DllImport ("iphlpapi.dll", SetLastError = true)] + private const string IPHLPAPI = "iphlpapi.dll"; + + [DllImport (IPHLPAPI, SetLastError = true)] static extern int GetAdaptersAddresses (uint family, uint flags, IntPtr reserved, byte [] info, ref int size); + [DllImport (IPHLPAPI)] + static extern uint GetBestInterfaceEx (byte[] ipAddress, out int index); + unsafe static Win32_IP_ADAPTER_ADDRESSES [] GetAdaptersAddresses () { byte [] bytes = null; @@ -485,9 +478,20 @@ namespace System.Net.NetworkInformation { return ret; } + private static int GetBestInterfaceForAddress (IPAddress addr) { + int index; + SocketAddress address = new SocketAddress (addr); + int error = (int) GetBestInterfaceEx (address.m_Buffer, out index); + if (error != 0) { + throw new NetworkInformationException (error); + } + + return index; + } + public override int GetLoopbackInterfaceIndex () { - throw new NotImplementedException (); + return GetBestInterfaceForAddress (IPAddress.Loopback); } public override IPAddress GetNetMask (IPAddress address) @@ -516,7 +520,7 @@ namespace System.Net.NetworkInformation { return new LinuxNetworkInterfaceAPI (); } -#if !MONODROID +#if !MOBILE if (Environment.OSVersion.Version >= windowsVer51) return new Win32NetworkInterfaceAPI (); #endif