diff --git a/Assets/GameScripts/HotFix/GameLogic/Network.meta b/Assets/GameScripts/HotFix/GameLogic/Network.meta new file mode 100644 index 00000000..854c49e1 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/Network.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e77590d750cf480baae2468038654bc0 +timeCreated: 1681991042 \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameLogic/Network/NetUtil.cs b/Assets/GameScripts/HotFix/GameLogic/Network/NetUtil.cs new file mode 100644 index 00000000..7f7476f5 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/Network/NetUtil.cs @@ -0,0 +1,54 @@ +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; + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameLogic/Network/NetUtil.cs.meta b/Assets/GameScripts/HotFix/GameLogic/Network/NetUtil.cs.meta new file mode 100644 index 00000000..588ccde7 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameLogic/Network/NetUtil.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 26846cca9e0f4d3c965d58882c1b503e +timeCreated: 1681991073 \ No newline at end of file