//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace System.Net { using System.Net.Sockets; using System.Globalization; /// /// /// Provides an IP address. /// /// [Serializable] public class IPEndPoint : EndPoint { /// /// /// Specifies the minimum acceptable value for the /// property. /// /// public const int MinPort = 0x00000000; /// /// /// Specifies the maximum acceptable value for the /// property. /// /// public const int MaxPort = 0x0000FFFF; private IPAddress m_Address; private int m_Port; internal const int AnyPort = MinPort; internal static IPEndPoint Any = new IPEndPoint(IPAddress.Any, AnyPort); internal static IPEndPoint IPv6Any = new IPEndPoint(IPAddress.IPv6Any,AnyPort); /// /// [To be supplied.] /// public override AddressFamily AddressFamily { get { // // IPv6 Changes: Always delegate this to the address we are // wrapping. // return m_Address.AddressFamily; } } /// /// Creates a new instance of the IPEndPoint class with the specified address and /// port. /// public IPEndPoint(long address, int port) { if (!ValidationHelper.ValidateTcpPort(port)) { throw new ArgumentOutOfRangeException("port"); } m_Port = port; m_Address = new IPAddress(address); } /// /// Creates a new instance of the IPEndPoint class with the specified address and port. /// public IPEndPoint(IPAddress address, int port) { if (address==null) { throw new ArgumentNullException("address"); } if (!ValidationHelper.ValidateTcpPort(port)) { throw new ArgumentOutOfRangeException("port"); } m_Port = port; m_Address = address; } /// /// /// Gets or sets the IP address. /// /// public IPAddress Address { get { return m_Address; } set { m_Address = value; } } /// /// /// Gets or sets the port. /// /// public int Port { get { return m_Port; } set { if (!ValidationHelper.ValidateTcpPort(value)) { throw new ArgumentOutOfRangeException("value"); } m_Port = value; } } /// /// [To be supplied.] /// public override string ToString() { string format; if (m_Address.AddressFamily == AddressFamily.InterNetworkV6) format = "[{0}]:{1}"; else format = "{0}:{1}"; return String.Format(format, m_Address.ToString(), Port.ToString(NumberFormatInfo.InvariantInfo)); } /// /// [To be supplied.] /// public override SocketAddress Serialize() { // Let SocketAddress do the bulk of the work return new SocketAddress(Address, Port); } /// /// [To be supplied.] /// public override EndPoint Create(SocketAddress socketAddress) { // // validate SocketAddress // if (socketAddress.Family != this.AddressFamily) { throw new ArgumentException(SR.GetString(SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), this.GetType().FullName, this.AddressFamily.ToString()), "socketAddress"); } if (socketAddress.Size<8) { throw new ArgumentException(SR.GetString(SR.net_InvalidSocketAddressSize, socketAddress.GetType().FullName, this.GetType().FullName), "socketAddress"); } return socketAddress.GetIPEndPoint(); } //UEUE public override bool Equals(object comparand) { if (!(comparand is IPEndPoint)) { return false; } return ((IPEndPoint)comparand).m_Address.Equals(m_Address) && ((IPEndPoint)comparand).m_Port==m_Port; } //UEUE public override int GetHashCode() { return m_Address.GetHashCode() ^ m_Port; } // For security, we need to be able to take an IPEndPoint and make a copy that's immutable and not derived. internal IPEndPoint Snapshot() { return new IPEndPoint(Address.Snapshot(), Port); } } // class IPEndPoint } // namespace System.Net