/* * * * Author: John D. Carlson * Martin Hunt * Networks and Distributed Computing * Computing & Communications * University of Washington * Administration Building, AG-44 * Seattle, WA 98195 * Internet: johnc@cac.washington.edu * * * Copyright 1992 by the University of Washington * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appears in all copies and that both the * above copyright notice and this permission notice appear in supporting * documentation, and that the name of the University of Washington not be * used in advertising or publicity pertaining to distribution of the software * without specific, written prior permission. This software is made * available "as is", and * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ #ifndef lint static char rcsid[] = "@(#) $Header: /usr/staff/martinh/tcpview/RCS/telnet.c,v 1.1 1993/04/22 20:36:38 martinh Exp $ (UW)"; #endif #include #include int PrintFrames = 0; /* print headers ? */ int EndSub=1; /* begin/end subnegotiation */ int TType=0; /* request and response for terminal types */ #ifdef __STDC__ int getbyte(void); u_short getword(void); u_long getlword(void); void processIAC(void); void checksmallopts(void); #else int getbyte(); u_short getword(); u_long getlword(); void processIAC(); void checksmallopts(); #endif main(argc, argv) int argc; char *argv[]; { int c, i=0; int type; int length; if( argc > 1 ) if( *argv[1]=='-' && argv[1][1]=='f' ) PrintFrames=1; while( (c = getbyte()) != EOF) { if( c=='\n' ) { putchar('\n'); c = getbyte(); if( c=='\r' ) continue; } else if( c=='\r' ) { putchar('\n'); c = getbyte(); if( c=='\n') continue; } if( c=='\t' ) putchar(c); else if (c == 255) { putchar('\n'); processIAC(); } else { /* not IAC or subnegotiation must be c > 31 && c < 128 */ if (0 < c && c < 128) putchar(c); else fprintf(stdout,"<%d>",c); } } } /* handle IAC stuff */ void processIAC() { int c; c=getbyte(); switch (c) { case 250: /* SB */ printf(""); EndSub=0; while (!EndSub) { /* keep looking until we find an end to subnegotiation */ checksmallopts(); } break; case 251: /* WILL */ printf(""); checksmallopts(); break; case 252: /* WONT */ printf(""); checksmallopts(); break; case 253: /* DO */ printf(""); checksmallopts(); break; case 254: /* DONT */ printf(""); checksmallopts(); break; default: /* don't know what it is so indicate command */ if (c) /* if not null ie c == 0, then print it */ putchar(c); } } /* need to handle option which are larger than 31 */ void checksmallopts() { int c; c=getbyte(); switch (c) { case 0: if (TType && !EndSub) { printf(""); TType=0; } else printf(""); break; case 1: if (TType && !EndSub) { printf(""); TType=0; } else printf(""); break; case 2: printf(""); break; case 3: printf(""); break; case 4: printf(""); break; case 5: printf(""); break; case 6: printf(""); break; case 7: printf(""); break; case 8: printf(""); break; case 9: printf(""); break; case 10: printf(""); break; case 11: printf(""); break; case 12: printf(""); break; case 13: printf(""); break; case 14: printf(""); break; case 15: printf(""); break; case 16: printf(""); break; case 17: printf(""); break; case 18: printf(""); break; case 19: printf(""); break; case 20: printf(""); break; case 21: printf(""); break; case 22: printf(""); break; case 23: printf(""); break; case 24: printf(""); TType=1; break; case 25: printf(""); break; case 26: printf(""); break; case 27: printf(""); break; case 28: printf(""); break; case 29: printf(""); break; case 30: printf(""); break; case 31: printf(""); break; case 32: printf(""); break; case 33: printf(""); break; case 34: printf(""); break; case 35: printf(""); break; case 36: printf(""); break; case 37: printf(""); break; case 38: printf(""); break; case 239: printf(""); break; case 240: /* SE */ printf(""); EndSub=1; break; case 241: printf(""); break; case 242: printf(""); break; case 243: printf(""); break; case 244: printf(""); break; case 245: printf(""); break; case 246: printf(""); break; case 247: printf(""); break; case 248: printf(""); break; case 249: printf(""); break; default: if (!EndSub && c != 255) /* print char if in subnegot and not an IAC */ putchar(c); else if (EndSub && c != 255) /* print # if not in subnegot and not IAC */ fprintf(stdout,"<%d>",c); } if (EndSub) /* insert a newline unless in the midst of subnegotiation */ putchar('\n'); } /* some basic I/O functions */ int getbyte() { u_char b; if(hexread(&b,1)) return( (int)b ); else return( EOF ); } u_short getword() { unsigned short buf; if( hexread(&buf,2) ) return( ntohs(buf) ); else return( EOF ); } u_long getlword() { unsigned int buf; if( hexread(&buf,4) ) return( ntohl(buf) ); else return( EOF ); }