mscorlib(4.0.0.0) API with additions
IPEndPoint.cs
2 using System.Net.Sockets;
3 
4 namespace System.Net
5 {
8  [global::__DynamicallyInvokable]
9  public class IPEndPoint : EndPoint
10  {
12  [global::__DynamicallyInvokable]
13  public const int MinPort = 0;
14 
16  [global::__DynamicallyInvokable]
17  public const int MaxPort = 65535;
18 
19  private IPAddress m_Address;
20 
21  private int m_Port;
22 
23  internal const int AnyPort = 0;
24 
25  internal static IPEndPoint Any = new IPEndPoint(IPAddress.Any, 0);
26 
27  internal static IPEndPoint IPv6Any = new IPEndPoint(IPAddress.IPv6Any, 0);
28 
31  [global::__DynamicallyInvokable]
32  public override AddressFamily AddressFamily
33  {
34  [global::__DynamicallyInvokable]
35  get
36  {
37  return m_Address.AddressFamily;
38  }
39  }
40 
43  [global::__DynamicallyInvokable]
44  public IPAddress Address
45  {
46  [global::__DynamicallyInvokable]
47  get
48  {
49  return m_Address;
50  }
51  [global::__DynamicallyInvokable]
52  set
53  {
54  m_Address = value;
55  }
56  }
57 
61  [global::__DynamicallyInvokable]
62  public int Port
63  {
64  [global::__DynamicallyInvokable]
65  get
66  {
67  return m_Port;
68  }
69  [global::__DynamicallyInvokable]
70  set
71  {
72  if (!ValidationHelper.ValidateTcpPort(value))
73  {
74  throw new ArgumentOutOfRangeException("value");
75  }
76  m_Port = value;
77  }
78  }
79 
87  [global::__DynamicallyInvokable]
88  public IPEndPoint(long address, int port)
89  {
90  if (!ValidationHelper.ValidateTcpPort(port))
91  {
92  throw new ArgumentOutOfRangeException("port");
93  }
94  m_Port = port;
95  m_Address = new IPAddress(address);
96  }
97 
107  [global::__DynamicallyInvokable]
108  public IPEndPoint(IPAddress address, int port)
109  {
110  if (address == null)
111  {
112  throw new ArgumentNullException("address");
113  }
114  if (!ValidationHelper.ValidateTcpPort(port))
115  {
116  throw new ArgumentOutOfRangeException("port");
117  }
118  m_Port = port;
119  m_Address = address;
120  }
121 
124  [global::__DynamicallyInvokable]
125  public override string ToString()
126  {
127  string format = (m_Address.AddressFamily != AddressFamily.InterNetworkV6) ? "{0}:{1}" : "[{0}]:{1}";
128  return string.Format(format, m_Address.ToString(), Port.ToString(NumberFormatInfo.InvariantInfo));
129  }
130 
133  [global::__DynamicallyInvokable]
134  public override SocketAddress Serialize()
135  {
136  return new SocketAddress(Address, Port);
137  }
138 
144  [global::__DynamicallyInvokable]
145  public override EndPoint Create(SocketAddress socketAddress)
146  {
147  if (socketAddress.Family != AddressFamily)
148  {
149  throw new ArgumentException(SR.GetString("net_InvalidAddressFamily", socketAddress.Family.ToString(), GetType().FullName, AddressFamily.ToString()), "socketAddress");
150  }
151  if (socketAddress.Size < 8)
152  {
153  throw new ArgumentException(SR.GetString("net_InvalidSocketAddressSize", socketAddress.GetType().FullName, GetType().FullName), "socketAddress");
154  }
155  return socketAddress.GetIPEndPoint();
156  }
157 
162  [global::__DynamicallyInvokable]
163  public override bool Equals(object comparand)
164  {
165  if (!(comparand is IPEndPoint))
166  {
167  return false;
168  }
169  if (((IPEndPoint)comparand).m_Address.Equals(m_Address))
170  {
171  return ((IPEndPoint)comparand).m_Port == m_Port;
172  }
173  return false;
174  }
175 
178  [global::__DynamicallyInvokable]
179  public override int GetHashCode()
180  {
181  return m_Address.GetHashCode() ^ m_Port;
182  }
183 
184  internal IPEndPoint Snapshot()
185  {
186  return new IPEndPoint(Address.Snapshot(), Port);
187  }
188  }
189 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override SocketAddress Serialize()
Serializes endpoint information into a T:System.Net.SocketAddress instance.
Definition: IPEndPoint.cs:134
static readonly IPAddress Any
Provides an IP address that indicates that the server must listen for client activity on all network ...
Definition: IPAddress.cs:14
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
unsafe override string ToString()
Converts an Internet address to its standard notation.
Definition: IPAddress.cs:503
override int GetHashCode()
Returns a hash value for an IP address.
Definition: IPAddress.cs:702
AddressFamily AddressFamily
Gets the address family of the IP address.
Definition: IPAddress.cs:111
override bool Equals(object comparand)
Determines whether the specified T:System.Object is equal to the current T:System....
Definition: IPEndPoint.cs:163
Provides an Internet Protocol (IP) address.
Definition: IPAddress.cs:10
AddressFamily Family
Gets the T:System.Net.Sockets.AddressFamily enumerated value of the current T:System....
static readonly IPAddress IPv6Any
The M:System.Net.Sockets.Socket.Bind(System.Net.EndPoint) method uses the F:System....
Definition: IPAddress.cs:37
AddressFamily
Specifies the addressing scheme that an instance of the T:System.Net.Sockets.Socket class can use.
Definition: AddressFamily.cs:5
IPAddress Address
Gets or sets the IP address of the endpoint.
Definition: IPEndPoint.cs:45
int Port
Gets or sets the port number of the endpoint.
Definition: IPEndPoint.cs:63
override int GetHashCode()
Returns a hash value for a T:System.Net.IPEndPoint instance.
Definition: IPEndPoint.cs:179
Stores serialized information from T:System.Net.EndPoint derived classes.
Definition: SocketAddress.cs:9
Represents a network endpoint as an IP address and a port number.
Definition: IPEndPoint.cs:9
const int MaxPort
Specifies the maximum value that can be assigned to the P:System.Net.IPEndPoint.Port property....
Definition: IPEndPoint.cs:17
IPEndPoint(long address, int port)
Initializes a new instance of the T:System.Net.IPEndPoint class with the specified address and port n...
Definition: IPEndPoint.cs:88
The exception that is thrown when one of the arguments provided to a method is not valid.
IPEndPoint(IPAddress address, int port)
Initializes a new instance of the T:System.Net.IPEndPoint class with the specified address and port n...
Definition: IPEndPoint.cs:108
override EndPoint Create(SocketAddress socketAddress)
Creates an endpoint from a socket address.
Definition: IPEndPoint.cs:145
Specifies that the class can be serialized.
const int MinPort
Specifies the minimum value that can be assigned to the P:System.Net.IPEndPoint.Port property....
Definition: IPEndPoint.cs:13
Identifies a network address. This is an abstract class.
Definition: EndPoint.cs:8
static NumberFormatInfo InvariantInfo
Gets a read-only T:System.Globalization.NumberFormatInfo object that is culture-independent (invarian...
override string ToString()
Returns the IP address and port number of the specified endpoint.
Definition: IPEndPoint.cs:125
int Size
Gets the underlying buffer size of the T:System.Net.SocketAddress.
Provides culture-specific information for formatting and parsing numeric values.