using System; using System.Globalization; using System.Net.Sockets; namespace System.Net { /// Provides an Internet Protocol (IP) address. // Token: 0x02000240 RID: 576 [Serializable] public class IPAddress { /// Initializes a new instance of the class with the address specified as an . /// The long value of the IP address. For example, the value 0x2414188f in big-endian format would be the IP address "143.24.20.36". // Token: 0x0600146F RID: 5231 RVA: 0x00040D64 File Offset: 0x0003EF64 public IPAddress(long addr) { this.m_Address = addr; this.m_Family = global::System.Net.Sockets.AddressFamily.InterNetwork; } /// Initializes a new instance of the class with the address specified as a array. /// The byte array value of the IP address. /// /// is null. // Token: 0x06001470 RID: 5232 RVA: 0x00040D7C File Offset: 0x0003EF7C public IPAddress(byte[] address) { if (address == null) { throw new ArgumentNullException("address"); } int num = address.Length; if (num != 16 && num != 4) { throw new ArgumentException("An invalid IP address was specified.", "address"); } if (num == 16) { this.m_Numbers = new ushort[8]; Buffer.BlockCopy(address, 0, this.m_Numbers, 0, 16); this.m_Family = global::System.Net.Sockets.AddressFamily.InterNetworkV6; this.m_ScopeId = 0L; } else { this.m_Address = (long)((ulong)((ulong)address[3] << 24) + (ulong)((long)((long)address[2] << 16)) + (ulong)((long)((long)address[1] << 8)) + (ulong)((long)address[0])); this.m_Family = global::System.Net.Sockets.AddressFamily.InterNetwork; } } /// Initializes a new instance of the class with the address specified as a array and the specified scope identifier. /// The byte array value of the IP address. /// The long value of the scope identifier. /// /// is null. /// /// < 0 or > 0x00000000FFFFFFFF // Token: 0x06001471 RID: 5233 RVA: 0x00040E24 File Offset: 0x0003F024 public IPAddress(byte[] address, long scopeId) { if (address == null) { throw new ArgumentNullException("address"); } if (address.Length != 16) { throw new ArgumentException("An invalid IP address was specified.", "address"); } this.m_Numbers = new ushort[8]; Buffer.BlockCopy(address, 0, this.m_Numbers, 0, 16); this.m_Family = global::System.Net.Sockets.AddressFamily.InterNetworkV6; this.m_ScopeId = scopeId; } // Token: 0x06001472 RID: 5234 RVA: 0x00040E90 File Offset: 0x0003F090 internal IPAddress(ushort[] address, long scopeId) { this.m_Numbers = address; for (int i = 0; i < 8; i++) { this.m_Numbers[i] = (ushort)IPAddress.HostToNetworkOrder((short)this.m_Numbers[i]); } this.m_Family = global::System.Net.Sockets.AddressFamily.InterNetworkV6; this.m_ScopeId = scopeId; } // Token: 0x06001474 RID: 5236 RVA: 0x00040F58 File Offset: 0x0003F158 private static short SwapShort(short number) { return (short)(((number >> 8) & 255) | (((int)number << 8) & 65280)); } // Token: 0x06001475 RID: 5237 RVA: 0x00040F70 File Offset: 0x0003F170 private static int SwapInt(int number) { return ((number >> 24) & 255) | ((number >> 8) & 65280) | ((number << 8) & 16711680) | (number << 24); } // Token: 0x06001476 RID: 5238 RVA: 0x00040F98 File Offset: 0x0003F198 private static long SwapLong(long number) { return ((number >> 56) & 255L) | ((number >> 40) & 65280L) | ((number >> 24) & 16711680L) | ((number >> 8) & (long)((ulong)(-16777216))) | ((number << 8) & 1095216660480L) | ((number << 24) & 280375465082880L) | ((number << 40) & 71776119061217280L) | (number << 56); } /// Converts a short value from host byte order to network byte order. /// A short value, expressed in network byte order. /// The number to convert, expressed in host byte order. // Token: 0x06001477 RID: 5239 RVA: 0x00041004 File Offset: 0x0003F204 public static short HostToNetworkOrder(short host) { if (!BitConverter.IsLittleEndian) { return host; } return IPAddress.SwapShort(host); } /// Converts an integer value from host byte order to network byte order. /// An integer value, expressed in network byte order. /// The number to convert, expressed in host byte order. // Token: 0x06001478 RID: 5240 RVA: 0x00041018 File Offset: 0x0003F218 public static int HostToNetworkOrder(int host) { if (!BitConverter.IsLittleEndian) { return host; } return IPAddress.SwapInt(host); } /// Converts a long value from host byte order to network byte order. /// A long value, expressed in network byte order. /// The number to convert, expressed in host byte order. // Token: 0x06001479 RID: 5241 RVA: 0x0004102C File Offset: 0x0003F22C public static long HostToNetworkOrder(long host) { if (!BitConverter.IsLittleEndian) { return host; } return IPAddress.SwapLong(host); } /// Converts a short value from network byte order to host byte order. /// A short value, expressed in host byte order. /// The number to convert, expressed in network byte order. // Token: 0x0600147A RID: 5242 RVA: 0x00041040 File Offset: 0x0003F240 public static short NetworkToHostOrder(short network) { if (!BitConverter.IsLittleEndian) { return network; } return IPAddress.SwapShort(network); } /// Converts an integer value from network byte order to host byte order. /// An integer value, expressed in host byte order. /// The number to convert, expressed in network byte order. // Token: 0x0600147B RID: 5243 RVA: 0x00041054 File Offset: 0x0003F254 public static int NetworkToHostOrder(int network) { if (!BitConverter.IsLittleEndian) { return network; } return IPAddress.SwapInt(network); } /// Converts a long value from network byte order to host byte order. /// A long value, expressed in host byte order. /// The number to convert, expressed in network byte order. // Token: 0x0600147C RID: 5244 RVA: 0x00041068 File Offset: 0x0003F268 public static long NetworkToHostOrder(long network) { if (!BitConverter.IsLittleEndian) { return network; } return IPAddress.SwapLong(network); } /// Converts an IP address string to an instance. /// An instance. /// A string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6. /// /// is null. /// /// is not a valid IP address. // Token: 0x0600147D RID: 5245 RVA: 0x0004107C File Offset: 0x0003F27C public static IPAddress Parse(string ipString) { IPAddress ipaddress; if (IPAddress.TryParse(ipString, out ipaddress)) { return ipaddress; } throw new FormatException("An invalid IP address was specified."); } /// Determines whether a string is a valid IP address. /// true if is a valid IP address; otherwise, false. /// The string to validate. /// The version of the string. // Token: 0x0600147E RID: 5246 RVA: 0x000410A4 File Offset: 0x0003F2A4 public static bool TryParse(string ipString, out IPAddress address) { if (ipString == null) { throw new ArgumentNullException("ipString"); } IPAddress ipaddress; address = (ipaddress = IPAddress.ParseIPV4(ipString)); if (ipaddress == null) { address = (ipaddress = IPAddress.ParseIPV6(ipString)); if (ipaddress == null) { return false; } } return true; } // Token: 0x0600147F RID: 5247 RVA: 0x000410E8 File Offset: 0x0003F2E8 private static IPAddress ParseIPV4(string ip) { int num = ip.IndexOf(' '); if (num != -1) { string[] array = ip.Substring(num + 1).Split(new char[] { '.' }); if (array.Length > 0) { string text = array[array.Length - 1]; if (text.Length == 0) { return null; } foreach (char c in text.ToCharArray()) { if (!global::System.Uri.IsHexDigit(c)) { return null; } } } ip = ip.Substring(0, num); } if (ip.Length == 0 || ip[ip.Length - 1] == '.') { return null; } string[] array3 = ip.Split(new char[] { '.' }); if (array3.Length > 4) { return null; } IPAddress ipaddress; try { long num2 = 0L; long num3 = 0L; for (int j = 0; j < array3.Length; j++) { string text2 = array3[j]; if (3 <= text2.Length && text2.Length <= 4 && text2[0] == '0' && (text2[1] == 'x' || text2[1] == 'X')) { if (text2.Length == 3) { num3 = (long)((byte)global::System.Uri.FromHex(text2[2])); } else { num3 = (long)((byte)((global::System.Uri.FromHex(text2[2]) << 4) | global::System.Uri.FromHex(text2[3]))); } } else { if (text2.Length == 0) { return null; } if (text2[0] == '0') { num3 = 0L; for (int k = 1; k < text2.Length; k++) { if ('0' > text2[k] || text2[k] > '7') { return null; } num3 = (num3 << 3) + (long)text2[k] - 48L; } } else if (!long.TryParse(text2, NumberStyles.None, null, out num3)) { return null; } } if (j == array3.Length - 1) { j = 3; } else if (num3 > 255L) { return null; } int num4 = 0; while (num3 > 0L) { num2 |= (num3 & 255L) << (j - num4 << 3); num4++; num3 /= 256L; } } ipaddress = new IPAddress(num2); } catch (Exception) { ipaddress = null; } return ipaddress; } // Token: 0x06001480 RID: 5248 RVA: 0x000413C0 File Offset: 0x0003F5C0 private static IPAddress ParseIPV6(string ip) { IPv6Address pv6Address; if (IPv6Address.TryParse(ip, out pv6Address)) { return new IPAddress(pv6Address.Address, pv6Address.ScopeId); } return null; } /// An Internet Protocol (IP) address. /// The long value of the IP address. // Token: 0x170006B6 RID: 1718 // (get) Token: 0x06001481 RID: 5249 RVA: 0x000413F0 File Offset: 0x0003F5F0 // (set) Token: 0x06001482 RID: 5250 RVA: 0x00041410 File Offset: 0x0003F610 [Obsolete("This property is obsolete. Use GetAddressBytes.")] public long Address { get { if (this.m_Family != global::System.Net.Sockets.AddressFamily.InterNetwork) { throw new Exception("The attempted operation is not supported for the type of object referenced"); } return this.m_Address; } set { if (this.m_Family != global::System.Net.Sockets.AddressFamily.InterNetwork) { throw new Exception("The attempted operation is not supported for the type of object referenced"); } this.m_Address = value; } } // Token: 0x170006B7 RID: 1719 // (get) Token: 0x06001483 RID: 5251 RVA: 0x00041430 File Offset: 0x0003F630 internal long InternalIPv4Address { get { return this.m_Address; } } /// Gets whether the address is an IPv6 link local address. /// true if the IP address is an IPv6 link local address; otherwise, false. // Token: 0x170006B8 RID: 1720 // (get) Token: 0x06001484 RID: 5252 RVA: 0x00041438 File Offset: 0x0003F638 public bool IsIPv6LinkLocal { get { if (this.m_Family == global::System.Net.Sockets.AddressFamily.InterNetwork) { return false; } int num = (int)IPAddress.NetworkToHostOrder((short)this.m_Numbers[0]) & 65520; return 65152 <= num && num < 65216; } } /// Gets whether the address is an IPv6 site local address. /// true if the IP address is an IPv6 site local address; otherwise, false. // Token: 0x170006B9 RID: 1721 // (get) Token: 0x06001485 RID: 5253 RVA: 0x00041480 File Offset: 0x0003F680 public bool IsIPv6SiteLocal { get { if (this.m_Family == global::System.Net.Sockets.AddressFamily.InterNetwork) { return false; } int num = (int)IPAddress.NetworkToHostOrder((short)this.m_Numbers[0]) & 65520; return 65216 <= num && num < 65280; } } /// Gets whether the address is an IPv6 multicast global address. /// true if the IP address is an IPv6 multicast global address; otherwise, false. // Token: 0x170006BA RID: 1722 // (get) Token: 0x06001486 RID: 5254 RVA: 0x000414C8 File Offset: 0x0003F6C8 public bool IsIPv6Multicast { get { return this.m_Family != global::System.Net.Sockets.AddressFamily.InterNetwork && ((ushort)IPAddress.NetworkToHostOrder((short)this.m_Numbers[0]) & 65280) == 65280; } } /// Gets or sets the IPv6 address scope identifier. /// A long integer that specifies the scope of the address. /// AddressFamily = InterNetwork. /// /// < 0- or - > 0x00000000FFFFFFFF // Token: 0x170006BB RID: 1723 // (get) Token: 0x06001487 RID: 5255 RVA: 0x000414F8 File Offset: 0x0003F6F8 // (set) Token: 0x06001488 RID: 5256 RVA: 0x00041518 File Offset: 0x0003F718 public long ScopeId { get { if (this.m_Family != global::System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new Exception("The attempted operation is not supported for the type of object referenced"); } return this.m_ScopeId; } set { if (this.m_Family != global::System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new Exception("The attempted operation is not supported for the type of object referenced"); } this.m_ScopeId = value; } } /// Provides a copy of the as an array of bytes. /// A array. // Token: 0x06001489 RID: 5257 RVA: 0x0004153C File Offset: 0x0003F73C public byte[] GetAddressBytes() { if (this.m_Family == global::System.Net.Sockets.AddressFamily.InterNetworkV6) { byte[] array = new byte[16]; Buffer.BlockCopy(this.m_Numbers, 0, array, 0, 16); return array; } return new byte[] { (byte)(this.m_Address & 255L), (byte)((this.m_Address >> 8) & 255L), (byte)((this.m_Address >> 16) & 255L), (byte)(this.m_Address >> 24) }; } /// Gets the address family of the IP address. /// Returns for IPv4 or for IPv6. // Token: 0x170006BC RID: 1724 // (get) Token: 0x0600148A RID: 5258 RVA: 0x000415BC File Offset: 0x0003F7BC public global::System.Net.Sockets.AddressFamily AddressFamily { get { return this.m_Family; } } /// Indicates whether the specified IP address is the loopback address. /// true if is the loopback address; otherwise, false. /// An IP address. // Token: 0x0600148B RID: 5259 RVA: 0x000415C4 File Offset: 0x0003F7C4 public static bool IsLoopback(IPAddress addr) { if (addr.m_Family == global::System.Net.Sockets.AddressFamily.InterNetwork) { return (addr.m_Address & 255L) == 127L; } for (int i = 0; i < 6; i++) { if (addr.m_Numbers[i] != 0) { return false; } } return IPAddress.NetworkToHostOrder((short)addr.m_Numbers[7]) == 1; } /// Converts an Internet address to its standard notation. /// A string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation. /// /// /// // Token: 0x0600148C RID: 5260 RVA: 0x00041624 File Offset: 0x0003F824 public override string ToString() { if (this.m_Family == global::System.Net.Sockets.AddressFamily.InterNetwork) { return IPAddress.ToString(this.m_Address); } ushort[] array = this.m_Numbers.Clone() as ushort[]; for (int i = 0; i < array.Length; i++) { array[i] = (ushort)IPAddress.NetworkToHostOrder((short)array[i]); } return new IPv6Address(array) { ScopeId = this.ScopeId }.ToString(); } // Token: 0x0600148D RID: 5261 RVA: 0x00041694 File Offset: 0x0003F894 private static string ToString(long addr) { return string.Concat(new string[] { (addr & 255L).ToString(), ".", ((addr >> 8) & 255L).ToString(), ".", ((addr >> 16) & 255L).ToString(), ".", ((addr >> 24) & 255L).ToString() }); } /// Compares two IP addresses. /// true if the two addresses are equal; otherwise, false. /// An instance to compare to the current instance. // Token: 0x0600148E RID: 5262 RVA: 0x00041718 File Offset: 0x0003F918 public override bool Equals(object other) { IPAddress ipaddress = other as IPAddress; if (ipaddress == null) { return false; } if (this.AddressFamily != ipaddress.AddressFamily) { return false; } if (this.AddressFamily == global::System.Net.Sockets.AddressFamily.InterNetwork) { return this.m_Address == ipaddress.m_Address; } ushort[] numbers = ipaddress.m_Numbers; for (int i = 0; i < 8; i++) { if (this.m_Numbers[i] != numbers[i]) { return false; } } return true; } /// Returns a hash value for an IP address. /// An integer hash value. /// /// /// // Token: 0x0600148F RID: 5263 RVA: 0x00041790 File Offset: 0x0003F990 public override int GetHashCode() { if (this.m_Family == global::System.Net.Sockets.AddressFamily.InterNetwork) { return (int)this.m_Address; } return IPAddress.Hash(((int)this.m_Numbers[0] << 16) + (int)this.m_Numbers[1], ((int)this.m_Numbers[2] << 16) + (int)this.m_Numbers[3], ((int)this.m_Numbers[4] << 16) + (int)this.m_Numbers[5], ((int)this.m_Numbers[6] << 16) + (int)this.m_Numbers[7]); } // Token: 0x06001490 RID: 5264 RVA: 0x00041808 File Offset: 0x0003FA08 private static int Hash(int i, int j, int k, int l) { return i ^ ((j << 13) | (j >> 19)) ^ ((k << 26) | (k >> 6)) ^ ((l << 7) | (l >> 25)); } // Token: 0x04001169 RID: 4457 private long m_Address; // Token: 0x0400116A RID: 4458 private global::System.Net.Sockets.AddressFamily m_Family; // Token: 0x0400116B RID: 4459 private ushort[] m_Numbers; // Token: 0x0400116C RID: 4460 private long m_ScopeId; /// Provides an IP address that indicates that the server must listen for client activity on all network interfaces. This field is read-only. // Token: 0x0400116D RID: 4461 public static readonly IPAddress Any = new IPAddress(0L); /// Provides the IP broadcast address. This field is read-only. // Token: 0x0400116E RID: 4462 public static readonly IPAddress Broadcast = IPAddress.Parse("255.255.255.255"); /// Provides the IP loopback address. This field is read-only. // Token: 0x0400116F RID: 4463 public static readonly IPAddress Loopback = IPAddress.Parse("127.0.0.1"); /// Provides an IP address that indicates that no network interface should be used. This field is read-only. // Token: 0x04001170 RID: 4464 public static readonly IPAddress None = IPAddress.Parse("255.255.255.255"); /// The method uses the field to indicate that a must listen for client activity on all network interfaces. // Token: 0x04001171 RID: 4465 public static readonly IPAddress IPv6Any = IPAddress.ParseIPV6("::"); /// Provides the IP loopback address. This property is read-only. // Token: 0x04001172 RID: 4466 public static readonly IPAddress IPv6Loopback = IPAddress.ParseIPV6("::1"); /// Provides an IP address that indicates that no network interface should be used. This property is read-only. // Token: 0x04001173 RID: 4467 public static readonly IPAddress IPv6None = IPAddress.ParseIPV6("::"); // Token: 0x04001174 RID: 4468 private int m_HashCode; } }