Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/networking/telnet.c

    r2725 r3232  
    2222 */
    2323
     24//usage:#if ENABLE_FEATURE_TELNET_AUTOLOGIN
     25//usage:#define telnet_trivial_usage
     26//usage:       "[-a] [-l USER] HOST [PORT]"
     27//usage:#define telnet_full_usage "\n\n"
     28//usage:       "Connect to telnet server\n"
     29//usage:     "\n    -a  Automatic login with $USER variable"
     30//usage:     "\n    -l USER Automatic login as USER"
     31//usage:
     32//usage:#else
     33//usage:#define telnet_trivial_usage
     34//usage:       "HOST [PORT]"
     35//usage:#define telnet_full_usage "\n\n"
     36//usage:       "Connect to telnet server"
     37//usage:#endif
     38
    2439#include <arpa/telnet.h>
    2540#include <netinet/in.h>
    2641#include "libbb.h"
    2742
     43#ifdef __BIONIC__
     44/* should be in arpa/telnet.h */
     45# define IAC         255  /* interpret as command: */
     46# define DONT        254  /* you are not to use option */
     47# define DO          253  /* please, you use option */
     48# define WONT        252  /* I won't use option */
     49# define WILL        251  /* I will use option */
     50# define SB          250  /* interpret as subnegotiation */
     51# define SE          240  /* end sub negotiation */
     52# define TELOPT_ECHO   1  /* echo */
     53# define TELOPT_SGA    3  /* suppress go ahead */
     54# define TELOPT_TTYPE 24  /* terminal type */
     55# define TELOPT_NAWS  31  /* window size */
     56#endif
     57
    2858#ifdef DOTRACE
    29 #define TRACE(x, y) do { if (x) printf y; } while (0)
     59# define TRACE(x, y) do { if (x) printf y; } while (0)
    3060#else
    31 #define TRACE(x, y)
     61# define TRACE(x, y)
    3262#endif
    3363
     
    157187static void handle_net_output(int len)
    158188{
    159     /* here we could do smart tricks how to handle 0xFF:s in output
    160      * stream like writing twice every sequence of FF:s (thus doing
    161      * many write()s. But I think interactive telnet application does
    162      * not need to be 100% 8-bit clean, so changing every 0xff:s to
    163      * 0x7f:s
    164      *
    165      * 2002-mar-21, Przemyslaw Czerpak (druzus@polbox.com)
    166      * I don't agree.
    167      * first - I cannot use programs like sz/rz
    168      * second - the 0x0D is sent as one character and if the next
    169      *  char is 0x0A then it's eaten by a server side.
    170      * third - why do you have to make 'many write()s'?
    171      *  I don't understand.
    172      * So I implemented it. It's really useful for me. I hope that
    173      * other people will find it interesting too.
    174      */
    175189    byte outbuf[2 * DATABUFSIZE];
    176     byte *p = (byte*)G.buf;
    177     int j = 0;
    178 
    179     for (; len > 0; len--, p++) {
    180         byte c = *p;
     190    byte *dst = outbuf;
     191    byte *src = (byte*)G.buf;
     192    byte *end = src + len;
     193
     194    while (src < end) {
     195        byte c = *src++;
    181196        if (c == 0x1d) {
    182197            con_escape();
    183198            return;
    184199        }
    185         outbuf[j++] = c;
     200        *dst = c;
    186201        if (c == IAC)
    187             outbuf[j++] = c; /* IAC -> IAC IAC */
    188         else if (c == '\r')
    189             outbuf[j++] = '\0'; /* CR -> CR NUL */
    190     }
    191     if (j > 0)
    192         full_write(netfd, outbuf, j);
     202            *++dst = c; /* IAC -> IAC IAC */
     203        else
     204        if (c == '\r' || c == '\n') {
     205            /* Enter key sends '\r' in raw mode and '\n' in cooked one.
     206             *
     207             * See RFC 1123 3.3.1 Telnet End-of-Line Convention.
     208             * Using CR LF instead of other allowed possibilities
     209             * like CR NUL - easier to talk to HTTP/SMTP servers.
     210             */
     211            *dst = '\r'; /* Enter -> CR LF */
     212            *++dst = '\n';
     213        }
     214        dst++;
     215    }
     216    if (dst - outbuf != 0)
     217        full_write(netfd, outbuf, dst - outbuf);
    193218}
    194219
     
    369394#endif
    370395
    371 static char const escapecharis[] ALIGN1 = "\r\nEscape character is ";
    372 
    373396static void setConMode(void)
    374397{
     
    376399        if (G.charmode == CHM_TRY) {
    377400            G.charmode = CHM_ON;
    378             printf("\r\nEntering character mode%s'^]'.\r\n", escapecharis);
     401            printf("\r\nEntering %s mode"
     402                "\r\nEscape character is '^%c'.\r\n", "character", ']');
    379403            rawmode();
    380404        }
     
    382406        if (G.charmode != CHM_OFF) {
    383407            G.charmode = CHM_OFF;
    384             printf("\r\nEntering line mode%s'^C'.\r\n", escapecharis);
     408            printf("\r\nEntering %s mode"
     409                "\r\nEscape character is '^%c'.\r\n", "line", 'C');
    385410            cookmode();
    386411        }
Note: See TracChangeset for help on using the changeset viewer.