9 [global::__DynamicallyInvokable]
13 [global::__DynamicallyInvokable]
17 [global::__DynamicallyInvokable]
21 [global::__DynamicallyInvokable]
25 [global::__DynamicallyInvokable]
28 internal const long LoopbackMask = 255
L;
30 internal long m_Address;
33 internal string m_ToString;
36 [global::__DynamicallyInvokable]
40 [global::__DynamicallyInvokable]
62 [global::__DynamicallyInvokable]
67 private ushort[] m_Numbers =
new ushort[8];
69 private long m_ScopeId;
71 private int m_HashCode;
73 internal const int IPv4AddressBytes = 4;
75 internal const int IPv6AddressBytes = 16;
77 internal const int NumberOfLabels = 8;
82 [Obsolete(
"This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. http://go.microsoft.com/fwlink/?linkid=14202")]
99 if (m_Address != value)
109 [global::__DynamicallyInvokable]
112 [global::__DynamicallyInvokable]
126 [global::__DynamicallyInvokable]
129 [global::__DynamicallyInvokable]
138 [global::__DynamicallyInvokable]
145 if (value < 0 || value > uint.MaxValue)
149 if (m_ScopeId != value)
157 internal bool IsBroadcast
172 [global::__DynamicallyInvokable]
175 [global::__DynamicallyInvokable]
180 return (m_Numbers[0] & 0xFF00) == 65280;
189 [global::__DynamicallyInvokable]
192 [global::__DynamicallyInvokable]
197 return (m_Numbers[0] & 0xFFC0) == 65152;
206 [global::__DynamicallyInvokable]
209 [global::__DynamicallyInvokable]
214 return (m_Numbers[0] & 0xFFC0) == 65216;
223 [global::__DynamicallyInvokable]
226 [global::__DynamicallyInvokable]
229 if (m_Family ==
AddressFamily.InterNetworkV6 && m_Numbers[0] == 8193)
231 return m_Numbers[1] == 0;
240 [global::__DynamicallyInvokable]
243 [global::__DynamicallyInvokable]
250 for (
int i = 0; i < 5; i++)
252 if (m_Numbers[i] != 0)
257 return m_Numbers[5] == ushort.MaxValue;
266 [global::__DynamicallyInvokable]
269 if (newAddress < 0 || newAddress > uint.MaxValue)
273 m_Address = newAddress;
286 [global::__DynamicallyInvokable]
293 if (address.Length != 16)
298 for (
int i = 0; i < 8; i++)
300 m_Numbers[i] = (ushort)(address[i * 2] * 256 + address[i * 2 + 1]);
302 if (scopeid < 0 || scopeid > uint.MaxValue)
309 private IPAddress(ushort[] address, uint scopeid)
322 [global::__DynamicallyInvokable]
329 if (address.Length != 4 && address.Length != 16)
333 if (address.Length == 4)
336 m_Address = (((address[3] << 24) | (address[2] << 16) | (address[1] << 8) | address[0]) & uint.MaxValue);
340 for (
int i = 0; i < 8; i++)
342 m_Numbers[i] = (ushort)(address[i * 2] * 256 + address[i * 2 + 1]);
348 m_Address = (newAddress & uint.MaxValue);
356 [global::__DynamicallyInvokable]
359 address = InternalParse(ipString, tryParse:
true);
360 return address !=
null;
370 [global::__DynamicallyInvokable]
373 return InternalParse(ipString, tryParse:
false);
376 private unsafe
static IPAddress InternalParse(
string ipString,
bool tryParse)
378 if (ipString ==
null)
386 if (ipString.IndexOf(
':') != -1)
392 byte[] array =
new byte[16];
393 SocketAddress socketAddress =
new SocketAddress(
AddressFamily.InterNetworkV6, 28);
394 if (UnsafeNclNativeMethods.OSSOCK.WSAStringToAddress(ipString,
AddressFamily.InterNetworkV6, IntPtr.Zero, socketAddress.m_Buffer, ref socketAddress.m_Size) ==
SocketError.Success)
396 for (
int i = 0; i < 16; i++)
398 array[i] = socketAddress[i + 8];
400 num = (socketAddress[27] << 24) + (socketAddress[26] << 16) + (socketAddress[25] << 8) + socketAddress[24];
412 if (ipString[0] !=
'[')
420 int end = ipString.Length;
421 fixed (
char* name = ipString)
423 if (IPv6AddressHelper.IsValidStrict(name, start, ref end) || end != ipString.Length)
425 ushort[] array2 =
new ushort[8];
426 string scopeId =
null;
427 ushort[] array3 = array2;
428 fixed (ushort* numbers = array3)
430 IPv6AddressHelper.Parse(ipString, numbers, 0, ref scopeId);
432 if (scopeId ==
null || scopeId.Length == 0)
436 scopeId = scopeId.Substring(1);
437 if (uint.TryParse(scopeId,
NumberStyles.None,
null, out uint result))
449 throw new FormatException(SR.GetString(
"dns_bad_ip_address"), ex);
451 Socket.InitializeSockets();
452 int end2 = ipString.Length;
454 fixed (
char* name2 = ipString)
456 num2 = IPv4AddressHelper.ParseNonCanonical(name2, 0, ref end2, notImplicitFile:
true);
458 if (num2 == -1 || end2 != ipString.Length)
464 throw new FormatException(SR.GetString(
"dns_bad_ip_address"));
466 num2 = (((num2 & 0xFF) << 24) | (((num2 & 0xFF00) << 8) | (((num2 & 0xFF0000) >> 8) | ((num2 & 4278190080u) >> 24))));
472 [global::__DynamicallyInvokable]
481 (
byte)(m_Address >> 8),
482 (
byte)(m_Address >> 16),
483 (
byte)(m_Address >> 24)
488 array =
new byte[16];
490 for (
int i = 0; i < 8; i++)
492 array[num++] = (byte)((m_Numbers[i] >> 8) & 0xFF);
493 array[num++] = (byte)(m_Numbers[i] & 0xFF);
502 [global::__DynamicallyInvokable]
505 if (m_ToString ==
null)
509 int addressStringLength = 256;
515 for (
int i = 0; i < 8; i++)
517 socketAddress[num++] = (byte)(m_Numbers[i] >> 8);
518 socketAddress[num++] = (byte)m_Numbers[i];
522 socketAddress[24] = (byte)m_ScopeId;
523 socketAddress[25] = (byte)(m_ScopeId >> 8);
524 socketAddress[26] = (byte)(m_ScopeId >> 16);
525 socketAddress[27] = (byte)(m_ScopeId >> 24);
527 if (UnsafeNclNativeMethods.OSSOCK.WSAAddressToString(socketAddress.m_Buffer, socketAddress.m_Size,
IntPtr.
Zero, stringBuilder, ref addressStringLength) != 0)
534 string value =
string.Format(
CultureInfo.
InvariantCulture,
"{0:x4}:{1:x4}:{2:x4}:{3:x4}:{4:x4}:{5:x4}:{6}.{7}.{8}.{9}", m_Numbers[0], m_Numbers[1], m_Numbers[2], m_Numbers[3], m_Numbers[4], m_Numbers[5], (m_Numbers[6] >> 8) & 0xFF, m_Numbers[6] & 0xFF, (m_Numbers[7] >> 8) & 0xFF, m_Numbers[7] & 0xFF);
535 stringBuilder.
Append(value);
541 m_ToString = stringBuilder.
ToString();
546 char* ptr = stackalloc
char[15];
547 int num5 = (int)((m_Address >> 24) & 0xFF);
550 ptr[--num4] = (char)(48 + num5 % 10);
555 num5 = (int)((m_Address >> 16) & 0xFF);
558 ptr[--num4] = (char)(48 + num5 % 10);
563 num5 = (int)((m_Address >> 8) & 0xFF);
566 ptr[--num4] = (char)(48 + num5 % 10);
571 num5 = (int)(m_Address & 0xFF);
574 ptr[--num4] = (char)(48 + num5 % 10);
578 m_ToString =
new string(ptr, num4, 15 - num4);
587 [global::__DynamicallyInvokable]
596 [global::__DynamicallyInvokable]
605 [global::__DynamicallyInvokable]
608 return (
short)(((host & 0xFF) << 8) | ((host >> 8) & 0xFF));
614 [global::__DynamicallyInvokable]
623 [global::__DynamicallyInvokable]
632 [global::__DynamicallyInvokable]
642 [global::__DynamicallyInvokable]
653 return (address.m_Address & 0xFF) == (
Loopback.m_Address & 0xFF);
656 internal bool Equals(
object comparandObj,
bool compareScopeId)
659 if (iPAddress ==
null)
663 if (m_Family != iPAddress.m_Family)
669 for (
int i = 0; i < 8; i++)
671 if (iPAddress.m_Numbers[i] != m_Numbers[i])
676 if (iPAddress.m_ScopeId == m_ScopeId)
686 return iPAddress.m_Address == m_Address;
693 [global::__DynamicallyInvokable]
694 public override bool Equals(
object comparand)
696 return Equals(comparand, compareScopeId:
true);
701 [global::__DynamicallyInvokable]
712 return (
int)m_Address;
722 return new IPAddress(m_Numbers, (uint)m_ScopeId);
724 throw new InternalException();
730 [global::__DynamicallyInvokable]
745 (ushort)(((m_Address & 0xFF00) >> 8) | ((m_Address & 0xFF) << 8)),
746 (ushort)(((m_Address & 4278190080u) >> 24) | ((m_Address & 0xFF0000) >> 8))
752 [global::__DynamicallyInvokable]
759 long newAddress = (uint)((
int)((uint)(m_Numbers[6] & 0xFF00) >> 8) | ((m_Numbers[6] & 0xFF) << 8) | (((
int)((uint)(m_Numbers[7] & 0xFF00) >> 8) | ((m_Numbers[7] & 0xFF) << 8)) << 16));
long Address
An Internet Protocol (IP) address.
static readonly IPAddress Broadcast
Provides the IP broadcast address. This field is read-only.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
bool IsIPv6LinkLocal
Gets whether the address is an IPv6 link local address.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
bool IsIPv6SiteLocal
Gets whether the address is an IPv6 site local address.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
int GetHashCode(object obj)
When overridden in a derived class, gets the hash code for the specified object.
static bool IsLoopback(IPAddress address)
Indicates whether the specified IP address is the loopback address.
static readonly IPAddress Any
Provides an IP address that indicates that the server must listen for client activity on all network ...
bool IsIPv6Teredo
Gets whether the address is an IPv6 Teredo address.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
bool IsIPv4MappedToIPv6
Gets whether the IP address is an IPv4-mapped IPv6 address.
Implements the Berkeley sockets interface.
IPAddress(byte[] address, long scopeid)
Initializes a new instance of the T:System.Net.IPAddress class with the address specified as a T:Syst...
unsafe override string ToString()
Converts an Internet address to its standard notation.
static long NetworkToHostOrder(long network)
Converts a long value from network byte order to host byte order.
static IPAddress Parse(string ipString)
Converts an IP address string to an T:System.Net.IPAddress instance.
override int GetHashCode()
Returns a hash value for an IP address.
static bool TryParse(string ipString, out IPAddress address)
Determines whether a string is a valid IP address.
The exception that is thrown when a socket error occurs.
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Provides an Internet Protocol (IP) address.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
IPAddress(long newAddress)
Initializes a new instance of the T:System.Net.IPAddress class with the address specified as an T:Sys...
static readonly IPAddress IPv6Any
The M:System.Net.Sockets.Socket.Bind(System.Net.EndPoint) method uses the F:System....
AddressFamily
Specifies the addressing scheme that an instance of the T:System.Net.Sockets.Socket class can use.
A platform-specific type that is used to represent a pointer or a handle.
IPAddress(byte[] address)
Initializes a new instance of the T:System.Net.IPAddress class with the address specified as a T:Syst...
Stores serialized information from T:System.Net.EndPoint derived classes.
static readonly IPAddress Loopback
Provides the IP loopback address. This field is read-only.
IPAddress MapToIPv6()
Maps the T:System.Net.IPAddress object to an IPv6 address.
static int HostToNetworkOrder(int host)
Converts an integer value from host byte order to network byte order.
static readonly IPAddress IPv6None
Provides an IP address that indicates that no network interface should be used. This property is read...
long ScopeId
Gets or sets the IPv6 address scope identifier.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static StringComparer InvariantCultureIgnoreCase
Gets a T:System.StringComparer object that performs a case-insensitive string comparison using the wo...
bool IsIPv6Multicast
Gets whether the address is an IPv6 multicast global address.
The exception that is thrown when one of the arguments provided to a method is not valid.
byte [] GetAddressBytes()
Provides a copy of the T:System.Net.IPAddress as an array of bytes.
static readonly IPAddress IPv6Loopback
Provides the IP loopback address. This property is read-only.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
static readonly IPAddress None
Provides an IP address that indicates that no network interface should be used. This field is read-on...
Specifies that the class can be serialized.
override bool Equals(object comparand)
Compares two IP addresses.
static long HostToNetworkOrder(long host)
Converts a long value from host byte order to network byte order.
static bool OSSupportsIPv6
Indicates whether the underlying operating system and network adaptors support Internet Protocol vers...
IPAddress MapToIPv4()
Maps the T:System.Net.IPAddress object to an IPv4 address.
Provides information about a specific culture (called a locale for unmanaged code development)....
static short NetworkToHostOrder(short network)
Converts a short value from network byte order to host byte order.
static short HostToNetworkOrder(short host)
Converts a short value from host byte order to network byte order.
static int NetworkToHostOrder(int network)
Converts an integer value from network byte order to host byte order.
SocketError
Defines error codes for the T:System.Net.Sockets.Socket class.
Represents a string comparison operation that uses specific case and culture-based or ordinal compari...