Vladimir's last_patch_15

This commit is contained in:
Glenn L McGrath
2001-06-26 02:06:08 +00:00
parent addabd6f16
commit 78b0e379d7
15 changed files with 275 additions and 253 deletions

View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: hostname.c,v 1.29 2001/06/23 13:49:14 andersen Exp $
* $Id: hostname.c,v 1.30 2001/06/26 02:06:08 bug1 Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -49,10 +49,11 @@ static void do_sethostname(char *s, int isfile)
} else {
f = xfopen(s, "r");
fgets(buf, 255, f);
#ifdef BB_FEATURE_CLEAN_UP
fclose(f);
#endif
chomp(buf);
if (sethostname(buf, strlen(buf)) < 0)
perror_msg_and_die("sethostname");
do_sethostname(buf, 0);
}
}

View File

@ -64,8 +64,8 @@ static const int DOTRACE = 1;
#include <sys/time.h>
#endif
static const int DATABUFSIZE = 128;
static const int IACBUFSIZE = 128;
#define DATABUFSIZE 128
#define IACBUFSIZE 128
static const int CHM_TRY = 0;
static const int CHM_ON = 1;
@ -90,15 +90,14 @@ typedef unsigned char byte;
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 */
short len;
char buf[DATABUFSIZE]; /* allocating so static size is smaller */
byte telstate; /* telnet negotiation state from network input */
byte telwish; /* DO, DONT, WILL, WONT */
byte charmode;
byte telflags;
byte gotsig;
/* buffer to handle telnet negotiations */
char * iacbuf;
char iacbuf[IACBUFSIZE];
short iaclen; /* could even use byte */
struct termios termios_def;
struct termios termios_raw;
@ -198,7 +197,7 @@ static void conescape()
G.gotsig = 0;
}
static void handlenetoutput()
static void handlenetoutput(int len)
{
/* here we could do smart tricks how to handle 0xFF:s in output
* stream like writing twice every sequence of FF:s (thus doing
@ -209,7 +208,7 @@ static void handlenetoutput()
int i;
byte * p = G.buf;
for (i = G.len; i > 0; i--, p++)
for (i = len; i > 0; i--, p++)
{
if (*p == 0x1d)
{
@ -219,16 +218,16 @@ static void handlenetoutput()
if (*p == 0xff)
*p = 0x7f;
}
write(G.netfd, G.buf, G.len);
write(G.netfd, G.buf, len);
}
static void handlenetinput()
static void handlenetinput(int len)
{
int i;
int cstart = 0;
for (i = 0; i < G.len; i++)
for (i = 0; i < len; i++)
{
byte c = G.buf[i];
@ -290,11 +289,11 @@ static void handlenetinput()
if (G.iaclen) iacflush();
if (G.telstate == TS_0) G.telstate = 0;
G.len = cstart;
len = cstart;
}
if (G.len)
write(1, G.buf, G.len);
if (len)
write(1, G.buf, len);
}
@ -530,6 +529,7 @@ extern int telnet_main(int argc, char** argv)
{
struct in_addr host;
int port;
int len;
#ifdef USE_POLL
struct pollfd ufds[2];
#else
@ -547,15 +547,11 @@ extern int telnet_main(int argc, char** argv)
exit(1);
G.termios_raw = G.termios_def;
cfmakeraw(&G.termios_raw);
if (argc < 2) show_usage();
port = (argc > 2)? getport(argv[2]): 23;
G.buf = xmalloc(DATABUFSIZE);
G.iacbuf = xmalloc(IACBUFSIZE);
host = getserver(argv[1]);
G.netfd = remote_connect(host, port);
@ -599,14 +595,14 @@ extern int telnet_main(int argc, char** argv)
if (FD_ISSET(0, &rfds))
#endif
{
G.len = read(0, G.buf, DATABUFSIZE);
len = read(0, G.buf, DATABUFSIZE);
if (G.len <= 0)
if (len <= 0)
doexit(0);
TRACE(0, ("Read con: %d\n", G.len));
TRACE(0, ("Read con: %d\n", len));
handlenetoutput();
handlenetoutput(len);
}
#ifdef USE_POLL
@ -615,16 +611,16 @@ extern int telnet_main(int argc, char** argv)
if (FD_ISSET(G.netfd, &rfds))
#endif
{
G.len = read(G.netfd, G.buf, DATABUFSIZE);
len = read(G.netfd, G.buf, DATABUFSIZE);
if (G.len <= 0)
if (len <= 0)
{
WriteCS(1, "Connection closed by foreign host.\r\n");
doexit(1);
}
TRACE(0, ("Read netfd (%d): %d\n", G.netfd, G.len));
TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len));
handlenetinput();
handlenetinput(len);
}
}
}