14

I have an application where I accept a socket connection from a telnet client and put up a simple, keyboard driven character GUI.

The telnet client, at least on Linux, defaults into line-at-a-time mode, so I always have to do ^]mode char manually.

A skim of the relevant RFCs suggests that if my application simply sent the characters IAC DONT LINEMODE (\377\376\042) as soon as the client connects, the client should be forced into character mode. However, it doesn't make any difference.

What's the simplest bit of code that would do the job? Ideally just a string to be sent. My application can absorb whatever junk the client sends back.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61

3 Answers3

9

Interesting. I had more luck sending

IAC WILL ECHO IAC WILL SUPPRESS_GO_AHEAD IAC WONT LINEMODE
255  251    1 255  251                 3 255  252       34

The IAC WONT LINEMODE seems to be redundant: my telnet client seems to get to the right state without it, but I left it in for completeness.

8

For what it's worth, solved it myself.

// IAC WONT LINEMODE IAC WILL ECHO

write(s,"\377\375\042\377\373\001",6);

gets the remote (at least telnet from an Xterm on a Linux box) into the right state.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
3

Kevin's solution works great:

write(s,"\377\375\042\377\373\001",6);

Although the comment is slightly wrong. It should say "DO LINEMODE", not "WONT LINEMODE", ie:

// IAC DO LINEMODE IAC WILL ECHO

(Source: rfc854)

Community
  • 1
  • 1
h2g2bob
  • 31
  • 1
  • The default state equivalent to the NVT (the base Network Virtual Terminal) that each end of the Telnet connection is supposed to behave as upon connection has __everything__ disabled, and nothing is enabled until the option that one end has offered to do has been agreed with their WILL and the other end's DO reply and/or the same option that that same end wants the other end to do has been requested with their DO and the other end's WILL in reply. Of course the option in one direction is separate from the same option in the other direction - except that ECHO is a _special_ case... – SlySven Jul 15 '17 at 02:42
  • ... and it is not permitted (can't recall whether it is a SHOULD NOT or a MUST NOT) to ECHO in one direction if the reverse direction already is in ECHOing mode! – SlySven Jul 15 '17 at 02:44