[+] Network Module

[+] Network Module
This commit is contained in:
ALEXTANG
2023-04-21 10:29:42 +08:00
parent 91fff462cb
commit 4f908d46af
38 changed files with 2260 additions and 2 deletions

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: e77590d750cf480baae2468038654bc0
timeCreated: 1681991042

View File

@@ -1,54 +0,0 @@
using System.Net;
using System.Net.Sockets;
namespace TEngine
{
public class NetUtil
{
public static bool IsHaveIpV6Address(IPAddress[] ipAddresses, ref IPAddress[] outIPs)
{
int v6Count = 0;
for (int i = 0; i < ipAddresses.Length; i++)
{
if (AddressFamily.InterNetworkV6.Equals(ipAddresses[i].AddressFamily))
{
v6Count++;
}
}
if (v6Count > 0)
{
outIPs = new IPAddress[v6Count];
int resIndex = 0;
for (int i = 0; i < ipAddresses.Length; i++)
{
if (AddressFamily.InterNetworkV6.Equals(ipAddresses[i].AddressFamily))
{
outIPs[resIndex++] = ipAddresses[i];
}
}
return true;
}
return false;
}
public static IPEndPoint GetEndPoint(string server, int port)
{
IPAddress[] ps = Dns.GetHostAddresses(server);
IPAddress[] finalIps = ps;
if (Socket.OSSupportsIPv6 && NetUtil.IsHaveIpV6Address(ps, ref finalIps))
{
Log.Error("socket use addr ipV6: {0}, IP count:{1} AddressFamily[{2}]", server, finalIps.Length, finalIps[0].AddressFamily);
}
if (finalIps.Length > 0)
{
return new IPEndPoint(finalIps[0], port);
}
return null;
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 26846cca9e0f4d3c965d58882c1b503e
timeCreated: 1681991073