java telnet client duplicate IAC symbol

37 Views Asked by At

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?

1

There are 1 best solutions below

0
Jim Garrison On BEST ANSWER

You should be using the sendCommand() method to send the TelnetCommand.DO which prepends the 0xFF, followed by the option.

The way you are doing it tells the client to send the bytes as data, so the 0xFF is escaped in the stream by doubling it.

RFC 854 - Telnet Protocol Specification is worth looking at.