2dust/v2rayN · error · ArgumentException
Invalid SOCKS5 UDP packet: domain length missing
Error message
Invalid SOCKS5 UDP packet: domain length missing
What it means
Thrown when ATYP indicates a domain (0x03) but there is no length byte following it. A domain address in SOCKS5 is length-prefixed (1 length byte + N name bytes); the parser cannot proceed without the length.
Source
Thrown at v2rayN/ServiceLib.UdpTest/Socks5UdpChannel.cs:157
break;
case Socks5AddressData.AddrTypeIPv6:
if (packet.Length < offset + 16)
{
throw new ArgumentException("Invalid SOCKS5 UDP packet: IPv6 address incomplete");
}
var ipv6Bytes = new byte[16];
Array.Copy(packet, offset, ipv6Bytes, 0, 16);
host = new IPAddress(ipv6Bytes).ToString();
addressLength = 16;
isDomain = false;
break;
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;View on GitHub (pinned to e01717d832)
Solutions
- Catch ArgumentException in the attempt loop and treat as a failed attempt.
- Verify the proxy emits domain-type headers as ATYP 0x03 + 1-byte length + ASCII name when it relays by hostname.
- Log the packet tail to confirm whether the length byte is genuinely missing or the ATYP was misread due to an earlier field error.
- Test with a target that yields an IPv4 (ATYP 0x01) reply to isolate domain-encoding bugs.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check domain length byte presence static bool HasDomainLengthByte(byte[] p, int offset) => p != null && p.Length >= offset + 1;
Type guard
static bool HasDomainLength(byte[] packet, int offset) => packet != null && offset + 1 <= packet.Length;
Try / catch
try
{
var (remote, data) = ParseSocks5UdpPacket(packet);
}
catch (ArgumentException ex) when (ex.Message.Contains("domain length missing"))
{
// truncated just after ATYP; mark attempt failed
} Prevention
- Catch the ArgumentException per attempt.
- Confirm the proxy emits ATYP 0x03 + length byte + ASCII name.
- Log the packet tail to distinguish a missing length byte from earlier misalignment.
When it happens
Trigger: ParseSocks5UdpPacket reads ATYP == AddrTypeDomain then packet.Length < offset + 1, i.e. the datagram ends immediately after the ATYP byte with no domain-length octet.
Common situations: Truncated relay packet right after the ATYP; proxy that uses an ATYP the client does not expect; corrupt datagram.
Related errors
- Invalid SOCKS5 UDP packet: domain incomplete
- Invalid SOCKS5 UDP packet: too short
- Invalid SOCKS5 UDP packet: IPv4 address incomplete
- Invalid SOCKS5 UDP packet: IPv6 address incomplete
- Unsupported SOCKS5 address type: {addressType}
AI-assisted analysis of 2dust/v2rayN@e01717d832 (2026-08-13).
Data as JSON: /api/errors/c78119d1509839a9.
Report an issue: GitHub.