300 lines
8.7 KiB
C#
300 lines
8.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Net.NetworkInformation
|
|
{
|
|
// Token: 0x020001A4 RID: 420
|
|
internal class LinuxNetworkInterface : UnixNetworkInterface
|
|
{
|
|
// Token: 0x06000DFF RID: 3583 RVA: 0x00027130 File Offset: 0x00025330
|
|
private LinuxNetworkInterface(string name)
|
|
: base(name)
|
|
{
|
|
this.iface_path = "/sys/class/net/" + name + "/";
|
|
this.iface_operstate_path = this.iface_path + "operstate";
|
|
this.iface_flags_path = this.iface_path + "flags";
|
|
}
|
|
|
|
// Token: 0x06000E00 RID: 3584 RVA: 0x00027188 File Offset: 0x00025388
|
|
static LinuxNetworkInterface()
|
|
{
|
|
LinuxNetworkInterface.InitializeInterfaceAddresses();
|
|
}
|
|
|
|
// Token: 0x17000492 RID: 1170
|
|
// (get) Token: 0x06000E01 RID: 3585 RVA: 0x00027190 File Offset: 0x00025390
|
|
internal string IfacePath
|
|
{
|
|
get
|
|
{
|
|
return this.iface_path;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000E02 RID: 3586
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern void InitializeInterfaceAddresses();
|
|
|
|
// Token: 0x06000E03 RID: 3587
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern int GetInterfaceAddresses(out IntPtr ifap);
|
|
|
|
// Token: 0x06000E04 RID: 3588
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern void FreeInterfaceAddresses(IntPtr ifap);
|
|
|
|
// Token: 0x06000E05 RID: 3589 RVA: 0x00027198 File Offset: 0x00025398
|
|
public static NetworkInterface[] ImplGetAllNetworkInterfaces()
|
|
{
|
|
Dictionary<string, LinuxNetworkInterface> dictionary = new Dictionary<string, LinuxNetworkInterface>();
|
|
IntPtr intPtr;
|
|
if (LinuxNetworkInterface.GetInterfaceAddresses(out intPtr) != 0)
|
|
{
|
|
throw new SystemException("getifaddrs() failed");
|
|
}
|
|
try
|
|
{
|
|
IntPtr intPtr2 = intPtr;
|
|
int num = 0;
|
|
while (intPtr2 != IntPtr.Zero)
|
|
{
|
|
ifaddrs ifaddrs = (ifaddrs)Marshal.PtrToStructure(intPtr2, typeof(ifaddrs));
|
|
IPAddress ipaddress = IPAddress.None;
|
|
string text = ifaddrs.ifa_name;
|
|
int num2 = -1;
|
|
byte[] array = null;
|
|
NetworkInterfaceType networkInterfaceType = NetworkInterfaceType.Unknown;
|
|
if (ifaddrs.ifa_addr != IntPtr.Zero)
|
|
{
|
|
sockaddr_in sockaddr_in = (sockaddr_in)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(sockaddr_in));
|
|
if (sockaddr_in.sin_family == 10)
|
|
{
|
|
sockaddr_in6 sockaddr_in2 = (sockaddr_in6)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(sockaddr_in6));
|
|
ipaddress = new IPAddress(sockaddr_in2.sin6_addr.u6_addr8, (long)((ulong)sockaddr_in2.sin6_scope_id));
|
|
}
|
|
else if (sockaddr_in.sin_family == 2)
|
|
{
|
|
ipaddress = new IPAddress((long)((ulong)sockaddr_in.sin_addr));
|
|
}
|
|
else if (sockaddr_in.sin_family == 17)
|
|
{
|
|
sockaddr_ll sockaddr_ll = (sockaddr_ll)Marshal.PtrToStructure(ifaddrs.ifa_addr, typeof(sockaddr_ll));
|
|
if ((int)sockaddr_ll.sll_halen > sockaddr_ll.sll_addr.Length)
|
|
{
|
|
Console.Error.WriteLine("Got a bad hardware address length for an AF_PACKET {0} {1}", sockaddr_ll.sll_halen, sockaddr_ll.sll_addr.Length);
|
|
intPtr2 = ifaddrs.ifa_next;
|
|
continue;
|
|
}
|
|
array = new byte[(int)sockaddr_ll.sll_halen];
|
|
Array.Copy(sockaddr_ll.sll_addr, 0, array, 0, array.Length);
|
|
num2 = sockaddr_ll.sll_ifindex;
|
|
int sll_hatype = (int)sockaddr_ll.sll_hatype;
|
|
if (Enum.IsDefined(typeof(LinuxArpHardware), sll_hatype))
|
|
{
|
|
LinuxArpHardware linuxArpHardware = (LinuxArpHardware)sll_hatype;
|
|
switch (linuxArpHardware)
|
|
{
|
|
case LinuxArpHardware.TUNNEL:
|
|
break;
|
|
case LinuxArpHardware.TUNNEL6:
|
|
break;
|
|
default:
|
|
switch (linuxArpHardware)
|
|
{
|
|
case LinuxArpHardware.ETHER:
|
|
break;
|
|
case LinuxArpHardware.EETHER:
|
|
break;
|
|
default:
|
|
if (linuxArpHardware == LinuxArpHardware.ATM)
|
|
{
|
|
networkInterfaceType = NetworkInterfaceType.Atm;
|
|
goto IL_27D;
|
|
}
|
|
if (linuxArpHardware == LinuxArpHardware.SLIP)
|
|
{
|
|
networkInterfaceType = NetworkInterfaceType.Slip;
|
|
goto IL_27D;
|
|
}
|
|
if (linuxArpHardware != LinuxArpHardware.PPP)
|
|
{
|
|
goto IL_27D;
|
|
}
|
|
networkInterfaceType = NetworkInterfaceType.Ppp;
|
|
goto IL_27D;
|
|
case LinuxArpHardware.PRONET:
|
|
networkInterfaceType = NetworkInterfaceType.TokenRing;
|
|
goto IL_27D;
|
|
}
|
|
networkInterfaceType = NetworkInterfaceType.Ethernet;
|
|
goto IL_27D;
|
|
case LinuxArpHardware.LOOPBACK:
|
|
networkInterfaceType = NetworkInterfaceType.Loopback;
|
|
array = null;
|
|
goto IL_27D;
|
|
case LinuxArpHardware.FDDI:
|
|
networkInterfaceType = NetworkInterfaceType.Fddi;
|
|
goto IL_27D;
|
|
}
|
|
networkInterfaceType = NetworkInterfaceType.Tunnel;
|
|
}
|
|
}
|
|
}
|
|
IL_27D:
|
|
LinuxNetworkInterface linuxNetworkInterface = null;
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
string text2 = "\0";
|
|
int num3;
|
|
num = (num3 = num + 1);
|
|
text = text2 + num3.ToString();
|
|
}
|
|
if (!dictionary.TryGetValue(text, out linuxNetworkInterface))
|
|
{
|
|
linuxNetworkInterface = new LinuxNetworkInterface(text);
|
|
dictionary.Add(text, linuxNetworkInterface);
|
|
}
|
|
if (!ipaddress.Equals(IPAddress.None))
|
|
{
|
|
linuxNetworkInterface.AddAddress(ipaddress);
|
|
}
|
|
if (array != null || networkInterfaceType == NetworkInterfaceType.Loopback)
|
|
{
|
|
if (networkInterfaceType == NetworkInterfaceType.Ethernet && Directory.Exists(linuxNetworkInterface.IfacePath + "wireless"))
|
|
{
|
|
networkInterfaceType = NetworkInterfaceType.Wireless80211;
|
|
}
|
|
linuxNetworkInterface.SetLinkLayerInfo(num2, array, networkInterfaceType);
|
|
}
|
|
intPtr2 = ifaddrs.ifa_next;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
LinuxNetworkInterface.FreeInterfaceAddresses(intPtr);
|
|
}
|
|
NetworkInterface[] array2 = new NetworkInterface[dictionary.Count];
|
|
int num4 = 0;
|
|
foreach (NetworkInterface networkInterface in dictionary.Values)
|
|
{
|
|
array2[num4] = networkInterface;
|
|
num4++;
|
|
}
|
|
return array2;
|
|
}
|
|
|
|
// Token: 0x06000E06 RID: 3590 RVA: 0x0002757C File Offset: 0x0002577C
|
|
public override IPInterfaceProperties GetIPProperties()
|
|
{
|
|
if (this.ipproperties == null)
|
|
{
|
|
this.ipproperties = new LinuxIPInterfaceProperties(this, this.addresses);
|
|
}
|
|
return this.ipproperties;
|
|
}
|
|
|
|
// Token: 0x06000E07 RID: 3591 RVA: 0x000275A4 File Offset: 0x000257A4
|
|
public override IPv4InterfaceStatistics GetIPv4Statistics()
|
|
{
|
|
if (this.ipv4stats == null)
|
|
{
|
|
this.ipv4stats = new LinuxIPv4InterfaceStatistics(this);
|
|
}
|
|
return this.ipv4stats;
|
|
}
|
|
|
|
// Token: 0x17000493 RID: 1171
|
|
// (get) Token: 0x06000E08 RID: 3592 RVA: 0x000275C4 File Offset: 0x000257C4
|
|
public override OperationalStatus OperationalStatus
|
|
{
|
|
get
|
|
{
|
|
if (!Directory.Exists(this.iface_path))
|
|
{
|
|
return OperationalStatus.Unknown;
|
|
}
|
|
try
|
|
{
|
|
string text = NetworkInterface.ReadLine(this.iface_operstate_path);
|
|
string text2 = text;
|
|
switch (text2)
|
|
{
|
|
case "unknown":
|
|
return OperationalStatus.Unknown;
|
|
case "notpresent":
|
|
return OperationalStatus.NotPresent;
|
|
case "down":
|
|
return OperationalStatus.Down;
|
|
case "lowerlayerdown":
|
|
return OperationalStatus.LowerLayerDown;
|
|
case "testing":
|
|
return OperationalStatus.Testing;
|
|
case "dormant":
|
|
return OperationalStatus.Dormant;
|
|
case "up":
|
|
return OperationalStatus.Up;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return OperationalStatus.Unknown;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000494 RID: 1172
|
|
// (get) Token: 0x06000E09 RID: 3593 RVA: 0x00027700 File Offset: 0x00025900
|
|
public override bool SupportsMulticast
|
|
{
|
|
get
|
|
{
|
|
if (!Directory.Exists(this.iface_path))
|
|
{
|
|
return false;
|
|
}
|
|
bool flag;
|
|
try
|
|
{
|
|
string text = NetworkInterface.ReadLine(this.iface_flags_path);
|
|
if (text.Length > 2 && text[0] == '0' && text[1] == 'x')
|
|
{
|
|
text = text.Substring(2);
|
|
}
|
|
ulong num = ulong.Parse(text, NumberStyles.HexNumber);
|
|
flag = (num & 4096UL) == 4096UL;
|
|
}
|
|
catch
|
|
{
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
}
|
|
}
|
|
|
|
// Token: 0x04000C9A RID: 3226
|
|
private const int AF_INET = 2;
|
|
|
|
// Token: 0x04000C9B RID: 3227
|
|
private const int AF_INET6 = 10;
|
|
|
|
// Token: 0x04000C9C RID: 3228
|
|
private const int AF_PACKET = 17;
|
|
|
|
// Token: 0x04000C9D RID: 3229
|
|
private NetworkInterfaceType type;
|
|
|
|
// Token: 0x04000C9E RID: 3230
|
|
private string iface_path;
|
|
|
|
// Token: 0x04000C9F RID: 3231
|
|
private string iface_operstate_path;
|
|
|
|
// Token: 0x04000CA0 RID: 3232
|
|
private string iface_flags_path;
|
|
}
|
|
}
|