#if NET_1_1
public IPAddress(byte[] address) : this(address, 0)
- {\r
+ {
}
public IPAddress(byte[] address, long scopeId)
- {\r
- if(address.Length != 16)\r
- throw new ArgumentException("address");\r
-\r
- Buffer.BlockCopy(address, 0, _numbers, 0, 16);\r
+ {
+ if(address.Length != 16)
+ throw new ArgumentException("address");
+
+ Buffer.BlockCopy(address, 0, _numbers, 0, 16);
_family = AddressFamily.InterNetworkV6;
_scopeId = scopeId;
}
internal IPAddress(ushort[] address, long scopeId)
- {\r
- _numbers = address;\r
-\r
- for(int i=0; i<8; i++)\r
- _numbers[i] = (ushort)HostToNetworkOrder((short)_numbers[i]);\r
-\r
+ {
+ _numbers = address;
+
+ for(int i=0; i<8; i++)
+ _numbers[i] = (ushort)HostToNetworkOrder((short)_numbers[i]);
+
_family = AddressFamily.InterNetworkV6;
_scopeId = scopeId;
}
#if NET_1_1
if( (ret = ParseIPV4(ip)) == null)
if( (ret = ParseIPV6(ip)) == null)
- throw new FormatException("An invalid IP address was specified.");\r
+ throw new FormatException("An invalid IP address was specified.");
#else
if( (ret = ParseIPV4(ip)) == null)
- throw new FormatException("An invalid IP address was specified.");\r
+ throw new FormatException("An invalid IP address was specified.");
#endif
return ret;
}
private static IPAddress ParseIPV4 (string ip)
- {\r
+ {
if (ip.Length == 0 || ip [0] == ' ')
return new IPAddress (0);
return null;
// Make the number in network order
- try \r
+ try
{
long a = 0;
byte val = 0;
return (new IPAddress (a));
} catch (Exception) {
return null;
- }\r
+ }
}
#if NET_1_1
private static IPAddress ParseIPV6 (string ip)
- {\r
- try \r
- {\r
- IPv6Address newIPv6Address = IPv6Address.Parse(ip);\r
- return new IPAddress(newIPv6Address.Address, newIPv6Address.ScopeId);\r
- }\r
- catch (Exception) {\r
- return null;\r
- }\r
+ {
+ try
+ {
+ IPv6Address newIPv6Address = IPv6Address.Parse(ip);
+ return new IPAddress(newIPv6Address.Address, newIPv6Address.ScopeId);
+ }
+ catch (Exception) {
+ return null;
+ }
}
[Obsolete]
#endif
- public long Address \r
+ public long Address
{
get {
if(_family != AddressFamily.InterNetwork)
}
#if NET_1_1
- public long ScopeId {\r
- get {\r
+ public long ScopeId {
+ get {
if(_family != AddressFamily.InterNetworkV6)
throw new Exception("The attempted operation is not supported for the type of object referenced");
- return _scopeId;\r
- }\r
- set {\r
+ return _scopeId;
+ }
+ set {
if(_family != AddressFamily.InterNetworkV6)
throw new Exception("The attempted operation is not supported for the type of object referenced");
- _scopeId = value;\r
- }\r
+ _scopeId = value;
+ }
}
- public byte[] GetAddressBytes() \r
- {\r
-\r
+ public byte[] GetAddressBytes()
+ {
+
if(_family == AddressFamily.InterNetworkV6)
- {\r
- byte[] addressBytes = new byte[16];\r
- Buffer.BlockCopy(_numbers, 0, addressBytes, 0, 16);\r
- return addressBytes;\r
+ {
+ byte[] addressBytes = new byte[16];
+ Buffer.BlockCopy(_numbers, 0, addressBytes, 0, 16);
+ return addressBytes;
}
else
- {\r
+ {
return new byte[4] { (byte)(address & 0xFF),
(byte)((address >> 8) & 0xFF),
(byte)((address >> 16) & 0xFF),
}
#endif
- public AddressFamily AddressFamily \r
+ public AddressFamily AddressFamily
{
get {
return _family;
public static bool IsLoopback (IPAddress addr)
{
if(addr._family == AddressFamily.InterNetwork)
- return (addr.address & 0xFF) == 127;\r
- else {\r
+ return (addr.address & 0xFF) == 127;
+ else {
for(int i=0; i<6; i++) {
- if(addr._numbers[i] != 0)\r
- return false;\r
- }\r
-\r
+ if(addr._numbers[i] != 0)
+ return false;
+ }
+
return NetworkToHostOrder((short)addr._numbers[7]) == 1;
}
}
if(AddressFamily == AddressFamily.InterNetwork)
return Address == otherAddr.Address;
else
- {\r
- ushort[] vals = otherAddr._numbers;\r
-\r
- for(int i=0; i<8; i++)\r
- if(_numbers[i] != vals[i])\r
- return false;\r
-\r
- return true;\r
+ {
+ ushort[] vals = otherAddr._numbers;
+
+ for(int i=0; i<8; i++)
+ if(_numbers[i] != vals[i])
+ return false;
+
+ return true;
}
}
return false;
if(_family == AddressFamily.InterNetwork)
return (int)Address;
else
- return Hash (((((int) _numbers[0]) << 16) + _numbers [1]), \r
- ((((int) _numbers [2]) << 16) + _numbers [3]),\r
- ((((int) _numbers [4]) << 16) + _numbers [5]),\r
- ((((int) _numbers [6]) << 16) + _numbers [7]));\r
+ return Hash (((((int) _numbers[0]) << 16) + _numbers [1]),
+ ((((int) _numbers [2]) << 16) + _numbers [3]),
+ ((((int) _numbers [4]) << 16) + _numbers [5]),
+ ((((int) _numbers [6]) << 16) + _numbers [7]));
}
- private static int Hash (int i, int j, int k, int l) \r
- {\r
- return i ^ (j << 13 | j >> 19) ^ (k << 26 | k >> 6) ^ (l << 7 | l >> 25);\r
- }\r
+ 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);
+ }
}
}