I try to send some option to telnet server, so I use below code:
OutputStream outputStream = telnetClient.getOutputStream();
byte[] option = new byte[3];
option[0] = (byte) TelnetCommand.IAC;
option[1] = (byte) TelnetCommand.DO;
option[2] = (byte) 3;
outputStream.write(option);
outputStream.flush();
But in wireshark I see 4 bytes instead of 3:
0xff 0xff 0xfd 0x03 instead of 0xff 0xfd 0x03
As you can see the 0xff byte is duplicated. I don't know why this is happened. Has anyone any idea?
You should be using the
sendCommand()method to send theTelnetCommand.DOwhich prepends the0xFF, followed by the option.The way you are doing it tells the client to send the bytes as data, so the
0xFFis escaped in the stream by doubling it.RFC 854 - Telnet Protocol Specification is worth looking at.