Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IPEndPoint.cs
Go to the documentation of this file.
4
5namespace System.Net;
6
7public class IPEndPoint : EndPoint
8{
9 public const int MinPort = 0;
10
11 public const int MaxPort = 65535;
12
14
15 private int _port;
16
18
20 {
21 get
22 {
23 return _address;
24 }
25 set
26 {
27 _address = value ?? throw new ArgumentNullException("value");
28 }
29 }
30
31 public int Port
32 {
33 get
34 {
35 return _port;
36 }
37 set
38 {
40 {
41 throw new ArgumentOutOfRangeException("value");
42 }
43 _port = value;
44 }
45 }
46
47 public IPEndPoint(long address, int port)
48 {
50 {
51 throw new ArgumentOutOfRangeException("port");
52 }
53 _port = port;
54 _address = new IPAddress(address);
55 }
56
57 public IPEndPoint(IPAddress address, int port)
58 {
59 if (address == null)
60 {
61 throw new ArgumentNullException("address");
62 }
64 {
65 throw new ArgumentOutOfRangeException("port");
66 }
67 _port = port;
68 _address = address;
69 }
70
71 public static bool TryParse(string s, [NotNullWhen(true)] out IPEndPoint? result)
72 {
73 return TryParse(s.AsSpan(), out result);
74 }
75
76 public static bool TryParse(ReadOnlySpan<char> s, [NotNullWhen(true)] out IPEndPoint? result)
77 {
78 int num = s.Length;
79 int num2 = s.LastIndexOf(':');
80 if (num2 > 0)
81 {
82 if (s[num2 - 1] == ']')
83 {
84 num = num2;
85 }
86 else if (s.Slice(0, num2).LastIndexOf(':') == -1)
87 {
88 num = num2;
89 }
90 }
91 if (IPAddress.TryParse(s.Slice(0, num), out IPAddress address))
92 {
93 uint result2 = 0u;
94 if (num == s.Length || (uint.TryParse(s.Slice(num + 1), NumberStyles.None, CultureInfo.InvariantCulture, out result2) && result2 <= 65535))
95 {
96 result = new IPEndPoint(address, (int)result2);
97 return true;
98 }
99 }
100 result = null;
101 return false;
102 }
103
104 public static IPEndPoint Parse(string s)
105 {
106 if (s == null)
107 {
108 throw new ArgumentNullException("s");
109 }
110 return Parse(s.AsSpan());
111 }
112
114 {
115 if (TryParse(s, out IPEndPoint result))
116 {
117 return result;
118 }
120 }
121
122 public override string ToString()
123 {
124 string format = ((_address.AddressFamily == AddressFamily.InterNetworkV6) ? "[{0}]:{1}" : "{0}:{1}");
125 return string.Format(format, _address.ToString(), Port.ToString(NumberFormatInfo.InvariantInfo));
126 }
127
128 public override SocketAddress Serialize()
129 {
130 return new SocketAddress(Address, Port);
131 }
132
133 public override EndPoint Create(SocketAddress socketAddress)
134 {
135 if (socketAddress == null)
136 {
137 throw new ArgumentNullException("socketAddress");
138 }
139 if (socketAddress.Family != AddressFamily)
140 {
141 throw new ArgumentException(System.SR.Format(System.SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), GetType().FullName, AddressFamily.ToString()), "socketAddress");
142 }
144 if (socketAddress.Size < num)
145 {
146 throw new ArgumentException(System.SR.Format(System.SR.net_InvalidSocketAddressSize, socketAddress.GetType().FullName, GetType().FullName), "socketAddress");
147 }
148 return socketAddress.GetIPEndPoint();
149 }
150
151 public override bool Equals([NotNullWhen(true)] object? comparand)
152 {
153 if (comparand is IPEndPoint iPEndPoint && iPEndPoint._address.Equals(_address))
154 {
155 return iPEndPoint._port == _port;
156 }
157 return false;
158 }
159
160 public override int GetHashCode()
161 {
162 return _address.GetHashCode() ^ _port;
163 }
164}
static CultureInfo InvariantCulture
override int GetHashCode()
Definition IPAddress.cs:496
override string ToString()
Definition IPAddress.cs:390
override bool Equals([NotNullWhen(true)] object? comparand)
Definition IPAddress.cs:468
static bool TryParse([NotNullWhen(true)] string? ipString, [NotNullWhen(true)] out IPAddress? address)
Definition IPAddress.cs:303
AddressFamily AddressFamily
Definition IPAddress.cs:88
static bool TryParse(ReadOnlySpan< char > s, [NotNullWhen(true)] out IPEndPoint? result)
Definition IPEndPoint.cs:76
IPEndPoint(IPAddress address, int port)
Definition IPEndPoint.cs:57
override bool Equals([NotNullWhen(true)] object? comparand)
override EndPoint Create(SocketAddress socketAddress)
static IPEndPoint Parse(string s)
IPEndPoint(long address, int port)
Definition IPEndPoint.cs:47
override int GetHashCode()
override SocketAddress Serialize()
override string ToString()
static IPEndPoint Parse(ReadOnlySpan< char > s)
static bool TryParse(string s, [NotNullWhen(true)] out IPEndPoint? result)
Definition IPEndPoint.cs:71
static readonly int IPv4AddressSize
static readonly int IPv6AddressSize
static bool ValidatePortNumber(int port)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_InvalidSocketAddressSize
Definition SR.cs:22
static string net_InvalidAddressFamily
Definition SR.cs:20
static string bad_endpoint_string
Definition SR.cs:50
Definition SR.cs:7