Telnet and carriage return.

Rich Felker dalias at aerifal.cx
Wed Sep 12 13:15:40 UTC 2012


On Wed, Sep 12, 2012 at 01:50:38PM +0200, Arnaud Rébillout wrote:
> Hello,
> 
> I'm wondering if there is a way to issue a carriage return with telnet.
> 
> Here is the story:
> This morning I used telnet to send a mail. It's quite easy to do
> that, just telnet to the right SMTP server, the procedure is quite
> straight-forward.
> 
> The problem is that the SMTP protocol expects each line to be
> terminated by a carriage return (CR, \r in C) followed with a line
> feed (LF, \n in C). And obviously, when I hit enter in Telnet, the
> line issued to the server is terminated by a simple \n.
> 
> To fix that, I simply patched telnet, and replace each \n by \r\n.
> It works, but it's an ugly solution.
> 
> That's why I'm wondering for a better solution to do that. Simply,
> isn't there a way to issue a carriage return character ?

There are lots of translation modes available at the terminal level,
controllable with the stty command. There may be one to enable
translation of carriage return characters (the enter key) to CR+LF
combinations rather than just NL (LF). Otherwise, you could disable
the translation entirely and just press enter followed by ^J at the
end of each line...

Note that this only matters for interactive use, which is hopefully a
rare thing. Also, any SMTP server I've ever used accepts NL-only (with
no CR) input, so for interactive use rather than script use (wherein
the latter you would want to be fully robust against strict servers),
it probably doesn't matter anyway...

Another solution would be to use sed 's/$/^M/' | telnet ... (where ^M
is a literal carriage return in the command line) so that telnet is
reading from a pipe rather than a terminal, and sed is adding CR's for
you...

Rich


More information about the busybox mailing list