{"record":{"id":"f2c5f6a2e28da973","repo":"2dust/v2rayN","slug":"socks5-udp-fragmentation-is-not-supported","errorCode":null,"errorMessage":"SOCKS5 UDP fragmentation is not supported","messagePattern":"SOCKS5 UDP fragmentation is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs","lineNumber":116,"sourceCode":"    }\n\n    private static (Socks5RemoteEndpoint Remote, byte[] Data) ParseSocks5UdpPacket(byte[] packet)\n    {\n        if (packet.Length < 10) // Minimum length: RSV(2) + FRAG(1) + ATYP(1) + IPv4(4) + Port(2) = 10\n        {\n            throw new ArgumentException(\"Invalid SOCKS5 UDP packet: too short\");\n        }\n\n        var offset = 0;\n\n        // RSV (2 bytes) - Reserved field, skip\n        offset += 2;\n\n        // FRAG (1 byte) - Fragment number, currently only support 0 (no fragmentation)\n        var frag = packet[offset++];\n        if (frag != 0x00)\n        {\n            throw new NotSupportedException(\"SOCKS5 UDP fragmentation is not supported\");\n        }\n\n        // ATYP (1 byte) - Address type\n        var addressType = packet[offset++];\n\n        string host;\n        int addressLength;\n        bool isDomain;\n\n        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];","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs#L98-L134","documentation":"Thrown when the FRAG byte (3rd byte of a SOCKS5 UDP header) is non-zero. RFC 1928 allows UDP fragmentation via the FRAG field, but this implementation only supports unfragmented datagrams (FRAG == 0x00). Any proxy that actually fragments its UDP relay replies will trip this.","triggerScenarios":"ReceiveAsync parses a relay packet whose FRAG byte != 0x00. This happens when the SOCKS5 server fragments a large response across multiple UDP datagrams using the RFC 1928 fragmentation mechanism.","commonSituations":"Testing a target whose response exceeds the path MTU (e.g. a large DNS response >512 bytes, large STUN/ McBe payload) over a proxy that enables UDP fragmentation; proxy implementation that always sets a non-zero FRAG.","solutions":["Reduce the response size so it fits in a single unfragmented datagram (use a smaller test query or a tester with a compact reply such as DNS A-record queries).","Switch to a SOCKS5 proxy that does not fragment UDP, or raise the path MTU between client and proxy.","Catch NotSupportedException around ReceiveAsync and report 'fragmentation unsupported' to the user rather than crashing.","If fragmentation support is required, extend ParseSocks5UdpPacket to reassemble FRAG-ordered chunks before parsing."],"exampleFix":"// before - any non-zero FRAG aborts the whole test\nvar frag = packet[offset++];\nif (frag != 0x00)\n{\n    throw new NotSupportedException(\"SOCKS5 UDP fragmentation is not supported\");\n}\n\n// after - surface as a recoverable per-attempt failure\ntry\n{\n    var (_, receiveResult) = await channel.ReceiveAsync(cancellationToken);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"fragmentation\"))\n{\n    // retry with a smaller request or mark attempt failed\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check the FRAG byte before full parse\nstatic bool IsUnfragmented(byte[] p) => p != null && p.Length >= 3 && p[2] == 0x00;","typeGuard":"static bool IsUnfragmentedSocks5Udp(byte[] packet) => packet != null && packet.Length >= 3 && packet[2] == 0x00;","tryCatchPattern":"try\n{\n    var (remote, data) = ParseSocks5UdpPacket(packet);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"fragmentation\"))\n{\n    // proxy fragmented a large reply; reduce request size or pick a smaller tester\n}","preventionTips":["Prefer testers with compact replies (e.g. DNS A-record) to stay under MTU.","Use a SOCKS5 proxy that does not fragment UDP.","Catch NotSupportedException separately so fragmentation is distinguishable from other parse errors."],"tags":["socks5","udp","fragmentation","rfc1928","network"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}