static void _gettermname(void) { /* * If the client turned off the option, * we can't send another request, so we * just return. */ if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE); while (sequenceIs(ttypesubopt, baseline)) ttloop(); }
static void _gettermname(void) { /* * If the client turned off the option, * we can't send another request, so we * just return. */ if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf); nfrontp += sizeof ttytype_sbbuf; while (sequenceIs(ttypesubopt, baseline)) ttloop(); }
static int getterminaltype(char *name) { int retval = -1; (void)name; settimer(baseline); #if defined(AUTHENTICATE) /* * Handle the Authentication option before we do anything else. */ send_do(TELOPT_AUTHENTICATION, 1); while (his_will_wont_is_changing(TELOPT_AUTHENTICATION)) ttloop(); if (his_state_is_will(TELOPT_AUTHENTICATION)) { retval = auth_wait(name); } #endif #if defined(ENCRYPT) send_will(TELOPT_ENCRYPT, 1); #endif send_do(TELOPT_TTYPE, 1); send_do(TELOPT_TSPEED, 1); send_do(TELOPT_XDISPLOC, 1); send_do(TELOPT_ENVIRON, 1); while ( #if defined(ENCRYPT) his_do_dont_is_changing(TELOPT_ENCRYPT) || #endif his_will_wont_is_changing(TELOPT_TTYPE) || his_will_wont_is_changing(TELOPT_TSPEED) || his_will_wont_is_changing(TELOPT_XDISPLOC) || his_will_wont_is_changing(TELOPT_ENVIRON)) { ttloop(); } #if defined(ENCRYPT) /* * Wait for the negotiation of what type of encryption we can * send with. If autoencrypt is not set, this will just return. */ if (his_state_is_will(TELOPT_ENCRYPT)) { encrypt_wait(); } #endif if (his_state_is_will(TELOPT_TSPEED)) { static char sbbuf[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; bcopy(sbbuf, nfrontp, sizeof sbbuf); nfrontp += sizeof sbbuf; } if (his_state_is_will(TELOPT_XDISPLOC)) { static char sbbuf[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; bcopy(sbbuf, nfrontp, sizeof sbbuf); nfrontp += sizeof sbbuf; } if (his_state_is_will(TELOPT_ENVIRON)) { static char sbbuf[] = { IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE }; bcopy(sbbuf, nfrontp, sizeof sbbuf); nfrontp += sizeof sbbuf; } if (his_state_is_will(TELOPT_TTYPE)) { bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf); nfrontp += sizeof ttytype_sbbuf; } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) ttloop(); } if (his_state_is_will(TELOPT_XDISPLOC)) { while (sequenceIs(xdisplocsubopt, baseline)) ttloop(); } if (his_state_is_will(TELOPT_ENVIRON)) { while (sequenceIs(environsubopt, baseline)) ttloop(); } if (his_state_is_will(TELOPT_TTYPE)) { char first[256], last[256]; while (sequenceIs(ttypesubopt, baseline)) ttloop(); /* * If the other side has already disabled the option, then * we have to just go with what we (might) have already gotten. */ if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) { (void) strncpy(first, terminaltype, sizeof(first)); for(;;) { /* * Save the unknown name, and request the next name. */ (void) strncpy(last, terminaltype, sizeof(last)); _gettermname(); if (terminaltypeok(terminaltype)) break; if ((strncmp(last, terminaltype, sizeof(last)) == 0) || his_state_is_wont(TELOPT_TTYPE)) { /* * We've hit the end. If this is the same as * the first name, just go with it. */ if (strncmp(first, terminaltype, sizeof(first)) == 0) break; /* * Get the terminal name one more time, so that * RFC1091 compliant telnets will cycle back to * the start of the list. */ _gettermname(); if (strncmp(first, terminaltype, sizeof(first)) != 0) (void) strncpy(terminaltype, first, sizeof(first)); break; } } } } return(retval); } /* end of getterminaltype */
static int getterminaltype(char *name) { int retval = -1; (void)name; settimer(baseline); #if defined(AUTHENTICATE) /* * Handle the Authentication option before we do anything else. */ send_do(TELOPT_AUTHENTICATION, 1); while (his_will_wont_is_changing(TELOPT_AUTHENTICATION)) ttloop(); if (his_state_is_will(TELOPT_AUTHENTICATION)) { retval = auth_wait(name); } #endif #if defined(ENCRYPT) send_will(TELOPT_ENCRYPT, 1); #endif send_do(TELOPT_TTYPE, 1); send_do(TELOPT_TSPEED, 1); send_do(TELOPT_XDISPLOC, 1); send_do(TELOPT_ENVIRON, 1); while ( #if defined(ENCRYPT) his_do_dont_is_changing(TELOPT_ENCRYPT) || #endif his_will_wont_is_changing(TELOPT_TTYPE) || his_will_wont_is_changing(TELOPT_TSPEED) || his_will_wont_is_changing(TELOPT_XDISPLOC) || his_will_wont_is_changing(TELOPT_ENVIRON)) { ttloop(); } #if defined(ENCRYPT) /* * Wait for the negotiation of what type of encryption we can * send with. If autoencrypt is not set, this will just return. */ if (his_state_is_will(TELOPT_ENCRYPT)) { encrypt_wait(); } #endif if (his_state_is_will(TELOPT_TSPEED)) { netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE); } if (his_state_is_will(TELOPT_XDISPLOC)) { netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE); } if (his_state_is_will(TELOPT_ENVIRON)) { netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE); } if (his_state_is_will(TELOPT_TTYPE)) { netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE); } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) ttloop(); } if (his_state_is_will(TELOPT_XDISPLOC)) { while (sequenceIs(xdisplocsubopt, baseline)) ttloop(); } if (his_state_is_will(TELOPT_ENVIRON)) { while (sequenceIs(environsubopt, baseline)) ttloop(); } if (his_state_is_will(TELOPT_TTYPE)) { char first[256], last[256]; while (sequenceIs(ttypesubopt, baseline)) ttloop(); /* * If the other side has already disabled the option, then * we have to just go with what we (might) have already gotten. */ if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) { /* * Due to state.c, terminaltype points to a static char[41]. * Therefore, this assert cannot fail, and therefore, strings * arising from "terminaltype" can be safely strcpy'd into * first[] or last[]. */ assert(strlen(terminaltype) < sizeof(first)); strcpy(first, terminaltype); for(;;) { /* * Save the unknown name, and request the next name. */ strcpy(last, terminaltype); _gettermname(); assert(strlen(terminaltype) < sizeof(first)); if (terminaltypeok(terminaltype)) break; if (!strcmp(last, terminaltype) || his_state_is_wont(TELOPT_TTYPE)) { /* * We've hit the end. If this is the same as * the first name, just go with it. */ if (!strcmp(first, terminaltype)) break; /* * Get the terminal name one more time, so that * RFC1091 compliant telnets will cycle back to * the start of the list. */ _gettermname(); assert(strlen(terminaltype) < sizeof(first)); if (strcmp(first, terminaltype)) { /* * first[] came from terminaltype, so it must fit * back in. */ strcpy(terminaltype, first); } break; } } } } return(retval); } /* end of getterminaltype */