/*
*
*
* Author: Martin Hunt
* Networks and Distributed Computing
* Computing & Communications
* University of Washington
* Administration Building, AG-44
* Seattle, WA 98195
* Internet: martinh@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/generic.c,v 1.2 1993/04/22 20:21:25 martinh Exp $ (UW)";
#endif
/* This implements a filter which simply filters out control characters and
prints their ASCII value in angle brackets. You may want to use this as a template
for writing other simple filters. */
#include <stdio.h>
#include <sys/types.h>
int PrintFrames = 0;
#ifdef __STDC__
int getbyte(void);
u_short getword(void);
u_long getlword(void);
#else
int getbyte();
u_short getword();
u_long getlword();
#endif
main(argc, argv)
int argc;
char *argv[];
{
int c, i=0;
int type;
int length;
/* you must check for "-f" to see if frames will be printed too */
/* PrintFrames is a global used by hexread() in hex.c */
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>31 && c<128 )
putchar(c);
else
printf("<%d>",c);
}
}
/* 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 );
}
syntax highlighted by Code2HTML, v. 0.9.1