*** old/tn-gw.c 1997/03/24 15:06:00 --- tn-gw.c 1997/04/02 16:00:11 *************** *** 11,17 **** /* * Author: Marcus J. Ranum, Trusted Information Systems, Inc. */ ! static char RcsId[] = "$Header: /usr/home/rick/fwtk2.0/fwtk/tn-gw/RCS/tn-gw.c,v 1.22 1997/03/24 15:06:00 rick Exp $"; #include --- 11,17 ---- /* * Author: Marcus J. Ranum, Trusted Information Systems, Inc. */ ! static char RcsId[] = "$Header: /usr/home/rick/fwtk2.0/fwtk/tn-gw/RCS/tn-gw.c,v 1.23 1997/04/02 15:59:34 rick Exp $"; #include *************** *** 816,821 **** --- 816,869 ---- } + static int + eat_response(fd) + int fd; + { + fd_set r; + struct timeval timo; + int x; + unsigned char buf; + int state = 0; + + while (1) { + timo.tv_sec = 2; + timo.tv_usec = 0; + + FD_ZERO(&r); + FD_SET(fd,&r); + x = select(fd + 1,&r,(fd_set *)0,(fd_set *)0,&timo); + if (x == 0) + return 0; + if (x < 0) { + if (errno == EINTR) continue; + return x; + } + x = read(fd,&buf,1); + if (x < 0) { + return x; + } + if (x != 1) + return 0; + switch (state) { + case 0: + if (buf == IAC) + state = 1; + break; + case 1: + if (buf == WILL || buf == WONT || + buf == DO || buf == DONT) { + state = 2; + } else { + return 0; + } + break; + case 2: + return 0; + } + } + } + static int cmd_connect(ac,av,cbuf) int ac; *************** *** 903,920 **** syslog(LLEV,"permit host=%.512s/%.20s destination=%.512s",rladdr,riaddr,av[1]); if ((port != TNPORT) || (initialized && echomode)) { ! unsigned char xuf[9]; xuf[0] = IAC; xuf[1] = WONT; xuf[2] = TELOPT_ECHO; ! xuf[3] = IAC; ! xuf[4] = WONT; ! xuf[5] = TELOPT_SGA; ! xuf[6] = IAC; ! xuf[7] = WONT; ! xuf[8] = TELOPT_TTYPE; ! if(write(0,xuf,9) != 9) return(1); kludgeraw = 1; echomode = 0; --- 951,978 ---- syslog(LLEV,"permit host=%.512s/%.20s destination=%.512s",rladdr,riaddr,av[1]); if ((port != TNPORT) || (initialized && echomode)) { ! unsigned char xuf[3]; xuf[0] = IAC; xuf[1] = WONT; xuf[2] = TELOPT_ECHO; ! if(write(0,xuf,3) != 3) ! return(1); ! if (eat_response(0) < 0) ! return(1); ! xuf[0] = IAC; ! xuf[1] = WONT; ! xuf[2] = TELOPT_SGA; ! if(write(0,xuf,3) != 3) ! return(1); ! if (eat_response(0) < 0) ! return(1); ! xuf[0] = IAC; ! xuf[1] = WONT; ! xuf[2] = TELOPT_TTYPE; ! if(write(0,xuf,3) != 3) ! return(1); ! if (eat_response(0) < 0) return(1); kludgeraw = 1; echomode = 0;