{"record":{"id":"f3a38b10e573fad9","repo":"2dust/v2rayN","slug":"invalid-socks5-udp-packet-ipv6-address-incomplete","errorCode":null,"errorMessage":"Invalid SOCKS5 UDP packet: IPv6 address incomplete","messagePattern":"Invalid SOCKS5 UDP packet: IPv6 address incomplete","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs","lineNumber":144,"sourceCode":"        switch (addressType)\n        {\n            case Socks5AddressData.AddrTypeIPv4:\n                if (packet.Length < offset + 4)\n                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: IPv4 address incomplete\");\n                }\n\n                var ipv4Bytes = new byte[4];\n                Array.Copy(packet, offset, ipv4Bytes, 0, 4);\n                host = new IPAddress(ipv4Bytes).ToString();\n                addressLength = 4;\n                isDomain = false;\n                break;\n\n            case Socks5AddressData.AddrTypeIPv6:\n                if (packet.Length < offset + 16)\n                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: IPv6 address incomplete\");\n                }\n\n                var ipv6Bytes = new byte[16];\n                Array.Copy(packet, offset, ipv6Bytes, 0, 16);\n                host = new IPAddress(ipv6Bytes).ToString();\n                addressLength = 16;\n                isDomain = false;\n                break;\n\n            case Socks5AddressData.AddrTypeDomain:\n                if (packet.Length < offset + 1)\n                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: domain length missing\");\n                }\n\n                var domainLength = packet[offset++];\n                if (packet.Length < offset + domainLength)\n                {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs#L126-L162","documentation":"Thrown when ATYP indicates IPv6 (0x04) but fewer than 16 bytes remain for the 128-bit address. Same truncation guard as the IPv4 case but sized for 16 octets.","triggerScenarios":"ParseSocks5UdpPacket reads ATYP == AddrTypeIPv6 then packet.Length < offset + 16; the datagram was cut short inside the IPv6 address field.","commonSituations":"Truncated IPv6 relay response; proxy reporting an IPv6 ATYP without a full 16-byte address; MTU/fragmentation truncating an already-large IPv6-headed packet.","solutions":["Catch ArgumentException per attempt and continue (the response is unusable but the test loop can retry).","Confirm the proxy encodes IPv6 with ATYP 0x04 + 16 address bytes + 2 port bytes per RFC 1928.","If the target resolves to IPv6, prefer a dual-stack proxy and ensure the relay path supports 16-byte address headers.","Log ATYP and remaining-length at failure to confirm truncation vs. proxy bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check IPv6 address availability\nstatic bool HasFullIPv6(byte[] p, int offset) => p != null && p.Length >= offset + 16;","typeGuard":"static bool IsCompleteIPv6Packet(byte[] packet, int offset) => packet != null && offset + 16 + 2 <= packet.Length;","tryCatchPattern":"try\n{\n    var (remote, data) = ParseSocks5UdpPacket(packet);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"IPv6 address incomplete\"))\n{\n    // truncated IPv6 relay packet; retry or mark attempt failed\n}","preventionTips":["Catch the ArgumentException per attempt rather than letting it propagate.","Verify the proxy writes 16-byte IPv6 addresses with ATYP 0x04.","Ensure the relay path supports the larger IPv6-headed packet without truncation."],"tags":["socks5","udp","packet-parsing","ipv6","network"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}