Java's byte is signed. An octet whose wire value is 217 can therefore appear as a negative value when printed directly from a byte array. That does not mean the proxy sent an invalid negative IP address.

Convert the stored value to an unsigned integer, for example with Byte.toUnsignedInt(value), or use DataInputStream.readUnsignedByte() while reading the field. For a network-order port, read the documented two-byte value rather than treating either byte as a signed decimal number.

Also separate representation from framing. A socket read can return fewer bytes than requested. Read the complete field, then interpret it according to the SOCKS version and address type. SOCKS5 addresses can contain an IPv4 address, an IPv6 address, or a length-prefixed domain name; a fixed four-byte assumption only handles one of those forms.

Correcting a negative-looking octet fixes the display problem. It does not fix a parser that has started reading at the wrong offset or stopped halfway through the address.

Artiglyn mynjee