{"record":{"id":"1f11bc32ac5aee65","repo":"2dust/v2rayN","slug":"unsupported-socks5-address-type-addresstype","errorCode":null,"errorMessage":"Unsupported SOCKS5 address type: {addressType}","messagePattern":"Unsupported SOCKS5 address type: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs","lineNumber":172,"sourceCode":"            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                {\n                    throw new ArgumentException(\"Invalid SOCKS5 UDP packet: domain incomplete\");\n                }\n\n                host = Encoding.ASCII.GetString(packet, offset, domainLength);\n                addressLength = domainLength;\n                isDomain = true;\n                break;\n\n            default:\n                throw new NotSupportedException($\"Unsupported SOCKS5 address type: {addressType}\");\n        }\n\n        offset += addressLength;\n\n        // Port (2 bytes, big-endian)\n        if (packet.Length < offset + 2)\n        {\n            throw new ArgumentException(\"Invalid SOCKS5 UDP packet: port incomplete\");\n        }\n\n        var port = BinaryPrimitives.ReadUInt16BigEndian(packet.AsSpan(offset, 2));\n        offset += 2;\n\n        // Data (remaining bytes)\n        var dataLength = packet.Length - offset;\n        var data = new byte[dataLength];\n        if (dataLength > 0)\n        {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs#L154-L190","documentation":"Thrown by the default branch of the ATYP switch when the address-type byte is none of IPv4 (0x01), IPv6 (0x04), or domain (0x03). The parser does not know how to locate the address/port for any other ATYP.","triggerScenarios":"ParseSocks5UdpPacket reads an ATYP value outside {0x01, 0x04, 0x03}; e.g. 0x02 or any value >= 0x05. Usually indicates a corrupt header or a non-SOCKS5 datagram hitting the relay socket.","commonSituations":"Garbage/unrelated UDP traffic reached the bound local port; packet misalignment caused the parser to read the wrong byte as ATYP (e.g. after an earlier field was mis-sized); a buggy proxy emitting an undefined ATYP.","solutions":["Catch NotSupportedException in the attempt loop and treat as a failed attempt.","Ensure the local UDP socket is bound to an ephemeral port unlikely to receive stray traffic.","Log the unexpected ATYP value and surrounding bytes to detect misalignment or stray traffic.","Validate the packet starts with RSV==0x0000 before trusting subsequent fields."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate ATYP is one of the supported values\nstatic bool IsSupportedAddressType(byte atyp) => atyp is 0x01 or 0x03 or 0x04;","typeGuard":"static bool IsKnownAddressType(byte[] packet) => packet != null && packet.Length >= 4 && packet[3] is 0x01 or 0x03 or 0x04;","tryCatchPattern":"try\n{\n    var (remote, data) = ParseSocks5UdpPacket(packet);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"address type\"))\n{\n    // undefined ATYP; likely stray traffic or header misalignment\n}","preventionTips":["Confirm the packet starts with RSV 0x0000 and FRAG 0x00 before trusting the ATYP byte.","Bind the UDP socket to an ephemeral port to avoid stray traffic.","Log the unexpected ATYP value and surrounding bytes."],"tags":["socks5","udp","packet-parsing","address-type","network"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}