You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@ -250,6 +250,10 @@ namespace System.Net.NetworkInformation {
|
||||
|
||||
class LinuxNetworkInterfaceAPI : UnixNetworkInterfaceAPI
|
||||
{
|
||||
const int AF_INET = 2;
|
||||
const int AF_INET6 = 10;
|
||||
const int AF_PACKET = 17;
|
||||
|
||||
static void FreeInterfaceAddresses (IntPtr ifap)
|
||||
{
|
||||
#if MONODROID
|
||||
@ -270,9 +274,6 @@ namespace System.Net.NetworkInformation {
|
||||
|
||||
public override NetworkInterface [] GetAllNetworkInterfaces ()
|
||||
{
|
||||
const int AF_INET = 2;
|
||||
const int AF_INET6 = 10;
|
||||
const int AF_PACKET = 17;
|
||||
|
||||
var interfaces = new Dictionary <string, LinuxNetworkInterface> ();
|
||||
IntPtr ifap;
|
||||
@ -406,10 +407,47 @@ namespace System.Net.NetworkInformation {
|
||||
|
||||
public override IPAddress GetNetMask (IPAddress address)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
foreach (ifaddrs networkInteface in GetNetworkInterfaces()) {
|
||||
if (networkInteface.ifa_addr == IntPtr.Zero)
|
||||
continue;
|
||||
|
||||
var sockaddr = (sockaddr_in)Marshal.PtrToStructure(networkInteface.ifa_addr, typeof(sockaddr_in));
|
||||
|
||||
if (sockaddr.sin_family != AF_INET)
|
||||
continue;
|
||||
|
||||
if (!address.Equals(new IPAddress(sockaddr.sin_addr)))
|
||||
continue;
|
||||
|
||||
var netmask = (sockaddr_in)Marshal.PtrToStructure(networkInteface.ifa_netmask, typeof(sockaddr_in));
|
||||
return new IPAddress(netmask.sin_addr);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IEnumerable<ifaddrs> GetNetworkInterfaces()
|
||||
{
|
||||
IntPtr ifap = IntPtr.Zero;
|
||||
|
||||
try {
|
||||
if (GetInterfaceAddresses(out ifap) != 0)
|
||||
yield break;
|
||||
|
||||
var next = ifap;
|
||||
while (next != IntPtr.Zero) {
|
||||
var addr = (ifaddrs)Marshal.PtrToStructure(next, typeof(ifaddrs));
|
||||
yield return addr;
|
||||
next = addr.ifa_next;
|
||||
}
|
||||
} finally {
|
||||
if (ifap != IntPtr.Zero)
|
||||
FreeInterfaceAddresses(ifap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
class Win32NetworkInterfaceAPI : NetworkInterfaceFactory
|
||||
{
|
||||
[DllImport ("iphlpapi.dll", SetLastError = true)]
|
||||
@ -457,6 +495,7 @@ namespace System.Net.NetworkInformation {
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public abstract NetworkInterface [] GetAllNetworkInterfaces ();
|
||||
public abstract int GetLoopbackInterfaceIndex ();
|
||||
@ -464,7 +503,7 @@ namespace System.Net.NetworkInformation {
|
||||
|
||||
public static NetworkInterfaceFactory Create ()
|
||||
{
|
||||
#if MONOTOUCH
|
||||
#if MONOTOUCH || XAMMAC
|
||||
return new MacOsNetworkInterfaceAPI ();
|
||||
#else
|
||||
Version windowsVer51 = new Version (5, 1);
|
||||
@ -477,8 +516,10 @@ namespace System.Net.NetworkInformation {
|
||||
return new LinuxNetworkInterfaceAPI ();
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
if (Environment.OSVersion.Version >= windowsVer51)
|
||||
return new Win32NetworkInterfaceAPI ();
|
||||
#endif
|
||||
|
||||
throw new NotImplementedException ();
|
||||
#endif
|
||||
@ -718,6 +759,7 @@ namespace System.Net.NetworkInformation {
|
||||
}
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
class Win32NetworkInterface2 : NetworkInterface
|
||||
{
|
||||
[DllImport ("iphlpapi.dll", SetLastError = true)]
|
||||
@ -830,5 +872,6 @@ namespace System.Net.NetworkInformation {
|
||||
get { return !addr.NoMulticast; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user