358 lines
11 KiB
C#
358 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace System.Net.NetworkInformation
|
|
{
|
|
// Token: 0x02000163 RID: 355
|
|
internal class MibIPGlobalProperties : IPGlobalProperties
|
|
{
|
|
// Token: 0x06000BEF RID: 3055 RVA: 0x0002441C File Offset: 0x0002261C
|
|
public MibIPGlobalProperties(string procDir)
|
|
{
|
|
this.StatisticsFile = Path.Combine(procDir, "net/snmp");
|
|
this.StatisticsFileIPv6 = Path.Combine(procDir, "net/snmp6");
|
|
this.TcpFile = Path.Combine(procDir, "net/tcp");
|
|
this.Tcp6File = Path.Combine(procDir, "net/tcp6");
|
|
this.UdpFile = Path.Combine(procDir, "net/udp");
|
|
this.Udp6File = Path.Combine(procDir, "net/udp6");
|
|
}
|
|
|
|
// Token: 0x06000BF1 RID: 3057
|
|
[DllImport("libc")]
|
|
private static extern int gethostname([MarshalAs(UnmanagedType.LPArray, SizeConst = 0, SizeParamIndex = 1)] byte[] name, int len);
|
|
|
|
// Token: 0x06000BF2 RID: 3058
|
|
[DllImport("libc")]
|
|
private static extern int getdomainname([MarshalAs(UnmanagedType.LPArray, SizeConst = 0, SizeParamIndex = 1)] byte[] name, int len);
|
|
|
|
// Token: 0x06000BF3 RID: 3059 RVA: 0x000244B0 File Offset: 0x000226B0
|
|
private global::System.Collections.Specialized.StringDictionary GetProperties4(string item)
|
|
{
|
|
string statisticsFile = this.StatisticsFile;
|
|
string text = item + ": ";
|
|
global::System.Collections.Specialized.StringDictionary stringDictionary2;
|
|
using (StreamReader streamReader = new StreamReader(statisticsFile, Encoding.ASCII))
|
|
{
|
|
string[] array = null;
|
|
string[] array2 = null;
|
|
string text2 = string.Empty;
|
|
for (;;)
|
|
{
|
|
text2 = streamReader.ReadLine();
|
|
if (!string.IsNullOrEmpty(text2))
|
|
{
|
|
if (text2.Length > text.Length && string.CompareOrdinal(text2, 0, text, 0, text.Length) == 0)
|
|
{
|
|
if (array != null)
|
|
{
|
|
break;
|
|
}
|
|
array = text2.Substring(text.Length).Split(new char[] { ' ' });
|
|
}
|
|
}
|
|
if (streamReader.EndOfStream)
|
|
{
|
|
goto IL_E2;
|
|
}
|
|
}
|
|
if (array2 != null)
|
|
{
|
|
throw this.CreateException(statisticsFile, string.Format("Found duplicate line for values for the same item '{0}'", item));
|
|
}
|
|
array2 = text2.Substring(text.Length).Split(new char[] { ' ' });
|
|
IL_E2:
|
|
if (array2 == null)
|
|
{
|
|
throw this.CreateException(statisticsFile, string.Format("No corresponding line was not found for '{0}'", item));
|
|
}
|
|
if (array.Length != array2.Length)
|
|
{
|
|
throw this.CreateException(statisticsFile, string.Format("The counts in the header line and the value line do not match for '{0}'", item));
|
|
}
|
|
global::System.Collections.Specialized.StringDictionary stringDictionary = new global::System.Collections.Specialized.StringDictionary();
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
stringDictionary[array[i]] = array2[i];
|
|
}
|
|
stringDictionary2 = stringDictionary;
|
|
}
|
|
return stringDictionary2;
|
|
}
|
|
|
|
// Token: 0x06000BF4 RID: 3060 RVA: 0x00024640 File Offset: 0x00022840
|
|
private global::System.Collections.Specialized.StringDictionary GetProperties6(string item)
|
|
{
|
|
if (!File.Exists(this.StatisticsFileIPv6))
|
|
{
|
|
throw new NetworkInformationException();
|
|
}
|
|
string statisticsFileIPv = this.StatisticsFileIPv6;
|
|
global::System.Collections.Specialized.StringDictionary stringDictionary2;
|
|
using (StreamReader streamReader = new StreamReader(statisticsFileIPv, Encoding.ASCII))
|
|
{
|
|
global::System.Collections.Specialized.StringDictionary stringDictionary = new global::System.Collections.Specialized.StringDictionary();
|
|
string text = string.Empty;
|
|
for (;;)
|
|
{
|
|
text = streamReader.ReadLine();
|
|
if (!string.IsNullOrEmpty(text))
|
|
{
|
|
if (text.Length > item.Length && string.CompareOrdinal(text, 0, item, 0, item.Length) == 0)
|
|
{
|
|
int num = text.IndexOfAny(MibIPGlobalProperties.wsChars, item.Length);
|
|
if (num < 0)
|
|
{
|
|
break;
|
|
}
|
|
stringDictionary[text.Substring(item.Length, num - item.Length)] = text.Substring(num + 1).Trim(MibIPGlobalProperties.wsChars);
|
|
}
|
|
}
|
|
if (streamReader.EndOfStream)
|
|
{
|
|
goto Block_7;
|
|
}
|
|
}
|
|
throw this.CreateException(statisticsFileIPv, null);
|
|
Block_7:
|
|
stringDictionary2 = stringDictionary;
|
|
}
|
|
return stringDictionary2;
|
|
}
|
|
|
|
// Token: 0x06000BF5 RID: 3061 RVA: 0x00024764 File Offset: 0x00022964
|
|
private Exception CreateException(string file, string msg)
|
|
{
|
|
return new InvalidOperationException(string.Format("Unsupported (unexpected) '{0}' file format. ", file) + msg);
|
|
}
|
|
|
|
// Token: 0x06000BF6 RID: 3062 RVA: 0x0002477C File Offset: 0x0002297C
|
|
private IPEndPoint[] GetLocalAddresses(List<string[]> list)
|
|
{
|
|
IPEndPoint[] array = new IPEndPoint[list.Count];
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i] = this.ToEndpoint(list[i][1]);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x06000BF7 RID: 3063 RVA: 0x000247BC File Offset: 0x000229BC
|
|
private IPEndPoint ToEndpoint(string s)
|
|
{
|
|
int num = s.IndexOf(':');
|
|
int num2 = int.Parse(s.Substring(num + 1), NumberStyles.HexNumber);
|
|
if (s.Length == 13)
|
|
{
|
|
return new IPEndPoint(long.Parse(s.Substring(0, num), NumberStyles.HexNumber), num2);
|
|
}
|
|
byte[] array = new byte[16];
|
|
int num3 = 0;
|
|
while (num3 << 1 < num)
|
|
{
|
|
array[num3] = byte.Parse(s.Substring(num3 << 1, 2), NumberStyles.HexNumber);
|
|
num3++;
|
|
}
|
|
return new IPEndPoint(new IPAddress(array), num2);
|
|
}
|
|
|
|
// Token: 0x06000BF8 RID: 3064 RVA: 0x0002484C File Offset: 0x00022A4C
|
|
private void GetRows(string file, List<string[]> list)
|
|
{
|
|
if (!File.Exists(file))
|
|
{
|
|
return;
|
|
}
|
|
using (StreamReader streamReader = new StreamReader(file, Encoding.ASCII))
|
|
{
|
|
streamReader.ReadLine();
|
|
while (!streamReader.EndOfStream)
|
|
{
|
|
string[] array = streamReader.ReadLine().Split(MibIPGlobalProperties.wsChars, StringSplitOptions.RemoveEmptyEntries);
|
|
if (array.Length < 4)
|
|
{
|
|
throw this.CreateException(file, null);
|
|
}
|
|
list.Add(array);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000BF9 RID: 3065 RVA: 0x000248E4 File Offset: 0x00022AE4
|
|
public override TcpConnectionInformation[] GetActiveTcpConnections()
|
|
{
|
|
List<string[]> list = new List<string[]>();
|
|
this.GetRows(this.TcpFile, list);
|
|
this.GetRows(this.Tcp6File, list);
|
|
TcpConnectionInformation[] array = new TcpConnectionInformation[list.Count];
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
IPEndPoint ipendPoint = this.ToEndpoint(list[i][1]);
|
|
IPEndPoint ipendPoint2 = this.ToEndpoint(list[i][2]);
|
|
TcpState tcpState = (TcpState)int.Parse(list[i][3], NumberStyles.HexNumber);
|
|
array[i] = new TcpConnectionInformationImpl(ipendPoint, ipendPoint2, tcpState);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x06000BFA RID: 3066 RVA: 0x00024978 File Offset: 0x00022B78
|
|
public override IPEndPoint[] GetActiveTcpListeners()
|
|
{
|
|
List<string[]> list = new List<string[]>();
|
|
this.GetRows(this.TcpFile, list);
|
|
this.GetRows(this.Tcp6File, list);
|
|
return this.GetLocalAddresses(list);
|
|
}
|
|
|
|
// Token: 0x06000BFB RID: 3067 RVA: 0x000249AC File Offset: 0x00022BAC
|
|
public override IPEndPoint[] GetActiveUdpListeners()
|
|
{
|
|
List<string[]> list = new List<string[]>();
|
|
this.GetRows(this.UdpFile, list);
|
|
this.GetRows(this.Udp6File, list);
|
|
return this.GetLocalAddresses(list);
|
|
}
|
|
|
|
// Token: 0x06000BFC RID: 3068 RVA: 0x000249E0 File Offset: 0x00022BE0
|
|
public override IcmpV4Statistics GetIcmpV4Statistics()
|
|
{
|
|
return new MibIcmpV4Statistics(this.GetProperties4("Icmp"));
|
|
}
|
|
|
|
// Token: 0x06000BFD RID: 3069 RVA: 0x000249F4 File Offset: 0x00022BF4
|
|
public override IcmpV6Statistics GetIcmpV6Statistics()
|
|
{
|
|
return new MibIcmpV6Statistics(this.GetProperties6("Icmp6"));
|
|
}
|
|
|
|
// Token: 0x06000BFE RID: 3070 RVA: 0x00024A08 File Offset: 0x00022C08
|
|
public override IPGlobalStatistics GetIPv4GlobalStatistics()
|
|
{
|
|
return new MibIPGlobalStatistics(this.GetProperties4("Ip"));
|
|
}
|
|
|
|
// Token: 0x06000BFF RID: 3071 RVA: 0x00024A1C File Offset: 0x00022C1C
|
|
public override IPGlobalStatistics GetIPv6GlobalStatistics()
|
|
{
|
|
return new MibIPGlobalStatistics(this.GetProperties6("Ip6"));
|
|
}
|
|
|
|
// Token: 0x06000C00 RID: 3072 RVA: 0x00024A30 File Offset: 0x00022C30
|
|
public override TcpStatistics GetTcpIPv4Statistics()
|
|
{
|
|
return new MibTcpStatistics(this.GetProperties4("Tcp"));
|
|
}
|
|
|
|
// Token: 0x06000C01 RID: 3073 RVA: 0x00024A44 File Offset: 0x00022C44
|
|
public override TcpStatistics GetTcpIPv6Statistics()
|
|
{
|
|
return new MibTcpStatistics(this.GetProperties4("Tcp"));
|
|
}
|
|
|
|
// Token: 0x06000C02 RID: 3074 RVA: 0x00024A58 File Offset: 0x00022C58
|
|
public override UdpStatistics GetUdpIPv4Statistics()
|
|
{
|
|
return new MibUdpStatistics(this.GetProperties4("Udp"));
|
|
}
|
|
|
|
// Token: 0x06000C03 RID: 3075 RVA: 0x00024A6C File Offset: 0x00022C6C
|
|
public override UdpStatistics GetUdpIPv6Statistics()
|
|
{
|
|
return new MibUdpStatistics(this.GetProperties6("Udp6"));
|
|
}
|
|
|
|
// Token: 0x17000303 RID: 771
|
|
// (get) Token: 0x06000C04 RID: 3076 RVA: 0x00024A80 File Offset: 0x00022C80
|
|
public override string DhcpScopeName
|
|
{
|
|
get
|
|
{
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000304 RID: 772
|
|
// (get) Token: 0x06000C05 RID: 3077 RVA: 0x00024A88 File Offset: 0x00022C88
|
|
public override string DomainName
|
|
{
|
|
get
|
|
{
|
|
byte[] array = new byte[256];
|
|
if (MibIPGlobalProperties.getdomainname(array, 256) != 0)
|
|
{
|
|
throw new NetworkInformationException();
|
|
}
|
|
int num = Array.IndexOf<byte>(array, 0);
|
|
return Encoding.ASCII.GetString(array, 0, (num >= 0) ? num : 256);
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000305 RID: 773
|
|
// (get) Token: 0x06000C06 RID: 3078 RVA: 0x00024ADC File Offset: 0x00022CDC
|
|
public override string HostName
|
|
{
|
|
get
|
|
{
|
|
byte[] array = new byte[256];
|
|
if (MibIPGlobalProperties.gethostname(array, 256) != 0)
|
|
{
|
|
throw new NetworkInformationException();
|
|
}
|
|
int num = Array.IndexOf<byte>(array, 0);
|
|
return Encoding.ASCII.GetString(array, 0, (num >= 0) ? num : 256);
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000306 RID: 774
|
|
// (get) Token: 0x06000C07 RID: 3079 RVA: 0x00024B30 File Offset: 0x00022D30
|
|
public override bool IsWinsProxy
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000307 RID: 775
|
|
// (get) Token: 0x06000C08 RID: 3080 RVA: 0x00024B34 File Offset: 0x00022D34
|
|
public override NetBiosNodeType NodeType
|
|
{
|
|
get
|
|
{
|
|
return NetBiosNodeType.Unknown;
|
|
}
|
|
}
|
|
|
|
// Token: 0x04000BA6 RID: 2982
|
|
public const string ProcDir = "/proc";
|
|
|
|
// Token: 0x04000BA7 RID: 2983
|
|
public const string CompatProcDir = "/usr/compat/linux/proc";
|
|
|
|
// Token: 0x04000BA8 RID: 2984
|
|
public readonly string StatisticsFile;
|
|
|
|
// Token: 0x04000BA9 RID: 2985
|
|
public readonly string StatisticsFileIPv6;
|
|
|
|
// Token: 0x04000BAA RID: 2986
|
|
public readonly string TcpFile;
|
|
|
|
// Token: 0x04000BAB RID: 2987
|
|
public readonly string Tcp6File;
|
|
|
|
// Token: 0x04000BAC RID: 2988
|
|
public readonly string UdpFile;
|
|
|
|
// Token: 0x04000BAD RID: 2989
|
|
public readonly string Udp6File;
|
|
|
|
// Token: 0x04000BAE RID: 2990
|
|
private static readonly char[] wsChars = new char[] { ' ', '\t' };
|
|
}
|
|
}
|