{"record":{"id":"83bed3babf00e94d","repo":"egametang/ET","slug":"only-ipv4-addresses-are-supported","errorCode":null,"errorMessage":"Only IPv4 addresses are supported","messagePattern":"Only IPv4 addresses are supported","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Helper/NetworkHelper.cs","lineNumber":79,"sourceCode":"\t\t\tTcpListener tcpListener = new TcpListener(IPAddress.Loopback, 0);\n\t\t\ttry\n\t\t\t{\n\t\t\t\ttcpListener.Start();\n\t\t\t\treturn ((IPEndPoint)tcpListener.LocalEndpoint).Port;\n\t\t\t}\n\t\t\tfinally\n\t\t\t{\n\t\t\t\ttcpListener.Stop();\n\t\t\t}\n\t\t}\n\n\t\tpublic static int IPStringToInt(string ipString)\n\t\t{\n\t\t\tIPAddress ipAddress = IPAddress.Parse(ipString);\n\t\t\tbyte[] bytes = ipAddress.GetAddressBytes();\n\t\t\tif (bytes.Length != 4)\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"Only IPv4 addresses are supported\");\n\t\t\t}\n\t\t\treturn (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];\n\t\t}\n\n\t\tpublic static string IntToIPString(int ipInt)\n\t\t{\n\t\t\tbyte[] bytes = new byte[4];\n\t\t\tbytes[0] = (byte)((ipInt >> 24) & 0xFF);\n\t\t\tbytes[1] = (byte)((ipInt >> 16) & 0xFF);\n\t\t\tbytes[2] = (byte)((ipInt >> 8) & 0xFF);\n\t\t\tbytes[3] = (byte)(ipInt & 0xFF);\n\t\t\treturn new IPAddress(bytes).ToString();\n\t\t}\n        \n\t\tpublic static void SetSioUdpConnReset(Socket socket)\n\t\t{\n\t\t\tif (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))\n\t\t\t{","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Helper/NetworkHelper.cs#L61-L97","documentation":"Thrown by NetworkHelper.IPStringToInt when the parsed address is not IPv4 (i.e. its byte length is not 4, so it is IPv6 or an unexpected family). The helper packs an address into one 32-bit int, which only fits IPv4.","triggerScenarios":"Passing an IPv6 literal (e.g. '::1', 'fe80::1') to IPStringToInt; an address resolved from a dual-stack socket that returned IPv6; config/environment giving an IPv6 address.","commonSituations":"Server configured with IPv6 addresses; modern OS preferring IPv6 for loopback ('::1'); parsing addresses from hosts that are v6-only.","solutions":["Use an IPv4 address string (e.g. '127.0.0.1', '10.0.0.1') for any value fed to IPStringToInt.","If you must support IPv6, use IPAddress.GetAddressBytes/long directly instead of this 4-byte helper.","Normalize loopback to '127.0.0.1' rather than '::1' before calling."],"exampleFix":"// before\nint ip = NetworkHelper.IPStringToInt(\"::1\");\n\n// after\nint ip = NetworkHelper.IPStringToInt(\"127.0.0.1\");","handlingStrategy":"validation","validationCode":"var addr = IPAddress.Parse(ipString);\nif (addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)\n{\n    int ip = NetworkHelper.IPStringToInt(ipString);\n}","typeGuard":"static bool IsIPv4(string ip)\n    => IPAddress.TryParse(ip, out var a)\n       && a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork;","tryCatchPattern":null,"preventionTips":["Feed only IPv4 literals to IPStringToInt.","Normalize loopback to 127.0.0.1 instead of ::1.","For IPv6, use IPAddress bytes directly, not this helper."],"tags":["network","ipv4","ipv6","core"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}