You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@ -435,31 +435,34 @@ namespace System.Net.NetworkInformation {
|
||||
}
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
#if WIN_PLATFORM
|
||||
class Win32NetworkInterfaceAPI : NetworkInterfaceFactory
|
||||
{
|
||||
[DllImport ("iphlpapi.dll", SetLastError = true)]
|
||||
static extern int GetAdaptersAddresses (uint family, uint flags, IntPtr reserved, byte [] info, ref int size);
|
||||
private const string IPHLPAPI = "iphlpapi.dll";
|
||||
|
||||
unsafe static Win32_IP_ADAPTER_ADDRESSES [] GetAdaptersAddresses ()
|
||||
[DllImport (IPHLPAPI, SetLastError = true)]
|
||||
static extern int GetAdaptersAddresses (uint family, uint flags, IntPtr reserved, IntPtr info, ref int size);
|
||||
|
||||
[DllImport (IPHLPAPI)]
|
||||
static extern uint GetBestInterfaceEx (byte[] ipAddress, out int index);
|
||||
|
||||
static Win32_IP_ADAPTER_ADDRESSES [] GetAdaptersAddresses ()
|
||||
{
|
||||
byte [] bytes = null;
|
||||
IntPtr ptr = IntPtr.Zero;
|
||||
int len = 0;
|
||||
GetAdaptersAddresses (0, 0, IntPtr.Zero, bytes, ref len);
|
||||
bytes = new byte [len];
|
||||
int ret = GetAdaptersAddresses (0, 0, IntPtr.Zero, bytes, ref len);
|
||||
GetAdaptersAddresses (0, 0, IntPtr.Zero, ptr, ref len);
|
||||
ptr = Marshal.AllocHGlobal(len);
|
||||
int ret = GetAdaptersAddresses (0, 0, IntPtr.Zero, ptr, ref len);
|
||||
if (ret != 0)
|
||||
throw new NetworkInformationException (ret);
|
||||
|
||||
List<Win32_IP_ADAPTER_ADDRESSES> l = new List<Win32_IP_ADAPTER_ADDRESSES> ();
|
||||
fixed (byte* ptr = bytes) {
|
||||
Win32_IP_ADAPTER_ADDRESSES info;
|
||||
for (IntPtr p = (IntPtr) ptr; p != IntPtr.Zero; p = info.Next) {
|
||||
info = new Win32_IP_ADAPTER_ADDRESSES ();
|
||||
Marshal.PtrToStructure (p, info);
|
||||
l.Add (info);
|
||||
}
|
||||
Win32_IP_ADAPTER_ADDRESSES info;
|
||||
for (IntPtr p = ptr; p != IntPtr.Zero; p = info.Next) {
|
||||
info = Marshal.PtrToStructure<Win32_IP_ADAPTER_ADDRESSES> (p);
|
||||
l.Add (info);
|
||||
}
|
||||
|
||||
return l.ToArray ();
|
||||
}
|
||||
|
||||
@ -473,9 +476,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)
|
||||
@ -494,7 +508,6 @@ namespace System.Net.NetworkInformation {
|
||||
#if MONOTOUCH || XAMMAC
|
||||
return new MacOsNetworkInterfaceAPI ();
|
||||
#else
|
||||
Version windowsVer51 = new Version (5, 1);
|
||||
bool runningOnUnix = (Environment.OSVersion.Platform == PlatformID.Unix);
|
||||
|
||||
if (runningOnUnix) {
|
||||
@ -504,7 +517,8 @@ namespace System.Net.NetworkInformation {
|
||||
return new LinuxNetworkInterfaceAPI ();
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
#if WIN_PLATFORM
|
||||
Version windowsVer51 = new Version (5, 1);
|
||||
if (Environment.OSVersion.Version >= windowsVer51)
|
||||
return new Win32NetworkInterfaceAPI ();
|
||||
#endif
|
||||
@ -617,13 +631,13 @@ namespace System.Net.NetworkInformation {
|
||||
|
||||
#if MONODROID
|
||||
[DllImport ("__Internal")]
|
||||
protected static extern int _monodroid_get_android_api_level ();
|
||||
static extern int _monodroid_get_android_api_level ();
|
||||
|
||||
[DllImport ("__Internal")]
|
||||
protected static extern bool _monodroid_get_network_interface_up_state (string ifname, ref bool is_up);
|
||||
static extern bool _monodroid_get_network_interface_up_state (string ifname, ref bool is_up);
|
||||
|
||||
[DllImport ("__Internal")]
|
||||
protected static extern bool _monodroid_get_network_interface_supports_multicast (string ifname, ref bool supports_multicast);
|
||||
static extern bool _monodroid_get_network_interface_supports_multicast (string ifname, ref bool supports_multicast);
|
||||
|
||||
bool android_use_java_api;
|
||||
#endif
|
||||
@ -791,11 +805,11 @@ namespace System.Net.NetworkInformation {
|
||||
}
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
#if WIN_PLATFORM
|
||||
class Win32NetworkInterface2 : NetworkInterface
|
||||
{
|
||||
[DllImport ("iphlpapi.dll", SetLastError = true)]
|
||||
static extern int GetAdaptersInfo (byte [] info, ref int size);
|
||||
static extern int GetAdaptersInfo (IntPtr info, ref int size);
|
||||
|
||||
[DllImport ("iphlpapi.dll", SetLastError = true)]
|
||||
static extern int GetIfEntry (ref Win32_MIB_IFROW row);
|
||||
@ -805,28 +819,25 @@ namespace System.Net.NetworkInformation {
|
||||
foreach (Win32_IP_ADAPTER_INFO info in GetAdaptersInfo ())
|
||||
if (info.Index == index)
|
||||
return info;
|
||||
return null;
|
||||
throw new IndexOutOfRangeException ("No adapter found for index " + index);
|
||||
}
|
||||
|
||||
unsafe static Win32_IP_ADAPTER_INFO [] GetAdaptersInfo ()
|
||||
static Win32_IP_ADAPTER_INFO [] GetAdaptersInfo ()
|
||||
{
|
||||
byte [] bytes = null;
|
||||
int len = 0;
|
||||
GetAdaptersInfo (bytes, ref len);
|
||||
bytes = new byte [len];
|
||||
int ret = GetAdaptersInfo (bytes, ref len);
|
||||
IntPtr ptr = IntPtr.Zero;
|
||||
GetAdaptersInfo (ptr, ref len);
|
||||
ptr = Marshal.AllocHGlobal(len);
|
||||
int ret = GetAdaptersInfo (ptr, ref len);
|
||||
|
||||
if (ret != 0)
|
||||
throw new NetworkInformationException (ret);
|
||||
|
||||
List<Win32_IP_ADAPTER_INFO> l = new List<Win32_IP_ADAPTER_INFO> ();
|
||||
fixed (byte* ptr = bytes) {
|
||||
Win32_IP_ADAPTER_INFO info;
|
||||
for (IntPtr p = (IntPtr) ptr; p != IntPtr.Zero; p = info.Next) {
|
||||
info = new Win32_IP_ADAPTER_INFO ();
|
||||
Marshal.PtrToStructure (p, info);
|
||||
l.Add (info);
|
||||
}
|
||||
Win32_IP_ADAPTER_INFO info;
|
||||
for (IntPtr p = ptr; p != IntPtr.Zero; p = info.Next) {
|
||||
info = Marshal.PtrToStructure<Win32_IP_ADAPTER_INFO> (p);
|
||||
l.Add (info);
|
||||
}
|
||||
return l.ToArray ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user