summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--loader2/telnet.c22
-rw-r--r--loader2/telnetd.c17
2 files changed, 23 insertions, 16 deletions
diff --git a/loader2/telnet.c b/loader2/telnet.c
index fda836639..473acfeb4 100644
--- a/loader2/telnet.c
+++ b/loader2/telnet.c
@@ -77,30 +77,31 @@ telnet_negotiate(int socket, char ** term_type_ptr, int * heightPtr,
IAC DO NAWS
IAC SB TERMINAL_TYPE "\x01" IAC SE
;
+ int ret;
- write(socket, request, sizeof(request)-1);
+ ret = write(socket, request, sizeof(request)-1);
/* Read from the terminal until we get the terminal type. This will
do bad things if the client doesn't send the terminal type, but
those clients have existed for aeons (right?) */
do {
- read(socket, &ch, 1);
+ ret = read(socket, &ch, 1);
if (ch != '\xff') {
abort();
}
- read(socket, &ch, 1); /* command */
+ ret = read(socket, &ch, 1); /* command */
if (ch != '\xfa') {
- read(socket, &ch, 1); /* verb */
+ ret = read(socket, &ch, 1); /* verb */
continue;
}
- read(socket, &ch, 1); /* suboption */
+ ret = read(socket, &ch, 1); /* suboption */
if (ch == '\x18') {
state = ST_TERMTYPE;
- read(socket, &ch, 1); /* should be 0x0! */
+ ret = read(socket, &ch, 1); /* should be 0x0! */
done = 1;
} else if (ch == '\x1f') {
state = ST_WINDOWSIZE;
@@ -108,7 +109,7 @@ telnet_negotiate(int socket, char ** term_type_ptr, int * heightPtr,
state = ST_NONE;;
}
- read(socket, &ch, 1); /* data */
+ ret = read(socket, &ch, 1); /* data */
while (ch != '\xff') {
if (state == ST_TERMTYPE) {
if (termAlloced == termLength) {
@@ -122,10 +123,10 @@ telnet_negotiate(int socket, char ** term_type_ptr, int * heightPtr,
*sizePtr++ = ch;
}
- read(socket, &ch, 1); /* data */
+ ret = read(socket, &ch, 1); /* data */
}
- read(socket, &ch, 1); /* should be a SE */
+ ret = read(socket, &ch, 1); /* should be a SE */
} while (!done);
@@ -251,6 +252,7 @@ void
telnet_send_output(int sock, char *data, int len) {
char *s, *d; /* source, destination */
char *buf;
+ int ret;
buf = alloca((len*2)+1); /* max necessary size */
@@ -265,5 +267,5 @@ telnet_send_output(int sock, char *data, int len) {
}
/* now send it... */
- write(sock, buf, len);
+ ret = write(sock, buf, len);
}
diff --git a/loader2/telnetd.c b/loader2/telnetd.c
index 208a15c3f..9b5ed9930 100644
--- a/loader2/telnetd.c
+++ b/loader2/telnetd.c
@@ -46,10 +46,10 @@
int beTelnet(int flags) {
int sock;
int conn;
- int addrLength;
+ unsigned int addrLength;
pid_t child;
int i;
- int masterFd;
+ int masterFd, ttyFd;
struct sockaddr_in address;
char buf[4096];
struct pollfd fds[3];
@@ -162,6 +162,7 @@ int beTelnet(int flags) {
}
if (fds[1].revents) {
+ int ret;
i = read(conn, buf, sizeof(buf));
/* connection went away */
@@ -169,7 +170,7 @@ int beTelnet(int flags) {
break;
i = telnet_process_input(&ts, buf, i);
- write(masterFd, buf, i);
+ ret = write(masterFd, buf, i);
#ifdef DEBUG_TELNET
{
@@ -206,9 +207,13 @@ int beTelnet(int flags) {
close(1);
close(2);
- open("/dev/ttyp0", O_RDWR);
- dup(0);
- dup(0);
+ ttyFd = open("/dev/ttyp0", O_RDWR);
+ if (ttyFd != 0) {
+ dup2(ttyFd, 0);
+ close(ttyFd);
+ }
+ dup2(0, 1);
+ dup2(0, 2);
/* brand new tty! */
setenv("TERM", termType, 1);