Another update from Larry:
[oweals/busybox.git] / telnet.c
index 76956e9ac9dc756fe3ce62f50db78932ff606c29..edcc5081fd701697d3fe69723835dcbc58830d97 100644 (file)
--- a/telnet.c
+++ b/telnet.c
  *
  */
 
-#warning This applet has moved to netkit-tiny.  After BusyBox 0.49, this
-#warning applet will be removed from BusyBox.  All maintainence efforts
-#warning should be done in the netkit-tiny source tree.
-
-
-#include "busybox.h"
 #include <termios.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
+#include "busybox.h"
 
 #if 0
-#define DOTRACE 1
+static const int DOTRACE = 1;
 #endif
 
 #ifdef DOTRACE
 #include <sys/time.h>
 #endif
 
-#define DATABUFSIZE 128
-#define IACBUFSIZE 128
+static const int DATABUFSIZE = 128;
+static const int IACBUFSIZE = 128;
 
-#define CHM_TRY 0
-#define CHM_ON 1
-#define CHM_OFF        2
+static const int CHM_TRY = 0;
+static const int CHM_ON = 1;
+static const int CHM_OFF = 2;
 
-#define UF_ECHO        0x01
-#define UF_SGA 0x02
+static const int UF_ECHO = 0x01;
+static const int UF_SGA = 0x02;
 
-#define TS_0   1
-#define TS_IAC 2
-#define TS_OPT 3
-#define TS_SUB1 4
-#define TS_SUB2        5
+enum {
+       TS_0 = 1,
+       TS_IAC = 2,
+       TS_OPT = 3,
+       TS_SUB1 = 4,
+       TS_SUB2 = 5,
+};
 
 #define WriteCS(fd, str) write(fd, str, sizeof str -1)
 
 typedef unsigned char byte;
 
 /* use globals to reduce size ??? */ /* test this hypothesis later */
-struct Globalvars {
+static struct Globalvars {
        int             netfd; /* console fd:s are 0 and 1 (and 2) */
     /* same buffer used both for network and console read/write */
        char *  buf; /* allocating so static size is smaller */
@@ -111,7 +108,7 @@ struct Globalvars {
 struct Globalvars * Gptr;
 #define G (*Gptr)
 #else
-struct Globalvars G;
+static struct Globalvars G;
 #endif
 
 static inline void iacflush()
@@ -328,7 +325,7 @@ static void putiac1(byte c)
 
 /* ******************************* */
 
-char const escapecharis[] = "\r\nEscape character is ";
+static char const escapecharis[] = "\r\nEscape character is ";
 
 static void setConMode()
 {
@@ -501,7 +498,7 @@ extern int telnet_main(int argc, char** argv)
 
        cfmakeraw(&G.termios_raw);
        
-       if (argc < 2)   usage(telnet_usage);
+       if (argc < 2)   show_usage();
        port = (argc > 2)? getport(argv[2]): 23;
        
        G.buf = xmalloc(DATABUFSIZE);
@@ -587,7 +584,7 @@ static int getport(char * p)
 
        if ((unsigned)(port - 1 ) > 65534)
        {
-               error_msg_and_die("%s: bad port number\n", p);
+               error_msg_and_die("%s: bad port number", p);
        }
        return port;
 }
@@ -599,7 +596,7 @@ static struct in_addr getserver(char * host)
        struct hostent * he;
        if ((he = gethostbyname(host)) == NULL)
        {
-               error_msg_and_die("%s: Unknown host\n", host);
+               error_msg_and_die("%s: Unknown host", host);
        }
        memcpy(&addr, he->h_addr, sizeof addr);
 
@@ -615,7 +612,7 @@ static int create_socket()
 
 static void setup_sockaddr_in(struct sockaddr_in * addr, int port)
 {
-       memset(addr, 0, sizeof addr);
+       memset(addr, 0, sizeof(struct sockaddr_in));
        addr->sin_family = AF_INET;
        addr->sin_port = htons(port);
 }