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 ();
}
}
- [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
#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;
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)
return new LinuxNetworkInterfaceAPI ();
}
-#if !MONODROID
+#if !MOBILE
if (Environment.OSVersion.Version >= windowsVer51)
return new Win32NetworkInterfaceAPI ();
#endif