176 lines
6.1 KiB
C#
176 lines
6.1 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
namespace System.Net.NetworkInformation
|
|
{
|
|
/// <summary>Provides the Media Access Control (MAC) address for a network interface (adapter).</summary>
|
|
// Token: 0x020001AA RID: 426
|
|
public class PhysicalAddress
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> class. </summary>
|
|
/// <param name="address">A <see cref="T:System.Byte" /> array containing the address.</param>
|
|
// Token: 0x06000E26 RID: 3622 RVA: 0x00027F0C File Offset: 0x0002610C
|
|
public PhysicalAddress(byte[] address)
|
|
{
|
|
this.bytes = address;
|
|
}
|
|
|
|
// Token: 0x06000E28 RID: 3624 RVA: 0x00027F30 File Offset: 0x00026130
|
|
internal static PhysicalAddress ParseEthernet(string address)
|
|
{
|
|
if (address == null)
|
|
{
|
|
return PhysicalAddress.None;
|
|
}
|
|
string[] array = address.Split(new char[] { ':' });
|
|
byte[] array2 = new byte[array.Length];
|
|
int num = 0;
|
|
foreach (string text in array)
|
|
{
|
|
array2[num++] = byte.Parse(text, NumberStyles.HexNumber);
|
|
}
|
|
return new PhysicalAddress(array2);
|
|
}
|
|
|
|
/// <summary>Parses the specified <see cref="T:System.String" /> and stores its contents as the address bytes of the <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> returned by this method.</summary>
|
|
/// <returns>A <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> instance with the specified address.</returns>
|
|
/// <param name="address">A <see cref="T:System.String" /> containing the address that will be used to initialize the <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> instance returned by this method.</param>
|
|
/// <exception cref="T:System.FormatException">The <paramref name="address" /> parameter contains an illegal hardware address. This exception also occurs if the <paramref name="address" /> parameter contains a string in the incorrect format.</exception>
|
|
// Token: 0x06000E29 RID: 3625 RVA: 0x00027FA0 File Offset: 0x000261A0
|
|
public static PhysicalAddress Parse(string address)
|
|
{
|
|
if (address == null)
|
|
{
|
|
return PhysicalAddress.None;
|
|
}
|
|
if (address == string.Empty)
|
|
{
|
|
throw new FormatException("An invalid physical address was specified.");
|
|
}
|
|
string[] array = address.Split(new char[] { '-' });
|
|
if (array.Length == 1)
|
|
{
|
|
if (address.Length != 12)
|
|
{
|
|
throw new FormatException("An invalid physical address was specified.");
|
|
}
|
|
array = new string[6];
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i] = address.Substring(i * 2, 2);
|
|
}
|
|
}
|
|
if (array.Length == 6)
|
|
{
|
|
foreach (string text in array)
|
|
{
|
|
if (text.Length > 2)
|
|
{
|
|
throw new FormatException("An invalid physical address was specified.");
|
|
}
|
|
if (text.Length < 2)
|
|
{
|
|
throw new IndexOutOfRangeException("An invalid physical address was specified.");
|
|
}
|
|
}
|
|
byte[] array3 = new byte[6];
|
|
for (int k = 0; k < 6; k++)
|
|
{
|
|
byte b = (byte)(PhysicalAddress.GetValue(array[k][0]) << 4);
|
|
b += PhysicalAddress.GetValue(array[k][1]);
|
|
array3[k] = b;
|
|
}
|
|
return new PhysicalAddress(array3);
|
|
}
|
|
throw new FormatException("An invalid physical address was specified.");
|
|
}
|
|
|
|
// Token: 0x06000E2A RID: 3626 RVA: 0x000280EC File Offset: 0x000262EC
|
|
private static byte GetValue(char c)
|
|
{
|
|
if (c >= '0' && c <= '9')
|
|
{
|
|
return (byte)(c - '0');
|
|
}
|
|
if (c >= 'a' && c <= 'f')
|
|
{
|
|
return (byte)(c - 'a' + '\n');
|
|
}
|
|
if (c >= 'A' && c <= 'F')
|
|
{
|
|
return (byte)(c - 'A' + '\n');
|
|
}
|
|
throw new FormatException("Invalid physical address.");
|
|
}
|
|
|
|
/// <summary>Compares two <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> instances.</summary>
|
|
/// <returns>true if this instance and the specified instance contain the same address; otherwise false.</returns>
|
|
/// <param name="comparand">The <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> to compare to the current instance.</param>
|
|
// Token: 0x06000E2B RID: 3627 RVA: 0x0002814C File Offset: 0x0002634C
|
|
public override bool Equals(object comparand)
|
|
{
|
|
PhysicalAddress physicalAddress = comparand as PhysicalAddress;
|
|
if (physicalAddress == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (this.bytes.Length != physicalAddress.bytes.Length)
|
|
{
|
|
return false;
|
|
}
|
|
for (int i = 0; i < this.bytes.Length; i++)
|
|
{
|
|
if (this.bytes[i] != physicalAddress.bytes[i])
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Returns the hash value of a physical address.</summary>
|
|
/// <returns>An integer hash value.</returns>
|
|
// Token: 0x06000E2C RID: 3628 RVA: 0x000281B0 File Offset: 0x000263B0
|
|
public override int GetHashCode()
|
|
{
|
|
return ((int)this.bytes[5] << 8) ^ (int)this.bytes[4] ^ ((int)this.bytes[3] << 24) ^ ((int)this.bytes[2] << 16) ^ ((int)this.bytes[1] << 8) ^ (int)this.bytes[0];
|
|
}
|
|
|
|
/// <summary>Returns the address of the current instance.</summary>
|
|
/// <returns>A <see cref="T:System.Byte" /> array containing the address.</returns>
|
|
// Token: 0x06000E2D RID: 3629 RVA: 0x000281FC File Offset: 0x000263FC
|
|
public byte[] GetAddressBytes()
|
|
{
|
|
return this.bytes;
|
|
}
|
|
|
|
/// <summary>Returns the <see cref="T:System.String" /> representation of the address of this instance.</summary>
|
|
/// <returns>A <see cref="T:System.String" /> containing the address contained in this instance.</returns>
|
|
// Token: 0x06000E2E RID: 3630 RVA: 0x00028204 File Offset: 0x00026404
|
|
public override string ToString()
|
|
{
|
|
if (this.bytes == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (byte b in this.bytes)
|
|
{
|
|
stringBuilder.AppendFormat("{0:X2}", b);
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
// Token: 0x04000CCF RID: 3279
|
|
private const int numberOfBytes = 6;
|
|
|
|
/// <summary>Returns a new <see cref="T:System.Net.NetworkInformation.PhysicalAddress" /> instance with a zero length address. This field is read-only.</summary>
|
|
// Token: 0x04000CD0 RID: 3280
|
|
public static readonly PhysicalAddress None = new PhysicalAddress(new byte[0]);
|
|
|
|
// Token: 0x04000CD1 RID: 3281
|
|
private byte[] bytes;
|
|
}
|
|
}
|