Telnet and carriage return.

Denys Vlasenko vda.linux at googlemail.com
Thu Sep 13 11:03:17 UTC 2012


On Thu, Sep 13, 2012 at 12:37 PM, Denys Vlasenko
<vda.linux at googlemail.com> wrote:
>> The second thing is that there is this nasty piece of code in busybox
>> telnet.c source:
>>
>>               else if (c == '\r')
>>                       outbuf[j++] = '\0'; /* CR -> CR NUL */
>>
>> Hell ! For some reason, every CR has a NUL appended to it. So I had to
>> remove that, and then everything works fine. Any idea about the reason for
>> this stuff ? I read the comment above but it doesn't make sense to me...
>
> I have no idea yet. Here is when it was added:
>
> commit 0e28e1fa0551487dd28a42f1dbeb5bf717817175
> Author: Eric Andersen <andersen at codepoet.org>
> Date:   Fri Apr 26 07:20:47 2002 +0000
>
>     Forward port patch from Przemyslaw Czerpak <druzus at polbox.com>:
>
>      1. busybox-telnet dosn't inform server about the size of terminal screen.
>         In the world of xterminals and frame buffers it's rather horrible
>         to use fixed 80x24 region in upper-left corner of screen/window.
>
>      2. If client sends character 0x0d to the server then sends character 0x0a
>        the server eat the second byte (0x0a) - it's described in telnet RFC.
>         Client should send two bytes ( 0x0d + 0x0a or 0x0d + 0x00 ) insted of
>         one 0x0d byte.
>
>      3. busybox telnet implementation wasn't 8bit clean (look at 0xff byte).
>         I need it because I have to use binray transfer like rz/sz. So when
>         I resloved the problem (2) I corrected this one two.
>
>     This also contains a small cleanup patch from vodz, and some minor editing
>     by me.
>
> +       int i, j;
>         byte * p = G.buf;
> +       byte outbuf[4*DATABUFSIZE];
>
> -       for (i = len; i > 0; i--, p++)
> +       for (i = len, j = 0; i > 0; i--, p++)
>         {
>                 if (*p == 0x1d)
>                 {
>                         conescape();
>                         return;
>                 }
> +               outbuf[j++] = *p;
>                 if (*p == 0xff)
> -                       *p = 0x7f;
> +                   outbuf[j++] = 0xff;
> +               else if (*p == 0x0d)
> +                   outbuf[j++] = 0x00;
>         }
> -       write(G.netfd, G.buf, len);
> +       if (j > 0 )
> +           write(G.netfd, outbuf, j);


Changed it to this in git:

                else if (c == '\r')
-                       outbuf[j++] = '\0'; /* CR -> CR NUL */
+                       /* See RFC 1123 3.3.1 Telnet End-of-Line Convention.
+                        * Using CR LF instead of other allowed possibilities
+                        * like CR NUL - easier to talk to HTTP/SMTP servers.
+                        */
+                       outbuf[j++] = '\n'; /* CR -> CR LF */


More information about the busybox mailing list