diff options
author | Hans Insulander <hin@cvs.openbsd.org> | 2001-06-23 19:44:34 +0000 |
---|---|---|
committer | Hans Insulander <hin@cvs.openbsd.org> | 2001-06-23 19:44:34 +0000 |
commit | 12ce374fe89e95dea19bb150c4921a44f38e2b67 (patch) | |
tree | 013871c09a69480975817d38807e67dd5113de2b /libexec/telnetd/utility.c | |
parent | 65f285480cfb8ffdde7cfc949f935d1e91911803 (diff) |
Replace our telnetd with the one from heimdal-0.3f, with the following changes:
- obvious buildsystem tweakes
- our way to filter out bad environment variables
Diffstat (limited to 'libexec/telnetd/utility.c')
-rw-r--r-- | libexec/telnetd/utility.c | 1624 |
1 files changed, 791 insertions, 833 deletions
diff --git a/libexec/telnetd/utility.c b/libexec/telnetd/utility.c index 6f3cc3e1983..b14a10246fc 100644 --- a/libexec/telnetd/utility.c +++ b/libexec/telnetd/utility.c @@ -1,6 +1,3 @@ -/* $OpenBSD: utility.c,v 1.16 2001/06/11 15:18:53 mickey Exp $ */ -/* $NetBSD: utility.c,v 1.9 1996/02/28 20:38:29 thorpej Exp $ */ - /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -34,24 +31,10 @@ * SUCH DAMAGE. */ -#ifndef lint -#if 0 -static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95"; -static char rcsid[] = "$NetBSD: utility.c,v 1.9 1996/02/28 20:38:29 thorpej Exp $"; -#else -static char rcsid[] = "$OpenBSD: utility.c,v 1.16 2001/06/11 15:18:53 mickey Exp $"; -#endif -#endif /* not lint */ - -#include <sys/utsname.h> #define PRINTOPTIONS #include "telnetd.h" -#if defined(AUTHENTICATION) -#include <libtelnet/auth.h> -#endif -#if defined(ENCRYPTION) -#include <libtelnet/encrypt.h> -#endif + +/* RCSID("$KTH: utility.c,v 1.25 2001/05/17 00:34:42 assar Exp $"); */ /* * utility functions performing io related tasks @@ -60,60 +43,67 @@ static char rcsid[] = "$OpenBSD: utility.c,v 1.16 2001/06/11 15:18:53 mickey Exp /* * ttloop * - * A small subroutine to flush the network output buffer, get some data - * from the network, and pass it through the telnet state machine. We - * also flush the pty input buffer (by dropping its data) if it becomes - * too full. + * A small subroutine to flush the network output buffer, get some + * data from the network, and pass it through the telnet state + * machine. We also flush the pty input buffer (by dropping its data) + * if it becomes too full. + * + * return 0 if OK or 1 if interrupted by a signal. */ - void -ttloop() +int +ttloop(void) { - void netflush(); - - DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop\r\n"); - nfrontp += strlen(nfrontp);}); - if (nfrontp-nbackp) { + void netflush(void); + + DIAG(TD_REPORT, { + output_data("td: ttloop\r\n"); + }); + if (nfrontp-nbackp) netflush(); - } ncc = read(net, netibuf, sizeof netibuf); if (ncc < 0) { - syslog(LOG_INFO, "ttloop: read: %m"); + if (errno == EINTR) + return 1; + syslog(LOG_INFO, "ttloop: read: %m\n"); exit(1); } else if (ncc == 0) { - syslog(LOG_INFO, "ttloop: peer died: %m"); + syslog(LOG_INFO, "ttloop: peer died\n"); exit(1); } - DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc); - nfrontp += strlen(nfrontp);}); + DIAG(TD_REPORT, { + output_data("td: ttloop read %d chars\r\n", ncc); + }); netip = netibuf; telrcv(); /* state machine */ if (ncc > 0) { pfrontp = pbackp = ptyobuf; telrcv(); } + return 0; } /* end of ttloop */ /* * Check a descriptor to see if out of band data exists on it. */ - int -stilloob(s) - int s; /* socket number */ +int +stilloob(int s) { - struct timeval timeout; + static struct timeval timeout = { 0 }; fd_set excepts; int value; + if (s >= FD_SETSIZE) + fatal(ourpty, "fd too large"); + do { FD_ZERO(&excepts); FD_SET(s, &excepts); - memset((void *)&timeout, 0, sizeof timeout); - value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout); + value = select(s+1, 0, 0, &excepts, &timeout); } while ((value == -1) && (errno == EINTR)); if (value < 0) { - fatalperror(pty, "select"); + fatalperror(ourpty, "select"); } if (FD_ISSET(s, &excepts)) { return 1; @@ -122,26 +112,26 @@ stilloob(s) } } - void -ptyflush() +void +ptyflush(void) { - int n; - - if ((n = pfrontp - pbackp) > 0) { - DIAG((TD_REPORT | TD_PTYDATA), - { sprintf(nfrontp, "td: ptyflush %d chars\r\n", n); - nfrontp += strlen(nfrontp); }); - DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); - n = write(pty, pbackp, n); - } - if (n < 0) { - if (errno == EWOULDBLOCK || errno == EINTR) - return; - cleanup(0); - } - pbackp += n; - if (pbackp == pfrontp) - pbackp = pfrontp = ptyobuf; + int n; + + if ((n = pfrontp - pbackp) > 0) { + DIAG((TD_REPORT | TD_PTYDATA), { + output_data("td: ptyflush %d chars\r\n", n); + }); + DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); + n = write(ourpty, pbackp, n); + } + if (n < 0) { + if (errno == EWOULDBLOCK || errno == EINTR) + return; + cleanup(0); + } + pbackp += n; + if (pbackp == pfrontp) + pbackp = pfrontp = ptyobuf; } /* @@ -154,9 +144,8 @@ ptyflush() * if the current address is a TELNET IAC ("I Am a Command") * character. */ - char * -nextitem(current) - char *current; +char * +nextitem(char *current) { if ((*current&0xff) != IAC) { return current+1; @@ -167,22 +156,22 @@ nextitem(current) case WILL: case WONT: return current+3; - case SB: /* loop forever looking for the SE */ - { - register char *look = current+2; - - for (;;) { - if ((*look++&0xff) == IAC) { - if ((*look++&0xff) == SE) { - return look; - } + case SB:{ + /* loop forever looking for the SE */ + char *look = current+2; + + for (;;) { + if ((*look++&0xff) == IAC) { + if ((*look++&0xff) == SE) { + return look; } } } + } default: return current+2; } -} /* end of nextitem */ +} /* @@ -201,51 +190,52 @@ nextitem(current) * caller should be setting the urgent data pointer AFTER calling * us in any case. */ - void -netclear() +void +netclear(void) { - register char *thisitem, *next; + char *thisitem, *next; char *good; #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \ - ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)) + ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)) + #ifdef ENCRYPTION - thisitem = nclearto > netobuf ? nclearto : netobuf; + thisitem = nclearto > netobuf ? nclearto : netobuf; #else - thisitem = netobuf; + thisitem = netobuf; #endif - while ((next = nextitem(thisitem)) <= nbackp) { - thisitem = next; - } + while ((next = nextitem(thisitem)) <= nbackp) { + thisitem = next; + } - /* Now, thisitem is first before/at boundary. */ + /* Now, thisitem is first before/at boundary. */ #ifdef ENCRYPTION - good = nclearto > netobuf ? nclearto : netobuf; + good = nclearto > netobuf ? nclearto : netobuf; #else - good = netobuf; /* where the good bytes go */ + good = netobuf; /* where the good bytes go */ #endif - while (nfrontp > thisitem) { - if (wewant(thisitem)) { - int length; - - next = thisitem; - do { - next = nextitem(next); - } while (wewant(next) && (nfrontp > next)); - length = next-thisitem; - memmove((void *)good, (void *)thisitem, length); - good += length; - thisitem = next; - } else { - thisitem = nextitem(thisitem); + while (nfrontp > thisitem) { + if (wewant(thisitem)) { + int length; + + next = thisitem; + do { + next = nextitem(next); + } while (wewant(next) && (nfrontp > next)); + length = next-thisitem; + memmove(good, thisitem, length); + good += length; + thisitem = next; + } else { + thisitem = nextitem(thisitem); + } } - } - nbackp = netobuf; - nfrontp = good; /* next byte to be sent */ - neturg = 0; + nbackp = netobuf; + nfrontp = good; /* next byte to be sent */ + neturg = 0; } /* end of netclear */ /* @@ -253,18 +243,16 @@ netclear() * Send as much data as possible to the network, * handling requests for urgent data. */ - void -netflush() +void +netflush(void) { int n; extern int not42; if ((n = nfrontp - nbackp) > 0) { DIAG(TD_REPORT, - { sprintf(nfrontp, "td: netflush %d chars\r\n", n); - n += strlen(nfrontp); /* get count first */ - nfrontp += strlen(nfrontp); /* then move pointer */ - }); + { n += output_data("td: netflush %d chars\r\n", n); + }); #ifdef ENCRYPTION if (encrypt_output) { char *s = nclearto ? nclearto : nbackp; @@ -279,8 +267,11 @@ netflush() * old 4.2 client (and thus unable to survive TCP urgent data), * write the entire buffer in non-OOB mode. */ +#if 1 /* remove this to make it work between solaris 2.6 and linux */ if ((neturg == 0) || (not42 == 0)) { +#endif n = write(net, nbackp, n); /* normal write */ +#if 1 /* remove this to make it work between solaris 2.6 and linux */ } else { n = neturg - nbackp; /* @@ -297,10 +288,11 @@ netflush() n = send(net, nbackp, n, MSG_OOB); /* URGENT data */ } } +#endif } if (n < 0) { if (errno == EWOULDBLOCK || errno == EINTR) - return; + return; cleanup(0); } nbackp += n; @@ -318,7 +310,7 @@ netflush() #endif } return; -} /* end of netflush */ +} /* @@ -331,21 +323,18 @@ netflush() * ptr - A pointer to a character string to write * len - How many bytes to write */ - void -writenet(ptr, len) - register unsigned char *ptr; - register int len; +void +writenet(unsigned char *ptr, int len) { - /* flush buffer if no room for new data) */ - if ((&netobuf[BUFSIZ] - nfrontp) < len) { - /* if this fails, don't worry, buffer is a little big */ - netflush(); - } - - memmove((void *)nfrontp, (void *)ptr, len); - nfrontp += len; + /* flush buffer if no room for new data) */ + while ((&netobuf[BUFSIZ] - nfrontp) < len) { + /* if this fails, don't worry, buffer is a little big */ + netflush(); + } -} /* end of writenet */ + memmove(nfrontp, ptr, len); + nfrontp += len; +} /* @@ -353,861 +342,830 @@ writenet(ptr, len) */ - void -fatal(f, msg) - int f; - char *msg; +void fatal(int f, char *msg) { - char buf[BUFSIZ]; + char buf[BUFSIZ]; - snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg); + snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg); #ifdef ENCRYPTION - if (encrypt_output) { - /* - * Better turn off encryption first.... - * Hope it flushes... - */ - encrypt_send_end(); - netflush(); - } + if (encrypt_output) { + /* + * Better turn off encryption first.... + * Hope it flushes... + */ + encrypt_send_end(); + netflush(); + } #endif - write(f, buf, (int)strlen(buf)); - - sleep(1); /*XXX*/ - exit(1); + write(f, buf, (int)strlen(buf)); + sleep(1); /*XXX*/ + exit(1); } - void -fatalperror(f, msg) - int f; - char *msg; +void +fatalperror_errno(int f, const char *msg, int error) { - char buf[BUFSIZ], *strerror(); + char buf[BUFSIZ]; + + snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(error)); + fatal(f, buf); +} - (void) snprintf(buf, sizeof buf, "%s: %s", msg, strerror(errno)); - fatal(f, buf); +void +fatalperror(int f, const char *msg) +{ + fatalperror_errno(f, msg, errno); } -char editedhost[48]; +char editedhost[32]; - void -edithost(pat, host) - register char *pat; - register char *host; +void edithost(char *pat, char *host) { - register char *res = editedhost; + char *res = editedhost; - if (!pat) - pat = ""; - while (*pat) { - switch (*pat) { + if (!pat) + pat = ""; + while (*pat) { + switch (*pat) { - case '#': - if (*host) - host++; - break; + case '#': + if (*host) + host++; + break; - case '@': - if (*host) - *res++ = *host++; - break; + case '@': + if (*host) + *res++ = *host++; + break; - default: - *res++ = *pat; - break; - } - if (res == &editedhost[sizeof editedhost - 1]) { - *res = '\0'; - return; - } - pat++; + default: + *res++ = *pat; + break; } - if (*host) - strlcpy(res, host, sizeof editedhost - (res - editedhost)); - else - *res = '\0'; + if (res == &editedhost[sizeof editedhost - 1]) { + *res = '\0'; + return; + } + pat++; + } + if (*host) + strlcpy (res, host, + sizeof editedhost - (res - editedhost)); + else + *res = '\0'; + editedhost[sizeof editedhost - 1] = '\0'; } static char *putlocation; - void -putstr(s) - register char *s; +void +putstr(char *s) { - while (*s) - putchr(*s++); + while (*s) + putchr(*s++); } - void -putchr(cc) - int cc; +void +putchr(int cc) { - *putlocation++ = cc; + *putlocation++ = cc; } /* * This is split on two lines so that SCCS will not see the M * between two % signs and expand it... */ -static char fmtstr[] = { "%l:%M\ -%p on %A, %d %B %Y" }; +static char fmtstr[] = { "%l:%M" "%P on %A, %d %B %Y" }; - void -putf(cp, where) - register char *cp; - char *where; +void putf(char *cp, char *where) { - char *slash; - time_t t; - char db[100]; - struct utsname utsinfo; -#ifdef STREAMSPTY - extern char *strchr(); -#else - extern char *strrchr(); +#ifdef HAVE_UNAME + struct utsname name; +#endif + char *slash; + time_t t; + char db[100]; + + /* if we don't have uname, set these to sensible values */ + char *sysname = "Unix", + *machine = "", + *release = "", + *version = ""; + +#ifdef HAVE_UNAME + uname(&name); + sysname=name.sysname; + machine=name.machine; + release=name.release; + version=name.version; #endif - uname(&utsinfo); - - putlocation = where; + putlocation = where; - while (*cp) { - if (*cp != '%') { - putchr(*cp++); - continue; - } - switch (*++cp) { + while (*cp) { + if (*cp != '%') { + putchr(*cp++); + continue; + } + switch (*++cp) { - case 't': + case 't': #ifdef STREAMSPTY - /* names are like /dev/pts/2 -- we want pts/2 */ - slash = strchr(line+1, '/'); + /* names are like /dev/pts/2 -- we want pts/2 */ + slash = strchr(line+1, '/'); #else - slash = strrchr(line, '/'); + slash = strrchr(line, '/'); #endif - if (slash == (char *) 0) - putstr(line); - else - putstr(&slash[1]); - break; + if (slash == (char *) 0) + putstr(line); + else + putstr(&slash[1]); + break; - case 'h': - putstr(editedhost); - break; + case 'h': + putstr(editedhost); + break; - case 'd': - (void)time(&t); - (void)strftime(db, sizeof(db), fmtstr, localtime(&t)); - putstr(db); - break; + case 's': + putstr(sysname); + break; - case '%': - putchr('%'); - break; + case 'm': + putstr(machine); + break; - case 's': - putstr(utsinfo.sysname); - break; + case 'r': + putstr(release); + break; - case 'm': - putstr(utsinfo.machine); - break; + case 'v': + putstr(version); + break; - case 'r': - putstr(utsinfo.release); - break; + case 'd': + time(&t); + strftime(db, sizeof(db), fmtstr, localtime(&t)); + putstr(db); + break; - case 'v': - puts(utsinfo.version); - break; - } - cp++; + case '%': + putchr('%'); + break; } + cp++; + } } #ifdef DIAGNOSTICS /* * Print telnet options and commands in plain text, if possible. */ - void -printoption(fmt, option) - register char *fmt; - register int option; +void +printoption(char *fmt, int option) { - if (TELOPT_OK(option)) - sprintf(nfrontp, "%s %s\r\n", fmt, TELOPT(option)); - else if (TELCMD_OK(option)) - sprintf(nfrontp, "%s %s\r\n", fmt, TELCMD(option)); - else - sprintf(nfrontp, "%s %d\r\n", fmt, option); - nfrontp += strlen(nfrontp); - return; + if (TELOPT_OK(option)) + output_data("%s %s\r\n", + fmt, + TELOPT(option)); + else if (TELCMD_OK(option)) + output_data("%s %s\r\n", + fmt, + TELCMD(option)); + else + output_data("%s %d\r\n", + fmt, + option); + return; } - void -printsub(direction, pointer, length) - char direction; /* '<' or '>' */ - unsigned char *pointer; /* where suboption data sits */ - int length; /* length of suboption data */ +void +printsub(int direction, unsigned char *pointer, int length) + /* '<' or '>' */ + /* where suboption data sits */ + /* length of suboption data */ { - register int i = 0; - char buf[512]; - - if (!(diagnostic & TD_OPTIONS)) - return; - - if (direction) { - sprintf(nfrontp, "td: %s suboption ", - direction == '<' ? "recv" : "send"); - nfrontp += strlen(nfrontp); - if (length >= 3) { - register int j; - - i = pointer[length-2]; - j = pointer[length-1]; - - if (i != IAC || j != SE) { - sprintf(nfrontp, "(terminated by "); - nfrontp += strlen(nfrontp); - if (TELOPT_OK(i)) - sprintf(nfrontp, "%s ", TELOPT(i)); - else if (TELCMD_OK(i)) - sprintf(nfrontp, "%s ", TELCMD(i)); - else - sprintf(nfrontp, "%d ", i); - nfrontp += strlen(nfrontp); - if (TELOPT_OK(j)) - sprintf(nfrontp, "%s", TELOPT(j)); - else if (TELCMD_OK(j)) - sprintf(nfrontp, "%s", TELCMD(j)); - else - sprintf(nfrontp, "%d", j); - nfrontp += strlen(nfrontp); - sprintf(nfrontp, ", not IAC SE!) "); - nfrontp += strlen(nfrontp); - } + int i = 0; + unsigned char buf[512]; + + if (!(diagnostic & TD_OPTIONS)) + return; + + if (direction) { + output_data("td: %s suboption ", + direction == '<' ? "recv" : "send"); + if (length >= 3) { + int j; + + i = pointer[length-2]; + j = pointer[length-1]; + + if (i != IAC || j != SE) { + output_data("(terminated by "); + if (TELOPT_OK(i)) + output_data("%s ", + TELOPT(i)); + else if (TELCMD_OK(i)) + output_data("%s ", + TELCMD(i)); + else + output_data("%d ", + i); + if (TELOPT_OK(j)) + output_data("%s", + TELOPT(j)); + else if (TELCMD_OK(j)) + output_data("%s", + TELCMD(j)); + else + output_data("%d", + j); + output_data(", not IAC SE!) "); } - length -= 2; } - if (length < 1) { - sprintf(nfrontp, "(Empty suboption??\?)"); - nfrontp += strlen(nfrontp); - return; + length -= 2; + } + if (length < 1) { + output_data("(Empty suboption??\?)"); + return; + } + switch (pointer[0]) { + case TELOPT_TTYPE: + output_data("TERMINAL-TYPE "); + switch (pointer[1]) { + case TELQUAL_IS: + output_data("IS \"%.*s\"", + length-2, + (char *)pointer+2); + break; + case TELQUAL_SEND: + output_data("SEND"); + break; + default: + output_data("- unknown qualifier %d (0x%x).", + pointer[1], pointer[1]); } - switch (pointer[0]) { - case TELOPT_TTYPE: - sprintf(nfrontp, "TERMINAL-TYPE "); - nfrontp += strlen(nfrontp); - switch (pointer[1]) { - case TELQUAL_IS: - sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); - break; - case TELQUAL_SEND: - sprintf(nfrontp, "SEND"); - break; - default: - sprintf(nfrontp, - "- unknown qualifier %d (0x%x).", - pointer[1], pointer[1]); + break; + case TELOPT_TSPEED: + output_data("TERMINAL-SPEED"); + if (length < 2) { + output_data(" (empty suboption??\?)"); + break; + } + switch (pointer[1]) { + case TELQUAL_IS: + output_data(" IS %.*s", length-2, (char *)pointer+2); + break; + default: + if (pointer[1] == 1) + output_data(" SEND"); + else + output_data(" %d (unknown)", pointer[1]); + for (i = 2; i < length; i++) { + output_data(" ?%d?", pointer[i]); } - nfrontp += strlen(nfrontp); break; - case TELOPT_TSPEED: - sprintf(nfrontp, "TERMINAL-SPEED"); - nfrontp += strlen(nfrontp); - if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + } + break; + + case TELOPT_LFLOW: + output_data("TOGGLE-FLOW-CONTROL"); + if (length < 2) { + output_data(" (empty suboption??\?)"); + break; + } + switch (pointer[1]) { + case LFLOW_OFF: + output_data(" OFF"); + break; + case LFLOW_ON: + output_data(" ON"); + break; + case LFLOW_RESTART_ANY: + output_data(" RESTART-ANY"); + break; + case LFLOW_RESTART_XON: + output_data(" RESTART-XON"); + break; + default: + output_data(" %d (unknown)", + pointer[1]); + } + for (i = 2; i < length; i++) { + output_data(" ?%d?", + pointer[i]); + } + break; + + case TELOPT_NAWS: + output_data("NAWS"); + if (length < 2) { + output_data(" (empty suboption??\?)"); + break; + } + if (length == 2) { + output_data(" ?%d?", + pointer[1]); + break; + } + output_data(" %u %u(%u)", + pointer[1], + pointer[2], + (((unsigned int)pointer[1])<<8) + pointer[2]); + if (length == 4) { + output_data(" ?%d?", + pointer[3]); + break; + } + output_data(" %u %u(%u)", + pointer[3], + pointer[4], + (((unsigned int)pointer[3])<<8) + pointer[4]); + for (i = 5; i < length; i++) { + output_data(" ?%d?", + pointer[i]); + } + break; + + case TELOPT_LINEMODE: + output_data("LINEMODE "); + if (length < 2) { + output_data(" (empty suboption??\?)"); + break; + } + switch (pointer[1]) { + case WILL: + output_data("WILL "); + goto common; + case WONT: + output_data("WONT "); + goto common; + case DO: + output_data("DO "); + goto common; + case DONT: + output_data("DONT "); + common: + if (length < 3) { + output_data("(no option??\?)"); break; } - switch (pointer[1]) { - case TELQUAL_IS: - sprintf(nfrontp, " IS %.*s", length-2, (char *)pointer+2); - nfrontp += strlen(nfrontp); + switch (pointer[2]) { + case LM_FORWARDMASK: + output_data("Forward Mask"); + for (i = 3; i < length; i++) { + output_data(" %x", pointer[i]); + } break; default: - if (pointer[1] == 1) - sprintf(nfrontp, " SEND"); - else - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data("%d (unknown)", + pointer[2]); + for (i = 3; i < length; i++) { + output_data(" %d", + pointer[i]); } break; } break; - case TELOPT_LFLOW: - sprintf(nfrontp, "TOGGLE-FLOW-CONTROL"); - nfrontp += strlen(nfrontp); - if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); - break; - } - switch (pointer[1]) { - case LFLOW_OFF: - sprintf(nfrontp, " OFF"); break; - case LFLOW_ON: - sprintf(nfrontp, " ON"); break; - case LFLOW_RESTART_ANY: - sprintf(nfrontp, " RESTART-ANY"); break; - case LFLOW_RESTART_XON: - sprintf(nfrontp, " RESTART-XON"); break; - default: - sprintf(nfrontp, " %d (unknown)", pointer[1]); + case LM_SLC: + output_data("SLC"); + for (i = 2; i < length - 2; i += 3) { + if (SLC_NAME_OK(pointer[i+SLC_FUNC])) + output_data(" %s", + SLC_NAME(pointer[i+SLC_FUNC])); + else + output_data(" %d", + pointer[i+SLC_FUNC]); + switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) { + case SLC_NOSUPPORT: + output_data(" NOSUPPORT"); + break; + case SLC_CANTCHANGE: + output_data(" CANTCHANGE"); + break; + case SLC_VARIABLE: + output_data(" VARIABLE"); + break; + case SLC_DEFAULT: + output_data(" DEFAULT"); + break; + } + output_data("%s%s%s", + pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "", + pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "", + pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : ""); + if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN| + SLC_FLUSHOUT| SLC_LEVELBITS)) { + output_data("(0x%x)", + pointer[i+SLC_FLAGS]); + } + output_data(" %d;", + pointer[i+SLC_VALUE]); + if ((pointer[i+SLC_VALUE] == IAC) && + (pointer[i+SLC_VALUE+1] == IAC)) + i++; } - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + for (; i < length; i++) { + output_data(" ?%d?", + pointer[i]); } break; - case TELOPT_NAWS: - sprintf(nfrontp, "NAWS"); - nfrontp += strlen(nfrontp); - if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + case LM_MODE: + output_data("MODE "); + if (length < 3) { + output_data("(no mode??\?)"); break; } - if (length == 2) { - sprintf(nfrontp, " ?%d?", pointer[1]); - nfrontp += strlen(nfrontp); - break; + { + char tbuf[32]; + snprintf(tbuf, + sizeof(tbuf), + "%s%s%s%s%s", + pointer[2]&MODE_EDIT ? "|EDIT" : "", + pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "", + pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "", + pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "", + pointer[2]&MODE_ACK ? "|ACK" : ""); + output_data("%s", + tbuf[1] ? &tbuf[1] : "0"); } - sprintf(nfrontp, " %d %d (%d)", - pointer[1], pointer[2], - (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2]))); - nfrontp += strlen(nfrontp); - if (length == 4) { - sprintf(nfrontp, " ?%d?", pointer[3]); - nfrontp += strlen(nfrontp); - break; + if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) { + output_data(" (0x%x)", + pointer[2]); } - sprintf(nfrontp, " %d %d (%d)", - pointer[3], pointer[4], - (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4]))); - nfrontp += strlen(nfrontp); - for (i = 5; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + for (i = 3; i < length; i++) { + output_data(" ?0x%x?", + pointer[i]); } break; - - case TELOPT_LINEMODE: - sprintf(nfrontp, "LINEMODE "); - nfrontp += strlen(nfrontp); - if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); - break; + default: + output_data("%d (unknown)", + pointer[1]); + for (i = 2; i < length; i++) { + output_data(" %d", pointer[i]); } - switch (pointer[1]) { - case WILL: - sprintf(nfrontp, "WILL "); - goto common; - case WONT: - sprintf(nfrontp, "WONT "); - goto common; - case DO: - sprintf(nfrontp, "DO "); - goto common; - case DONT: - sprintf(nfrontp, "DONT "); - common: - nfrontp += strlen(nfrontp); - if (length < 3) { - sprintf(nfrontp, "(no option??\?)"); - nfrontp += strlen(nfrontp); - break; - } - switch (pointer[2]) { - case LM_FORWARDMASK: - sprintf(nfrontp, "Forward Mask"); - nfrontp += strlen(nfrontp); - for (i = 3; i < length; i++) { - sprintf(nfrontp, " %x", pointer[i]); - nfrontp += strlen(nfrontp); - } - break; - default: - sprintf(nfrontp, "%d (unknown)", pointer[2]); - nfrontp += strlen(nfrontp); - for (i = 3; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } - break; - } - break; + } + break; - case LM_SLC: - sprintf(nfrontp, "SLC"); - nfrontp += strlen(nfrontp); - for (i = 2; i < length - 2; i += 3) { - if (SLC_NAME_OK(pointer[i+SLC_FUNC])) - sprintf(nfrontp, " %s", SLC_NAME(pointer[i+SLC_FUNC])); - else - sprintf(nfrontp, " %d", pointer[i+SLC_FUNC]); - nfrontp += strlen(nfrontp); - switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) { - case SLC_NOSUPPORT: - sprintf(nfrontp, " NOSUPPORT"); break; - case SLC_CANTCHANGE: - sprintf(nfrontp, " CANTCHANGE"); break; - case SLC_VARIABLE: - sprintf(nfrontp, " VARIABLE"); break; - case SLC_DEFAULT: - sprintf(nfrontp, " DEFAULT"); break; - } - nfrontp += strlen(nfrontp); - sprintf(nfrontp, "%s%s%s", - pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "", - pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "", - pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : ""); - nfrontp += strlen(nfrontp); - if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN| - SLC_FLUSHOUT| SLC_LEVELBITS)) { - sprintf(nfrontp, "(0x%x)", pointer[i+SLC_FLAGS]); - nfrontp += strlen(nfrontp); - } - sprintf(nfrontp, " %d;", pointer[i+SLC_VALUE]); - nfrontp += strlen(nfrontp); - if ((pointer[i+SLC_VALUE] == IAC) && - (pointer[i+SLC_VALUE+1] == IAC)) - i++; - } - for (; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } - break; + case TELOPT_STATUS: { + char *cp; + int j, k; - case LM_MODE: - sprintf(nfrontp, "MODE "); - nfrontp += strlen(nfrontp); - if (length < 3) { - sprintf(nfrontp, "(no mode??\?)"); - nfrontp += strlen(nfrontp); - break; - } - { - char tbuf[32]; - sprintf(tbuf, "%s%s%s%s%s", - pointer[2]&MODE_EDIT ? "|EDIT" : "", - pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "", - pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "", - pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "", - pointer[2]&MODE_ACK ? "|ACK" : ""); - sprintf(nfrontp, "%s", tbuf[1] ? &tbuf[1] : "0"); - nfrontp += strlen(nfrontp); - } - if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) { - sprintf(nfrontp, " (0x%x)", pointer[2]); - nfrontp += strlen(nfrontp); - } - for (i = 3; i < length; i++) { - sprintf(nfrontp, " ?0x%x?", pointer[i]); - nfrontp += strlen(nfrontp); - } - break; - default: - sprintf(nfrontp, "%d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } + output_data("STATUS"); + + switch (pointer[1]) { + default: + if (pointer[1] == TELQUAL_SEND) + output_data(" SEND"); + else + output_data(" %d (unknown)", + pointer[1]); + for (i = 2; i < length; i++) { + output_data(" ?%d?", + pointer[i]); } break; + case TELQUAL_IS: + output_data(" IS\r\n"); - case TELOPT_STATUS: { - register char *cp; - register int j, k; - - sprintf(nfrontp, "STATUS"); - nfrontp += strlen(nfrontp); - - switch (pointer[1]) { - default: - if (pointer[1] == TELQUAL_SEND) - sprintf(nfrontp, " SEND"); + for (i = 2; i < length; i++) { + switch(pointer[i]) { + case DO: cp = "DO"; goto common2; + case DONT: cp = "DONT"; goto common2; + case WILL: cp = "WILL"; goto common2; + case WONT: cp = "WONT"; goto common2; + common2: + i++; + if (TELOPT_OK(pointer[i])) + output_data(" %s %s", + cp, + TELOPT(pointer[i])); else - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } + output_data(" %s %d", + cp, + pointer[i]); + + output_data("\r\n"); break; - case TELQUAL_IS: - sprintf(nfrontp, " IS\r\n"); - nfrontp += strlen(nfrontp); - - for (i = 2; i < length; i++) { - switch(pointer[i]) { - case DO: cp = "DO"; goto common2; - case DONT: cp = "DONT"; goto common2; - case WILL: cp = "WILL"; goto common2; - case WONT: cp = "WONT"; goto common2; - common2: - i++; - if (TELOPT_OK(pointer[i])) - sprintf(nfrontp, " %s %s", cp, TELOPT(pointer[i])); - else - sprintf(nfrontp, " %s %d", cp, pointer[i]); - nfrontp += strlen(nfrontp); - - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); - break; - case SB: - sprintf(nfrontp, " SB "); - nfrontp += strlen(nfrontp); - i++; - j = k = i; - while (j < length) { - if (pointer[j] == SE) { - if (j+1 == length) - break; - if (pointer[j+1] == SE) - j++; - else - break; - } - pointer[k++] = pointer[j++]; + case SB: + output_data(" SB "); + i++; + j = k = i; + while (j < length) { + if (pointer[j] == SE) { + if (j+1 == length) + break; + if (pointer[j+1] == SE) + j++; + else + break; } - printsub(0, &pointer[i], k - i); - if (i < length) { - sprintf(nfrontp, " SE"); - nfrontp += strlen(nfrontp); - i = j; - } else - i = j - 1; + pointer[k++] = pointer[j++]; + } + printsub(0, &pointer[i], k - i); + if (i < length) { + output_data(" SE"); + i = j; + } else + i = j - 1; - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + output_data("\r\n"); - break; + break; - default: - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - break; - } + default: + output_data(" %d", + pointer[i]); + break; } - break; } break; - } - - case TELOPT_XDISPLOC: - sprintf(nfrontp, "X-DISPLAY-LOCATION "); - nfrontp += strlen(nfrontp); - switch (pointer[1]) { - case TELQUAL_IS: - sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); - break; - case TELQUAL_SEND: - sprintf(nfrontp, "SEND"); - break; - default: - sprintf(nfrontp, "- unknown qualifier %d (0x%x).", - pointer[1], pointer[1]); - } - nfrontp += strlen(nfrontp); + } + break; + } + + case TELOPT_XDISPLOC: + output_data("X-DISPLAY-LOCATION "); + switch (pointer[1]) { + case TELQUAL_IS: + output_data("IS \"%.*s\"", + length-2, + (char *)pointer+2); break; + case TELQUAL_SEND: + output_data("SEND"); + break; + default: + output_data("- unknown qualifier %d (0x%x).", + pointer[1], pointer[1]); + } + break; + + case TELOPT_NEW_ENVIRON: + output_data("NEW-ENVIRON "); + goto env_common1; + case TELOPT_OLD_ENVIRON: + output_data("OLD-ENVIRON"); + env_common1: + switch (pointer[1]) { + case TELQUAL_IS: + output_data("IS "); + goto env_common; + case TELQUAL_SEND: + output_data("SEND "); + goto env_common; + case TELQUAL_INFO: + output_data("INFO "); + env_common: + { + int noquote = 2; + for (i = 2; i < length; i++ ) { + switch (pointer[i]) { + case NEW_ENV_VAR: + output_data("\" VAR " + noquote); + noquote = 2; + break; - case TELOPT_NEW_ENVIRON: - sprintf(nfrontp, "NEW-ENVIRON "); - goto env_common1; - case TELOPT_OLD_ENVIRON: - sprintf(nfrontp, "OLD-ENVIRON"); - env_common1: - nfrontp += strlen(nfrontp); - switch (pointer[1]) { - case TELQUAL_IS: - sprintf(nfrontp, "IS "); - goto env_common; - case TELQUAL_SEND: - sprintf(nfrontp, "SEND "); - goto env_common; - case TELQUAL_INFO: - sprintf(nfrontp, "INFO "); - env_common: - nfrontp += strlen(nfrontp); - { - register int noquote = 2; - for (i = 2; i < length; i++ ) { - switch (pointer[i]) { - case NEW_ENV_VAR: - sprintf(nfrontp, "\" VAR " + noquote); - nfrontp += strlen(nfrontp); - noquote = 2; - break; + case NEW_ENV_VALUE: + output_data("\" VALUE " + noquote); + noquote = 2; + break; - case NEW_ENV_VALUE: - sprintf(nfrontp, "\" VALUE " + noquote); - nfrontp += strlen(nfrontp); - noquote = 2; - break; + case ENV_ESC: + output_data("\" ESC " + noquote); + noquote = 2; + break; - case ENV_ESC: - sprintf(nfrontp, "\" ESC " + noquote); - nfrontp += strlen(nfrontp); - noquote = 2; - break; + case ENV_USERVAR: + output_data("\" USERVAR " + noquote); + noquote = 2; + break; - case ENV_USERVAR: - sprintf(nfrontp, "\" USERVAR " + noquote); - nfrontp += strlen(nfrontp); - noquote = 2; - break; - - default: - if (isprint(pointer[i]) && pointer[i] != '"') { - if (noquote) { - *nfrontp++ = '"'; - noquote = 0; - } - *nfrontp++ = pointer[i]; - } else { - sprintf(nfrontp, "\" %03o " + noquote, - pointer[i]); - nfrontp += strlen(nfrontp); - noquote = 2; + default: + if (isprint(pointer[i]) && pointer[i] != '"') { + if (noquote) { + output_data ("\""); + noquote = 0; } - break; + output_data ("%c", pointer[i]); + } else { + output_data("\" %03o " + noquote, + pointer[i]); + noquote = 2; } + break; } - if (!noquote) - *nfrontp++ = '"'; - break; } + if (!noquote) + output_data ("\""); + break; } - break; + } + break; -#if defined(AUTHENTICATION) - case TELOPT_AUTHENTICATION: - sprintf(nfrontp, "AUTHENTICATION"); - nfrontp += strlen(nfrontp); +#ifdef AUTHENTICATION + case TELOPT_AUTHENTICATION: + output_data("AUTHENTICATION"); - if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + if (length < 2) { + output_data(" (empty suboption??\?)"); + break; + } + switch (pointer[1]) { + case TELQUAL_REPLY: + case TELQUAL_IS: + output_data(" %s ", + (pointer[1] == TELQUAL_IS) ? + "IS" : "REPLY"); + if (AUTHTYPE_NAME_OK(pointer[2])) + output_data("%s ", + AUTHTYPE_NAME(pointer[2])); + else + output_data("%d ", + pointer[2]); + if (length < 3) { + output_data("(partial suboption??\?)"); break; } - switch (pointer[1]) { - case TELQUAL_REPLY: - case TELQUAL_IS: - sprintf(nfrontp, " %s ", (pointer[1] == TELQUAL_IS) ? - "IS" : "REPLY"); - nfrontp += strlen(nfrontp); - if (AUTHTYPE_NAME_OK(pointer[2])) - sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[2])); - else - sprintf(nfrontp, "%d ", pointer[2]); - nfrontp += strlen(nfrontp); - if (length < 3) { - sprintf(nfrontp, "(partial suboption??\?)"); - nfrontp += strlen(nfrontp); - break; - } - sprintf(nfrontp, "%s|%s", + output_data("%s|%s", ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? "CLIENT" : "SERVER", ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? "MUTUAL" : "ONE-WAY"); - nfrontp += strlen(nfrontp); - auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); - sprintf(nfrontp, "%s", buf); - nfrontp += strlen(nfrontp); - break; + auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); + output_data("%s", + buf); + break; - case TELQUAL_SEND: - i = 2; - sprintf(nfrontp, " SEND "); - nfrontp += strlen(nfrontp); - while (i < length) { - if (AUTHTYPE_NAME_OK(pointer[i])) - sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[i])); - else - sprintf(nfrontp, "%d ", pointer[i]); - nfrontp += strlen(nfrontp); - if (++i >= length) { - sprintf(nfrontp, "(partial suboption??\?)"); - nfrontp += strlen(nfrontp); - break; - } - sprintf(nfrontp, "%s|%s ", - ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? - "CLIENT" : "SERVER", - ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? - "MUTUAL" : "ONE-WAY"); - nfrontp += strlen(nfrontp); - ++i; + case TELQUAL_SEND: + i = 2; + output_data(" SEND "); + while (i < length) { + if (AUTHTYPE_NAME_OK(pointer[i])) + output_data("%s ", + AUTHTYPE_NAME(pointer[i])); + else + output_data("%d ", + pointer[i]); + if (++i >= length) { + output_data("(partial suboption??\?)"); + break; } - break; + output_data("%s|%s ", + ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? + "CLIENT" : "SERVER", + ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? + "MUTUAL" : "ONE-WAY"); + ++i; + } + break; - case TELQUAL_NAME: - i = 2; - sprintf(nfrontp, " NAME \""); - nfrontp += strlen(nfrontp); - while (i < length) - *nfrontp += pointer[i++]; - *nfrontp += '"'; - break; + case TELQUAL_NAME: + i = 2; + output_data(" NAME \"%.*s\"", + length - 2, + pointer); + break; - default: - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } - break; + default: + for (i = 2; i < length; i++) { + output_data(" ?%d?", + pointer[i]); } break; + } + break; #endif #ifdef ENCRYPTION - case TELOPT_ENCRYPT: - output_data("ENCRYPT"); - if (length < 2) { - output_data(" (empty suboption?)"); + case TELOPT_ENCRYPT: + output_data("ENCRYPT"); + if (length < 2) { + output_data(" (empty suboption?)"); + break; + } + switch (pointer[1]) { + case ENCRYPT_START: + output_data(" START"); + break; + + case ENCRYPT_END: + output_data(" END"); + break; + + case ENCRYPT_REQSTART: + output_data(" REQUEST-START"); + break; + + case ENCRYPT_REQEND: + output_data(" REQUEST-END"); + break; + + case ENCRYPT_IS: + case ENCRYPT_REPLY: + output_data(" %s ", + (pointer[1] == ENCRYPT_IS) ? + "IS" : "REPLY"); + if (length < 3) { + output_data(" (partial suboption?)"); break; } - switch (pointer[1]) { - case ENCRYPT_START: - output_data(" START"); - break; - - case ENCRYPT_END: - output_data(" END"); - break; - - case ENCRYPT_REQSTART: - output_data(" REQUEST-START"); - break; + if (ENCTYPE_NAME_OK(pointer[2])) + output_data("%s ", + ENCTYPE_NAME(pointer[2])); + else + output_data(" %d (unknown)", + pointer[2]); - case ENCRYPT_REQEND: - output_data(" REQUEST-END"); - break; - - case ENCRYPT_IS: - case ENCRYPT_REPLY: - output_data(" %s ", - (pointer[1] == ENCRYPT_IS) ? - "IS" : "REPLY"); - if (length < 3) { - output_data(" (partial suboption?)"); - break; - } - if (ENCTYPE_NAME_OK(pointer[2])) + encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); + output_data("%s", + buf); + break; + + case ENCRYPT_SUPPORT: + i = 2; + output_data(" SUPPORT "); + while (i < length) { + if (ENCTYPE_NAME_OK(pointer[i])) output_data("%s ", - ENCTYPE_NAME(pointer[2])); + ENCTYPE_NAME(pointer[i])); else - output_data(" %d (unknown)", - pointer[2]); - - encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); - output_data("%s", - buf); - break; - - case ENCRYPT_SUPPORT: - i = 2; - output_data(" SUPPORT "); - while (i < length) { - if (ENCTYPE_NAME_OK(pointer[i])) - output_data("%s ", - ENCTYPE_NAME(pointer[i])); - else - output_data("%d ", - pointer[i]); - i++; - } - break; - - case ENCRYPT_ENC_KEYID: - output_data(" ENC_KEYID %d", pointer[1]); - goto encommon; - - case ENCRYPT_DEC_KEYID: - output_data(" DEC_KEYID %d", pointer[1]); - goto encommon; - - default: - output_data(" %d (unknown)", pointer[1]); - encommon: - for (i = 2; i < length; i++) { - output_data(" %d", pointer[i]); - } - break; + output_data("%d ", + pointer[i]); + i++; } break; -#endif /* ENCRYPTION */ + + case ENCRYPT_ENC_KEYID: + output_data(" ENC_KEYID %d", pointer[1]); + goto encommon; + + case ENCRYPT_DEC_KEYID: + output_data(" DEC_KEYID %d", pointer[1]); + goto encommon; default: - if (TELOPT_OK(pointer[0])) - sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0])); - else - sprintf(nfrontp, "%d (unknown)", pointer[i]); - nfrontp += strlen(nfrontp); - for (i = 1; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %d (unknown)", pointer[1]); + encommon: + for (i = 2; i < length; i++) { + output_data(" %d", pointer[i]); } break; } - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + break; +#endif + + default: + if (TELOPT_OK(pointer[0])) + output_data("%s (unknown)", + TELOPT(pointer[0])); + else + output_data("%d (unknown)", + pointer[i]); + for (i = 1; i < length; i++) { + output_data(" %d", pointer[i]); + } + break; + } + output_data("\r\n"); } /* * Dump a data buffer in hex and ascii to the output data stream. */ - void -printdata(tag, ptr, cnt) - register char *tag; - register char *ptr; - register int cnt; +void +printdata(char *tag, char *ptr, int cnt) { - register int i; - char xbuf[30]; + int i; + char xbuf[30]; - while (cnt) { - /* flush net output buffer if no room for new data) */ - if ((&netobuf[BUFSIZ] - nfrontp) < 80) { - netflush(); - } + while (cnt) { + /* flush net output buffer if no room for new data) */ + if ((&netobuf[BUFSIZ] - nfrontp) < 80) { + netflush(); + } - /* add a line of output */ - sprintf(nfrontp, "%s: ", tag); - nfrontp += strlen(nfrontp); - for (i = 0; i < 20 && cnt; i++) { - sprintf(nfrontp, "%02x", *ptr); - nfrontp += strlen(nfrontp); - if (isprint(*ptr)) { - xbuf[i] = *ptr; - } else { - xbuf[i] = '.'; - } - if (i % 2) { - *nfrontp = ' '; - nfrontp++; - } - cnt--; - ptr++; - } - xbuf[i] = '\0'; - sprintf(nfrontp, " %s\r\n", xbuf ); - nfrontp += strlen(nfrontp); + /* add a line of output */ + output_data("%s: ", tag); + for (i = 0; i < 20 && cnt; i++) { + output_data("%02x", *ptr); + if (isprint(*ptr)) { + xbuf[i] = *ptr; + } else { + xbuf[i] = '.'; + } + if (i % 2) { + output_data(" "); + } + cnt--; + ptr++; } + xbuf[i] = '\0'; + output_data(" %s\r\n", xbuf); + } } #endif /* DIAGNOSTICS */ |