184 lines
6.3 KiB
C#
184 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.NetworkInformation.MacOsStructs;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Net.NetworkInformation
|
|
{
|
|
// Token: 0x020001A5 RID: 421
|
|
internal class MacOsNetworkInterface : UnixNetworkInterface
|
|
{
|
|
// Token: 0x06000E0A RID: 3594 RVA: 0x000277AC File Offset: 0x000259AC
|
|
private MacOsNetworkInterface(string name)
|
|
: base(name)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000E0B RID: 3595
|
|
[DllImport("libc")]
|
|
private static extern int getifaddrs(out IntPtr ifap);
|
|
|
|
// Token: 0x06000E0C RID: 3596
|
|
[DllImport("libc")]
|
|
private static extern void freeifaddrs(IntPtr ifap);
|
|
|
|
// Token: 0x06000E0D RID: 3597 RVA: 0x000277B8 File Offset: 0x000259B8
|
|
public static NetworkInterface[] ImplGetAllNetworkInterfaces()
|
|
{
|
|
Dictionary<string, MacOsNetworkInterface> dictionary = new Dictionary<string, MacOsNetworkInterface>();
|
|
IntPtr intPtr;
|
|
if (MacOsNetworkInterface.getifaddrs(out intPtr) != 0)
|
|
{
|
|
throw new SystemException("getifaddrs() failed");
|
|
}
|
|
try
|
|
{
|
|
IntPtr intPtr2 = intPtr;
|
|
while (intPtr2 != IntPtr.Zero)
|
|
{
|
|
global::System.Net.NetworkInformation.MacOsStructs.ifaddrs ifaddrs = (global::System.Net.NetworkInformation.MacOsStructs.ifaddrs)Marshal.PtrToStructure(intPtr2, typeof(global::System.Net.NetworkInformation.MacOsStructs.ifaddrs));
|
|
IPAddress ipaddress = IPAddress.None;
|
|
string ifa_name = ifaddrs.ifa_name;
|
|
int num = -1;
|
|
byte[] array = null;
|
|
NetworkInterfaceType networkInterfaceType = NetworkInterfaceType.Unknown;
|
|
if (ifaddrs.ifa_addr != IntPtr.Zero)
|
|
{
|
|
global::System.Net.NetworkInformation.MacOsStructs.sockaddr sockaddr = (global::System.Net.NetworkInformation.MacOsStructs.sockaddr)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(global::System.Net.NetworkInformation.MacOsStructs.sockaddr));
|
|
if (sockaddr.sa_family == 30)
|
|
{
|
|
global::System.Net.NetworkInformation.MacOsStructs.sockaddr_in6 sockaddr_in = (global::System.Net.NetworkInformation.MacOsStructs.sockaddr_in6)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(global::System.Net.NetworkInformation.MacOsStructs.sockaddr_in6));
|
|
ipaddress = new IPAddress(sockaddr_in.sin6_addr.u6_addr8, (long)((ulong)sockaddr_in.sin6_scope_id));
|
|
}
|
|
else if (sockaddr.sa_family == 2)
|
|
{
|
|
ipaddress = new IPAddress((long)((ulong)((global::System.Net.NetworkInformation.MacOsStructs.sockaddr_in)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(global::System.Net.NetworkInformation.MacOsStructs.sockaddr_in))).sin_addr));
|
|
}
|
|
else if (sockaddr.sa_family == 18)
|
|
{
|
|
global::System.Net.NetworkInformation.MacOsStructs.sockaddr_dl sockaddr_dl = (global::System.Net.NetworkInformation.MacOsStructs.sockaddr_dl)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(global::System.Net.NetworkInformation.MacOsStructs.sockaddr_dl));
|
|
array = new byte[(int)sockaddr_dl.sdl_alen];
|
|
Array.Copy(sockaddr_dl.sdl_data, (int)sockaddr_dl.sdl_nlen, array, 0, Math.Min(array.Length, sockaddr_dl.sdl_data.Length - (int)sockaddr_dl.sdl_nlen));
|
|
num = (int)sockaddr_dl.sdl_index;
|
|
int sdl_type = (int)sockaddr_dl.sdl_type;
|
|
if (Enum.IsDefined(typeof(MacOsArpHardware), sdl_type))
|
|
{
|
|
MacOsArpHardware macOsArpHardware = (MacOsArpHardware)sdl_type;
|
|
switch (macOsArpHardware)
|
|
{
|
|
case MacOsArpHardware.PPP:
|
|
networkInterfaceType = NetworkInterfaceType.Ppp;
|
|
break;
|
|
case MacOsArpHardware.LOOPBACK:
|
|
networkInterfaceType = NetworkInterfaceType.Loopback;
|
|
array = null;
|
|
break;
|
|
default:
|
|
if (macOsArpHardware != MacOsArpHardware.ETHER)
|
|
{
|
|
if (macOsArpHardware != MacOsArpHardware.FDDI)
|
|
{
|
|
if (macOsArpHardware == MacOsArpHardware.ATM)
|
|
{
|
|
networkInterfaceType = NetworkInterfaceType.Atm;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
networkInterfaceType = NetworkInterfaceType.Fddi;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
networkInterfaceType = NetworkInterfaceType.Ethernet;
|
|
}
|
|
break;
|
|
case MacOsArpHardware.SLIP:
|
|
networkInterfaceType = NetworkInterfaceType.Slip;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
MacOsNetworkInterface macOsNetworkInterface = null;
|
|
if (!dictionary.TryGetValue(ifa_name, out macOsNetworkInterface))
|
|
{
|
|
macOsNetworkInterface = new MacOsNetworkInterface(ifa_name);
|
|
dictionary.Add(ifa_name, macOsNetworkInterface);
|
|
}
|
|
if (!ipaddress.Equals(IPAddress.None))
|
|
{
|
|
macOsNetworkInterface.AddAddress(ipaddress);
|
|
}
|
|
if (array != null || networkInterfaceType == NetworkInterfaceType.Loopback)
|
|
{
|
|
macOsNetworkInterface.SetLinkLayerInfo(num, array, networkInterfaceType);
|
|
}
|
|
intPtr2 = ifaddrs.ifa_next;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
MacOsNetworkInterface.freeifaddrs(intPtr);
|
|
}
|
|
NetworkInterface[] array2 = new NetworkInterface[dictionary.Count];
|
|
int num2 = 0;
|
|
foreach (NetworkInterface networkInterface in dictionary.Values)
|
|
{
|
|
array2[num2] = networkInterface;
|
|
num2++;
|
|
}
|
|
return array2;
|
|
}
|
|
|
|
// Token: 0x06000E0E RID: 3598 RVA: 0x00027AF4 File Offset: 0x00025CF4
|
|
public override IPInterfaceProperties GetIPProperties()
|
|
{
|
|
if (this.ipproperties == null)
|
|
{
|
|
this.ipproperties = new MacOsIPInterfaceProperties(this, this.addresses);
|
|
}
|
|
return this.ipproperties;
|
|
}
|
|
|
|
// Token: 0x06000E0F RID: 3599 RVA: 0x00027B1C File Offset: 0x00025D1C
|
|
public override IPv4InterfaceStatistics GetIPv4Statistics()
|
|
{
|
|
if (this.ipv4stats == null)
|
|
{
|
|
this.ipv4stats = new MacOsIPv4InterfaceStatistics(this);
|
|
}
|
|
return this.ipv4stats;
|
|
}
|
|
|
|
// Token: 0x17000495 RID: 1173
|
|
// (get) Token: 0x06000E10 RID: 3600 RVA: 0x00027B3C File Offset: 0x00025D3C
|
|
public override OperationalStatus OperationalStatus
|
|
{
|
|
get
|
|
{
|
|
return OperationalStatus.Unknown;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000496 RID: 1174
|
|
// (get) Token: 0x06000E11 RID: 3601 RVA: 0x00027B40 File Offset: 0x00025D40
|
|
public override bool SupportsMulticast
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x04000CA2 RID: 3234
|
|
private const int AF_INET = 2;
|
|
|
|
// Token: 0x04000CA3 RID: 3235
|
|
private const int AF_INET6 = 30;
|
|
|
|
// Token: 0x04000CA4 RID: 3236
|
|
private const int AF_LINK = 18;
|
|
}
|
|
}
|