2

In Linux, when I run telnet <address> <port> and then type things, it buffers data and only sends collected line when I hit Enter. Furthermore, it buffers up to 4096 characters and truncates everything else.

I can confirm this by listening to the traffic via tcpdump or anything like this.

Is it possible to send bytes (or multibytes if UTF-8 encoding of character is multibyte) immediately when it appears? I expect to see "1-byte" (1 payload byte plus headers) TCP packets in the tcpdump output.

Or, at least, is it possible to force it to send the collected buffer without <cr> or/and <lf> characters?

1 Answer 1

5

The telnet client, specifically, is designed to speak to a Telnet server using the Telnet protocol; it will switch to character mode if it receives Telnet IAC WILL SGA / IAC DO SGA from the server.

Alternatively, you can press Ctrl] and enter mode character to initiate this from the client side; the client will send the Telnet IAC negotiation messages to the server and will switch to character-by-character mode. If the server is not a Telnet server, this will result in it receiving a few garbage characters before your input.

On the other hand, for programs like nc or ncat (i.e. not Telnet clients), which keep the local tty in "cooked" mode, this buffering is done by the tty and not by the program. Either a) press Ctrl+D at any point to make the tty return the text that was typed so far, or b) use stty raw to switch the tty to raw mode before starting the program (and stty cooked iutf8 -brkint to switch back).

(Ctrl+D isn't just the EOF key, it's the "end of read() call" key. Pressing Ctrl+D on an empty line, i.e. making the read() return nothing, is what actually gives EOF; whereas Ctrl+D after some input will return just that input, without any trailing CR/LF.)

1
  • Yes. Sure. I missed that mode character. Also nice suggestion about netcat. Thank you! Commented May 22, 2023 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .