[erlang-questions] Properly decoding telnet IAC negotiations.

Thom Cherryhomes thom.cherryhomes@REDACTED
Sat Jan 28 10:08:06 CET 2017


Another round of late late night hacking.

I've been further experimenting with ranch to implement a proper Telnet
implementation (for those who thought Telnet was simply a TCP connection
from A to B...nope..)

First, I wanted to compliment the softwre engineers who worked on
gen_statem, it's a fantastic replacement for gen_fsm which consolidates a
lot of previously seperate functions into something that is simpler to
implement, but has a lot more functionality.

As part of the Telnet negotiation process, I am having to send a string of
IAC codes to specify no echo, character mode, etc. to get the terminal
characteristics that I want:

negotiation(internal, preamble,
#data{transport=Transport,socket=Socket}=Data) ->
    io:format("Sending preamble~n"),
    Transport:send(Socket,<<255,253,1,255,253,31,255,251,1,255,251,3>>),
    {next_state, negotiation, Data};

but now that I am sending this data, I am getting the terminal
characteristics that I want, but as part of the negotiation, the client not
only acknowledges the attributes that I wanted, but the client responds
with attributes of its own:

1> EventType info -- Msg {tcp,#Port<0.638>,

 <<255,252,1,255,251,31,255,250,31,0,170,0,113,255,
                             240,255,253,1,255,253,3>>} -- Data {data,

 nakbbs_telnet_ascii,

 #Port<0.638>,
                                                                 ranch_tcp}
--


I know how to parse each of these bits, but am wondering how best to do the
appropriate pattern matching to deal with each incoming bit of info.

The one saving grace is that each piece of the reply is dileniated with 255
followed by the protocol option to change (1 = echo, 31 = window size,
etc.)

Is the correct approach to snip off each dileniated piece from the binary
and match?

-Thom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170128/20d37b71/attachment.htm>


More information about the erlang-questions mailing list