Im trying to build a basic proxy 4 server, and I have to parse a packet and extract its informations that looks like this:

```
1 byte (version)
1 byte (command)
2 byte (port)
4 byte (ip)
X byte (userID, builds a string by looping until '\0' is found)

```

Here's my code so far:

```
InputStream reader = socket.getInputStream();

byte[] ver  = new byte[1];
byte[] cmd  = new byte[1];
byte[] port = new byte[2];
byte[] ip   = new byte[4];

reader.read(ver, 0, 1);  //should be: 4
reader.read(cmd, 1, 1);  //should be: 1
reader.read(port, 2, 2); //should be: 00, 80
reader.read(ip, 4, 4);   //should be: 217, 70, 182, 162

```

Here's the response I get from my code: `[4, 1, 0, 80, -39, 70, -74, -94]`

For some reason the IP part I get is always wrong, I really don't know why. My second issue would be: Is there an easy and clean way to get the last userID string part, without having to build a messy loop that could end up hanging for ever, if the `\0` byte was not found?