Path: blob/main/crypto/heimdal/appl/telnet/telnetd/utility.c
34878 views
/*1* Copyright (c) 1989, 19932* The Regents of the University of California. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. All advertising materials mentioning features or use of this software13* must display the following acknowledgement:14* This product includes software developed by the University of15* California, Berkeley and its contributors.16* 4. Neither the name of the University nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#define PRINTOPTIONS34#include "telnetd.h"3536RCSID("$Id$");3738/*39* utility functions performing io related tasks40*/4142/*43* ttloop44*45* A small subroutine to flush the network output buffer, get some46* data from the network, and pass it through the telnet state47* machine. We also flush the pty input buffer (by dropping its data)48* if it becomes too full.49*50* return 0 if OK or 1 if interrupted by a signal.51*/5253int54ttloop(void)55{56DIAG(TD_REPORT, {57output_data("td: ttloop\r\n");58});59if (nfrontp-nbackp)60netflush();61ncc = read(net, netibuf, sizeof netibuf);62if (ncc < 0) {63if (errno == EINTR)64return 1;65syslog(LOG_INFO, "ttloop: read: %m\n");66exit(1);67} else if (ncc == 0) {68syslog(LOG_INFO, "ttloop: peer died\n");69exit(1);70}71DIAG(TD_REPORT, {72output_data("td: ttloop read %d chars\r\n", ncc);73});74netip = netibuf;75telrcv(); /* state machine */76if (ncc > 0) {77pfrontp = pbackp = ptyobuf;78telrcv();79}80return 0;81} /* end of ttloop */8283/*84* Check a descriptor to see if out of band data exists on it.85*/86int87stilloob(int s)88{89static struct timeval timeout = { 0 };90fd_set excepts;91int value;9293if (s >= FD_SETSIZE)94fatal(ourpty, "fd too large");9596do {97FD_ZERO(&excepts);98FD_SET(s, &excepts);99value = select(s+1, 0, 0, &excepts, &timeout);100} while ((value == -1) && (errno == EINTR));101102if (value < 0) {103fatalperror(ourpty, "select");104}105if (FD_ISSET(s, &excepts)) {106return 1;107} else {108return 0;109}110}111112void113ptyflush(void)114{115int n;116117if ((n = pfrontp - pbackp) > 0) {118DIAG((TD_REPORT | TD_PTYDATA), {119output_data("td: ptyflush %d chars\r\n", n);120});121DIAG(TD_PTYDATA, printdata("pd", pbackp, n));122n = write(ourpty, pbackp, n);123}124if (n < 0) {125if (errno == EWOULDBLOCK || errno == EINTR)126return;127cleanup(0);128}129pbackp += n;130if (pbackp == pfrontp)131pbackp = pfrontp = ptyobuf;132}133134/*135* nextitem()136*137* Return the address of the next "item" in the TELNET data138* stream. This will be the address of the next character if139* the current address is a user data character, or it will140* be the address of the character following the TELNET command141* if the current address is a TELNET IAC ("I Am a Command")142* character.143*/144char *145nextitem(char *current)146{147if ((*current&0xff) != IAC) {148return current+1;149}150switch (*(current+1)&0xff) {151case DO:152case DONT:153case WILL:154case WONT:155return current+3;156case SB:{157/* loop forever looking for the SE */158char *look = current+2;159160for (;;) {161if ((*look++&0xff) == IAC) {162if ((*look++&0xff) == SE) {163return look;164}165}166}167}168default:169return current+2;170}171}172173174/*175* netclear()176*177* We are about to do a TELNET SYNCH operation. Clear178* the path to the network.179*180* Things are a bit tricky since we may have sent the first181* byte or so of a previous TELNET command into the network.182* So, we have to scan the network buffer from the beginning183* until we are up to where we want to be.184*185* A side effect of what we do, just to keep things186* simple, is to clear the urgent data pointer. The principal187* caller should be setting the urgent data pointer AFTER calling188* us in any case.189*/190void191netclear(void)192{193char *thisitem, *next;194char *good;195#define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \196((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))197198#ifdef ENCRYPTION199thisitem = nclearto > netobuf ? nclearto : netobuf;200#else201thisitem = netobuf;202#endif203204while ((next = nextitem(thisitem)) <= nbackp) {205thisitem = next;206}207208/* Now, thisitem is first before/at boundary. */209210#ifdef ENCRYPTION211good = nclearto > netobuf ? nclearto : netobuf;212#else213good = netobuf; /* where the good bytes go */214#endif215216while (nfrontp > thisitem) {217if (wewant(thisitem)) {218int length;219220next = thisitem;221do {222next = nextitem(next);223} while (wewant(next) && (nfrontp > next));224length = next-thisitem;225memmove(good, thisitem, length);226good += length;227thisitem = next;228} else {229thisitem = nextitem(thisitem);230}231}232233nbackp = netobuf;234nfrontp = good; /* next byte to be sent */235neturg = 0;236} /* end of netclear */237238extern int not42;239240/*241* netflush242* Send as much data as possible to the network,243* handling requests for urgent data.244*/245void246netflush(void)247{248int n;249250if ((n = nfrontp - nbackp) > 0) {251DIAG(TD_REPORT,252{ n += output_data("td: netflush %d chars\r\n", n);253});254#ifdef ENCRYPTION255if (encrypt_output) {256char *s = nclearto ? nclearto : nbackp;257if (nfrontp - s > 0) {258(*encrypt_output)((unsigned char *)s, nfrontp-s);259nclearto = nfrontp;260}261}262#endif263/*264* if no urgent data, or if the other side appears to be an265* old 4.2 client (and thus unable to survive TCP urgent data),266* write the entire buffer in non-OOB mode.267*/268#if 1 /* remove this to make it work between solaris 2.6 and linux */269if ((neturg == 0) || (not42 == 0)) {270#endif271n = write(net, nbackp, n); /* normal write */272#if 1 /* remove this to make it work between solaris 2.6 and linux */273} else {274n = neturg - nbackp;275/*276* In 4.2 (and 4.3) systems, there is some question about277* what byte in a sendOOB operation is the "OOB" data.278* To make ourselves compatible, we only send ONE byte279* out of band, the one WE THINK should be OOB (though280* we really have more the TCP philosophy of urgent data281* rather than the Unix philosophy of OOB data).282*/283if (n > 1) {284n = send(net, nbackp, n-1, 0); /* send URGENT all by itself */285} else {286n = send(net, nbackp, n, MSG_OOB); /* URGENT data */287}288}289#endif290}291if (n < 0) {292if (errno == EWOULDBLOCK || errno == EINTR)293return;294cleanup(0);295}296nbackp += n;297#ifdef ENCRYPTION298if (nbackp > nclearto)299nclearto = 0;300#endif301if (nbackp >= neturg) {302neturg = 0;303}304if (nbackp == nfrontp) {305nbackp = nfrontp = netobuf;306#ifdef ENCRYPTION307nclearto = 0;308#endif309}310return;311}312313314/*315* writenet316*317* Just a handy little function to write a bit of raw data to the net.318* It will force a transmit of the buffer if necessary319*320* arguments321* ptr - A pointer to a character string to write322* len - How many bytes to write323*/324void325writenet(const void *ptr, size_t len)326{327/* flush buffer if no room for new data) */328while ((&netobuf[BUFSIZ] - nfrontp) < len) {329/* if this fails, don't worry, buffer is a little big */330netflush();331}332if ((&netobuf[BUFSIZ] - nfrontp) < len)333abort();334335memmove(nfrontp, ptr, len);336nfrontp += len;337}338339340/*341* miscellaneous functions doing a variety of little jobs follow ...342*/343344345void fatal(int f, char *msg)346{347char buf[BUFSIZ];348349snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg);350#ifdef ENCRYPTION351if (encrypt_output) {352/*353* Better turn off encryption first....354* Hope it flushes...355*/356encrypt_send_end();357netflush();358}359#endif360write(f, buf, (int)strlen(buf));361sleep(1); /*XXX*/362exit(1);363}364365void366fatalperror_errno(int f, const char *msg, int error)367{368char buf[BUFSIZ];369370snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(error));371fatal(f, buf);372}373374void375fatalperror(int f, const char *msg)376{377fatalperror_errno(f, msg, errno);378}379380char editedhost[32];381382void edithost(char *pat, char *host)383{384char *res = editedhost;385386if (!pat)387pat = "";388while (*pat) {389switch (*pat) {390391case '#':392if (*host)393host++;394break;395396case '@':397if (*host)398*res++ = *host++;399break;400401default:402*res++ = *pat;403break;404}405if (res == &editedhost[sizeof editedhost - 1]) {406*res = '\0';407return;408}409pat++;410}411if (*host)412strlcpy (res, host,413sizeof editedhost - (res - editedhost));414else415*res = '\0';416editedhost[sizeof editedhost - 1] = '\0';417}418419static char *putlocation;420421void422putstr(char *s)423{424425while (*s)426putchr(*s++);427}428429void430putchr(int cc)431{432*putlocation++ = cc;433}434435static char fmtstr[] = { "%l:%M%P on %A, %d %B %Y" };436437void putf(char *cp, char *where)438{439#ifdef HAVE_UNAME440struct utsname name;441#endif442char *slash;443time_t t;444char db[100];445446/* if we don't have uname, set these to sensible values */447char *sysname = "Unix",448*machine = "",449*release = "",450*version = "";451452#ifdef HAVE_UNAME453uname(&name);454sysname=name.sysname;455machine=name.machine;456release=name.release;457version=name.version;458#endif459460putlocation = where;461462while (*cp) {463if (*cp != '%') {464putchr(*cp++);465continue;466}467switch (*++cp) {468469case 't':470slash = strchr(line+1, '/');471if (slash == (char *) 0)472putstr(line);473else474putstr(&slash[1]);475break;476477case 'h':478putstr(editedhost);479break;480481case 's':482putstr(sysname);483break;484485case 'm':486putstr(machine);487break;488489case 'r':490putstr(release);491break;492493case 'v':494putstr(version);495break;496497case 'd':498time(&t);499strftime(db, sizeof(db), fmtstr, localtime(&t));500putstr(db);501break;502503case '%':504putchr('%');505break;506}507cp++;508}509}510511#ifdef DIAGNOSTICS512/*513* Print telnet options and commands in plain text, if possible.514*/515void516printoption(char *fmt, int option)517{518if (TELOPT_OK(option))519output_data("%s %s\r\n",520fmt,521TELOPT(option));522else if (TELCMD_OK(option))523output_data("%s %s\r\n",524fmt,525TELCMD(option));526else527output_data("%s %d\r\n",528fmt,529option);530return;531}532533void534printsub(int direction, unsigned char *pointer, size_t length)535/* '<' or '>' */536/* where suboption data sits */537/* length of suboption data */538{539int i = 0;540unsigned char buf[512];541542if (!(diagnostic & TD_OPTIONS))543return;544545if (direction) {546output_data("td: %s suboption ",547direction == '<' ? "recv" : "send");548if (length >= 3) {549int j;550551i = pointer[length-2];552j = pointer[length-1];553554if (i != IAC || j != SE) {555output_data("(terminated by ");556if (TELOPT_OK(i))557output_data("%s ",558TELOPT(i));559else if (TELCMD_OK(i))560output_data("%s ",561TELCMD(i));562else563output_data("%d ",564i);565if (TELOPT_OK(j))566output_data("%s",567TELOPT(j));568else if (TELCMD_OK(j))569output_data("%s",570TELCMD(j));571else572output_data("%d",573j);574output_data(", not IAC SE!) ");575}576}577length -= 2;578}579if (length < 1) {580output_data("(Empty suboption??\?)");581return;582}583switch (pointer[0]) {584case TELOPT_TTYPE:585output_data("TERMINAL-TYPE ");586switch (pointer[1]) {587case TELQUAL_IS:588output_data("IS \"%.*s\"",589(int)(length-2),590(char *)pointer+2);591break;592case TELQUAL_SEND:593output_data("SEND");594break;595default:596output_data("- unknown qualifier %d (0x%x).",597pointer[1], pointer[1]);598}599break;600case TELOPT_TSPEED:601output_data("TERMINAL-SPEED");602if (length < 2) {603output_data(" (empty suboption??\?)");604break;605}606switch (pointer[1]) {607case TELQUAL_IS:608output_data(" IS %.*s", (int)(length-2), (char *)pointer+2);609break;610default:611if (pointer[1] == 1)612output_data(" SEND");613else614output_data(" %d (unknown)", pointer[1]);615for (i = 2; i < length; i++) {616output_data(" ?%d?", pointer[i]);617}618break;619}620break;621622case TELOPT_LFLOW:623output_data("TOGGLE-FLOW-CONTROL");624if (length < 2) {625output_data(" (empty suboption??\?)");626break;627}628switch (pointer[1]) {629case LFLOW_OFF:630output_data(" OFF");631break;632case LFLOW_ON:633output_data(" ON");634break;635case LFLOW_RESTART_ANY:636output_data(" RESTART-ANY");637break;638case LFLOW_RESTART_XON:639output_data(" RESTART-XON");640break;641default:642output_data(" %d (unknown)",643pointer[1]);644}645for (i = 2; i < length; i++) {646output_data(" ?%d?",647pointer[i]);648}649break;650651case TELOPT_NAWS:652output_data("NAWS");653if (length < 2) {654output_data(" (empty suboption??\?)");655break;656}657if (length == 2) {658output_data(" ?%d?",659pointer[1]);660break;661}662output_data(" %u %u(%u)",663pointer[1],664pointer[2],665(((unsigned int)pointer[1])<<8) + pointer[2]);666if (length == 4) {667output_data(" ?%d?",668pointer[3]);669break;670}671output_data(" %u %u(%u)",672pointer[3],673pointer[4],674(((unsigned int)pointer[3])<<8) + pointer[4]);675for (i = 5; i < length; i++) {676output_data(" ?%d?",677pointer[i]);678}679break;680681case TELOPT_LINEMODE:682output_data("LINEMODE ");683if (length < 2) {684output_data(" (empty suboption??\?)");685break;686}687switch (pointer[1]) {688case WILL:689output_data("WILL ");690goto common;691case WONT:692output_data("WONT ");693goto common;694case DO:695output_data("DO ");696goto common;697case DONT:698output_data("DONT ");699common:700if (length < 3) {701output_data("(no option??\?)");702break;703}704switch (pointer[2]) {705case LM_FORWARDMASK:706output_data("Forward Mask");707for (i = 3; i < length; i++) {708output_data(" %x", pointer[i]);709}710break;711default:712output_data("%d (unknown)",713pointer[2]);714for (i = 3; i < length; i++) {715output_data(" %d",716pointer[i]);717}718break;719}720break;721722case LM_SLC:723output_data("SLC");724for (i = 2; i < length - 2; i += 3) {725if (SLC_NAME_OK(pointer[i+SLC_FUNC]))726output_data(" %s",727SLC_NAME(pointer[i+SLC_FUNC]));728else729output_data(" %d",730pointer[i+SLC_FUNC]);731switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {732case SLC_NOSUPPORT:733output_data(" NOSUPPORT");734break;735case SLC_CANTCHANGE:736output_data(" CANTCHANGE");737break;738case SLC_VARIABLE:739output_data(" VARIABLE");740break;741case SLC_DEFAULT:742output_data(" DEFAULT");743break;744}745output_data("%s%s%s",746pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",747pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",748pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");749if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|750SLC_FLUSHOUT| SLC_LEVELBITS)) {751output_data("(0x%x)",752pointer[i+SLC_FLAGS]);753}754output_data(" %d;",755pointer[i+SLC_VALUE]);756if ((pointer[i+SLC_VALUE] == IAC) &&757(pointer[i+SLC_VALUE+1] == IAC))758i++;759}760for (; i < length; i++) {761output_data(" ?%d?",762pointer[i]);763}764break;765766case LM_MODE:767output_data("MODE ");768if (length < 3) {769output_data("(no mode??\?)");770break;771}772{773char tbuf[32];774snprintf(tbuf,775sizeof(tbuf),776"%s%s%s%s%s",777pointer[2]&MODE_EDIT ? "|EDIT" : "",778pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",779pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",780pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",781pointer[2]&MODE_ACK ? "|ACK" : "");782output_data("%s",783tbuf[1] ? &tbuf[1] : "0");784}785if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) {786output_data(" (0x%x)",787pointer[2]);788}789for (i = 3; i < length; i++) {790output_data(" ?0x%x?",791pointer[i]);792}793break;794default:795output_data("%d (unknown)",796pointer[1]);797for (i = 2; i < length; i++) {798output_data(" %d", pointer[i]);799}800}801break;802803case TELOPT_STATUS: {804char *cp;805int j, k;806807output_data("STATUS");808809switch (pointer[1]) {810default:811if (pointer[1] == TELQUAL_SEND)812output_data(" SEND");813else814output_data(" %d (unknown)",815pointer[1]);816for (i = 2; i < length; i++) {817output_data(" ?%d?",818pointer[i]);819}820break;821case TELQUAL_IS:822output_data(" IS\r\n");823824for (i = 2; i < length; i++) {825switch(pointer[i]) {826case DO: cp = "DO"; goto common2;827case DONT: cp = "DONT"; goto common2;828case WILL: cp = "WILL"; goto common2;829case WONT: cp = "WONT"; goto common2;830common2:831i++;832if (TELOPT_OK(pointer[i]))833output_data(" %s %s",834cp,835TELOPT(pointer[i]));836else837output_data(" %s %d",838cp,839pointer[i]);840841output_data("\r\n");842break;843844case SB:845output_data(" SB ");846i++;847j = k = i;848while (j < length) {849if (pointer[j] == SE) {850if (j+1 == length)851break;852if (pointer[j+1] == SE)853j++;854else855break;856}857pointer[k++] = pointer[j++];858}859printsub(0, &pointer[i], k - i);860if (i < length) {861output_data(" SE");862i = j;863} else864i = j - 1;865866output_data("\r\n");867868break;869870default:871output_data(" %d",872pointer[i]);873break;874}875}876break;877}878break;879}880881case TELOPT_XDISPLOC:882output_data("X-DISPLAY-LOCATION ");883switch (pointer[1]) {884case TELQUAL_IS:885output_data("IS \"%.*s\"",886(int)(length-2),887(char *)pointer+2);888break;889case TELQUAL_SEND:890output_data("SEND");891break;892default:893output_data("- unknown qualifier %d (0x%x).",894pointer[1], pointer[1]);895}896break;897898case TELOPT_NEW_ENVIRON:899output_data("NEW-ENVIRON ");900goto env_common1;901case TELOPT_OLD_ENVIRON:902output_data("OLD-ENVIRON");903env_common1:904switch (pointer[1]) {905case TELQUAL_IS:906output_data("IS ");907goto env_common;908case TELQUAL_SEND:909output_data("SEND ");910goto env_common;911case TELQUAL_INFO:912output_data("INFO ");913env_common:914{915int quote = 0;916for (i = 2; i < length; i++ ) {917switch (pointer[i]) {918case NEW_ENV_VAR:919if (quote)920output_data("\" ");921output_data("VAR ");922quote = 0;923break;924925case NEW_ENV_VALUE:926if (quote)927output_data("\" ");928output_data("VALUE ");929quote = 0;930break;931932case ENV_ESC:933if (quote)934output_data("\" ");935output_data("ESC ");936quote = 0;937break;938939case ENV_USERVAR:940if (quote)941output_data("\" ");942output_data("USERVAR ");943quote = 0;944break;945946default:947if (isprint(pointer[i]) && pointer[i] != '"') {948if (!quote) {949output_data("\"");950quote = 1;951}952output_data("%c", pointer[i]);953} else {954output_data("%03o ", pointer[i]);955quote = 0;956}957break;958}959}960if (quote)961output_data("\"");962break;963}964}965break;966967#ifdef AUTHENTICATION968case TELOPT_AUTHENTICATION:969output_data("AUTHENTICATION");970971if (length < 2) {972output_data(" (empty suboption??\?)");973break;974}975switch (pointer[1]) {976case TELQUAL_REPLY:977case TELQUAL_IS:978output_data(" %s ",979(pointer[1] == TELQUAL_IS) ?980"IS" : "REPLY");981if (AUTHTYPE_NAME_OK(pointer[2]))982output_data("%s ",983AUTHTYPE_NAME(pointer[2]));984else985output_data("%d ",986pointer[2]);987if (length < 3) {988output_data("(partial suboption??\?)");989break;990}991output_data("%s|%s",992((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?993"CLIENT" : "SERVER",994((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?995"MUTUAL" : "ONE-WAY");996997auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));998output_data("%s",999buf);1000break;10011002case TELQUAL_SEND:1003i = 2;1004output_data(" SEND ");1005while (i < length) {1006if (AUTHTYPE_NAME_OK(pointer[i]))1007output_data("%s ",1008AUTHTYPE_NAME(pointer[i]));1009else1010output_data("%d ",1011pointer[i]);1012if (++i >= length) {1013output_data("(partial suboption??\?)");1014break;1015}1016output_data("%s|%s ",1017((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?1018"CLIENT" : "SERVER",1019((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?1020"MUTUAL" : "ONE-WAY");1021++i;1022}1023break;10241025case TELQUAL_NAME:1026i = 2;1027output_data(" NAME \"%.*s\"",1028(int)(length - 2),1029pointer);1030break;10311032default:1033for (i = 2; i < length; i++) {1034output_data(" ?%d?",1035pointer[i]);1036}1037break;1038}1039break;1040#endif10411042#ifdef ENCRYPTION1043case TELOPT_ENCRYPT:1044output_data("ENCRYPT");1045if (length < 2) {1046output_data(" (empty suboption?)");1047break;1048}1049switch (pointer[1]) {1050case ENCRYPT_START:1051output_data(" START");1052break;10531054case ENCRYPT_END:1055output_data(" END");1056break;10571058case ENCRYPT_REQSTART:1059output_data(" REQUEST-START");1060break;10611062case ENCRYPT_REQEND:1063output_data(" REQUEST-END");1064break;10651066case ENCRYPT_IS:1067case ENCRYPT_REPLY:1068output_data(" %s ",1069(pointer[1] == ENCRYPT_IS) ?1070"IS" : "REPLY");1071if (length < 3) {1072output_data(" (partial suboption?)");1073break;1074}1075if (ENCTYPE_NAME_OK(pointer[2]))1076output_data("%s ",1077ENCTYPE_NAME(pointer[2]));1078else1079output_data(" %d (unknown)",1080pointer[2]);10811082encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));1083output_data("%s",1084buf);1085break;10861087case ENCRYPT_SUPPORT:1088i = 2;1089output_data(" SUPPORT ");1090while (i < length) {1091if (ENCTYPE_NAME_OK(pointer[i]))1092output_data("%s ",1093ENCTYPE_NAME(pointer[i]));1094else1095output_data("%d ",1096pointer[i]);1097i++;1098}1099break;11001101case ENCRYPT_ENC_KEYID:1102output_data(" ENC_KEYID %d", pointer[1]);1103goto encommon;11041105case ENCRYPT_DEC_KEYID:1106output_data(" DEC_KEYID %d", pointer[1]);1107goto encommon;11081109default:1110output_data(" %d (unknown)", pointer[1]);1111encommon:1112for (i = 2; i < length; i++) {1113output_data(" %d", pointer[i]);1114}1115break;1116}1117break;1118#endif11191120default:1121if (TELOPT_OK(pointer[0]))1122output_data("%s (unknown)",1123TELOPT(pointer[0]));1124else1125output_data("%d (unknown)",1126pointer[i]);1127for (i = 1; i < length; i++) {1128output_data(" %d", pointer[i]);1129}1130break;1131}1132output_data("\r\n");1133}11341135/*1136* Dump a data buffer in hex and ascii to the output data stream.1137*/1138void1139printdata(char *tag, char *ptr, size_t cnt)1140{1141size_t i;1142char xbuf[30];11431144while (cnt) {1145/* flush net output buffer if no room for new data) */1146if ((&netobuf[BUFSIZ] - nfrontp) < 80) {1147netflush();1148}11491150/* add a line of output */1151output_data("%s: ", tag);1152for (i = 0; i < 20 && cnt; i++) {1153output_data("%02x", *ptr);1154if (isprint((unsigned char)*ptr)) {1155xbuf[i] = *ptr;1156} else {1157xbuf[i] = '.';1158}1159if (i % 2) {1160output_data(" ");1161}1162cnt--;1163ptr++;1164}1165xbuf[i] = '\0';1166output_data(" %s\r\n", xbuf);1167}1168}1169#endif /* DIAGNOSTICS */117011711172