2dust/v2rayN · error · NotSupportedException

Unsupported SOCKS5 address type: {addressType}

Error message

Unsupported SOCKS5 address type: {addressType}

What it means

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.

Source

Thrown at v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs:172

            case Socks5AddressData.AddrTypeDomain:
                if (packet.Length < offset + 1)
                {
                    throw new ArgumentException("Invalid SOCKS5 UDP packet: domain length missing");
                }

                var domainLength = packet[offset++];
                if (packet.Length < offset + domainLength)
                {
                    throw new ArgumentException("Invalid SOCKS5 UDP packet: domain incomplete");
                }

                host = Encoding.ASCII.GetString(packet, offset, domainLength);
                addressLength = domainLength;
                isDomain = true;
                break;

            default:
                throw new NotSupportedException($"Unsupported SOCKS5 address type: {addressType}");
        }

        offset += addressLength;

        // Port (2 bytes, big-endian)
        if (packet.Length < offset + 2)
        {
            throw new ArgumentException("Invalid SOCKS5 UDP packet: port incomplete");
        }

        var port = BinaryPrimitives.ReadUInt16BigEndian(packet.AsSpan(offset, 2));
        offset += 2;

        // Data (remaining bytes)
        var dataLength = packet.Length - offset;
        var data = new byte[dataLength];
        if (dataLength > 0)
        {

View on GitHub (pinned to e01717d832)

Solutions

  1. Catch NotSupportedException in the attempt loop and treat as a failed attempt.
  2. Ensure the local UDP socket is bound to an ephemeral port unlikely to receive stray traffic.
  3. Log the unexpected ATYP value and surrounding bytes to detect misalignment or stray traffic.
  4. Validate the packet starts with RSV==0x0000 before trusting subsequent fields.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate ATYP is one of the supported values
static bool IsSupportedAddressType(byte atyp) => atyp is 0x01 or 0x03 or 0x04;

Type guard

static bool IsKnownAddressType(byte[] packet) => packet != null && packet.Length >= 4 && packet[3] is 0x01 or 0x03 or 0x04;

Try / catch

try
{
    var (remote, data) = ParseSocks5UdpPacket(packet);
}
catch (NotSupportedException ex) when (ex.Message.Contains("address type"))
{
    // undefined ATYP; likely stray traffic or header misalignment
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of 2dust/v2rayN@e01717d832 (2026-08-13). Data as JSON: /api/errors/1f11bc32ac5aee65. Report an issue: GitHub.