Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IPEndPointExtensions.cs
Go to the documentation of this file.
2
3namespace System.Net.Sockets;
4
5internal static class IPEndPointExtensions
6{
8 {
9 if (endpoint is IPEndPoint iPEndPoint)
10 {
11 return new System.Net.Internals.SocketAddress(iPEndPoint.Address, iPEndPoint.Port);
12 }
13 SocketAddress address = endpoint.Serialize();
14 return GetInternalSocketAddress(address);
15 }
16
17 public static EndPoint Create(this EndPoint thisObj, System.Net.Internals.SocketAddress socketAddress)
18 {
19 AddressFamily family = socketAddress.Family;
20 if (family != thisObj.AddressFamily)
21 {
22 throw new ArgumentException(System.SR.Format(System.SR.net_InvalidAddressFamily, family.ToString(), thisObj.GetType().FullName, thisObj.AddressFamily.ToString()), "socketAddress");
23 }
24 switch (family)
25 {
26 case AddressFamily.InterNetwork:
27 case AddressFamily.InterNetworkV6:
28 if (socketAddress.Size < 8)
29 {
30 throw new ArgumentException(System.SR.Format(System.SR.net_InvalidSocketAddressSize, socketAddress.GetType().FullName, thisObj.GetType().FullName), "socketAddress");
31 }
32 return socketAddress.GetIPEndPoint();
33 case AddressFamily.Unknown:
34 return thisObj;
35 default:
36 {
37 SocketAddress netSocketAddress = GetNetSocketAddress(socketAddress);
38 return thisObj.Create(netSocketAddress);
39 }
40 }
41 }
42
44 {
46 for (int i = 0; i < address.Size; i++)
47 {
48 socketAddress[i] = address[i];
49 }
50 return socketAddress;
51 }
52
54 {
55 SocketAddress socketAddress = new SocketAddress(address.Family, address.Size);
56 for (int i = 0; i < address.Size; i++)
57 {
58 socketAddress[i] = address[i];
59 }
60 return socketAddress;
61 }
62}
virtual SocketAddress Serialize()
Definition EndPoint.cs:15
virtual EndPoint Create(SocketAddress socketAddress)
Definition EndPoint.cs:20
virtual AddressFamily AddressFamily
Definition EndPoint.cs:8
static SocketAddress GetNetSocketAddress(System.Net.Internals.SocketAddress address)
static System.Net.Internals.SocketAddress GetInternalSocketAddress(SocketAddress address)
static EndPoint Create(this EndPoint thisObj, System.Net.Internals.SocketAddress socketAddress)
static System.Net.Internals.SocketAddress Serialize(EndPoint endpoint)
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
Definition SR.cs:7