[comp.sources.x] xtr - X front end to etherd

pochmara@ogicse.cse.ogi.edu (John Pochmara) (03/15/91)

Article-I.D.: ogicse.18619
Posted: Thu Mar 14 10:03:29 1991
Sender: pochmara@ogicse.ogi.edu
Distribution: usa
Organization: Oregon Graduate Institute (formerly OGC), Beaverton, OR
Lines: 1585

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 3)."
# Contents:  display.c mask.c rpc_stuff.c strip.c xtr.c
# Wrapped by pochmara@ogicse on Thu Mar 14 10:00:07 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'display.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'display.c'\"
else
echo shar: Extracting \"'display.c'\" \(4264 characters\)
sed "s/^X//" >'display.c' <<'END_OF_FILE'
X/*
X * display.c
X *
X *
X */
X#include <stdio.h>
X#include <signal.h>	
X#include <X11/Xlib.h>
X#include <X11/Xatom.h>
X#include "misc.h"
X
X
X#define STR_LEN		(256)
X
XDisplay *Dp;
XWindow MainWin;
XVisual *MVis;
XGC Text6x10GC;
XGC Text5x8GC;
XFont Fnt6x10;
XFont Fnt5x8;
Xint screen;
X
Xint ForGndPix;
Xint BackGndPix;
X
Xstatic char HostName[STR_LEN];
Xstatic int IntervalVal = 0;
Xstatic int IntervalChanged = TRUE;
X
Xstatic void DisplayInterval();
Xstatic void DisplayHost();
Xstatic void PropagateInterval();
X
Xstatic int AfterXlib();
X
Xvoid InitWin( hostname )
Xchar *hostname;
X{
X	XEvent ev;
X	char buf[256];
X
X	if( ( Dp = XOpenDisplay( NULL ) ) == NULL ) {
X		fprintf( stderr, "Could not open display.\n" );
X		exit( 1 );
X	}
X
X#ifdef XDEBUG
X	/* XSynchronize( Dp, True ); */
X	XSetAfterFunction( Dp, AfterXlib );
X#endif XDEBUG
X
X	screen = DefaultScreen( Dp );
X	MVis = DefaultVisual( Dp, screen );
X
X	ForGndPix = WhitePixel( Dp, screen );
X	BackGndPix = BlackPixel( Dp, screen );
X
X	MainWin = XCreateSimpleWindow( Dp, RootWindow( Dp, screen ), 0, 0,
X			MWIN_W, MWIN_H, 1, ForGndPix, BackGndPix );
X
X	XSelectInput( Dp, MainWin, ExposureMask|StructureNotifyMask|
X							ButtonPressMask );
X
X	sprintf( buf, "xtr: %s", hostname );
X
X	XChangeProperty( Dp, MainWin, XA_WM_NAME, XA_STRING, 8,
X			PropModeReplace, (unsigned char *)buf, strlen( buf ) );
X
X	XMapWindow( Dp, MainWin );
X
X	Text6x10GC = XCreateGC( Dp, MainWin, 0, NULL );
X	Fnt6x10 = XLoadFont( Dp, "6x10" );
X	XSetState( Dp, Text6x10GC, ForGndPix, BackGndPix, GXset, AllPlanes );
X	XSetFont( Dp, Text6x10GC, Fnt6x10 );
X
X	Text5x8GC = XCreateGC( Dp, MainWin, 0, NULL );
X	Fnt5x8 = XLoadFont( Dp, "5x8" );
X	XSetState( Dp, Text5x8GC, ForGndPix, BackGndPix, GXset, AllPlanes );
X	XSetFont( Dp, Text5x8GC, Fnt5x8 );
X
X	XFlush( Dp );
X
X	while( 1 ) {
X		XNextEvent( Dp, &ev );
X		if( ev.type == Expose ) {
X			break;
X		}
X	}
X}
X
Xvoid FlushDpy()
X{
X	XFlush( Dp );
X}
X
Xvoid SyncDpy()
X{
X	XSync( Dp, False );
X}
X
Xvoid ResizeWindow( w, h )
Xint w, h;
X{
X	XResizeWindow( Dp, MainWin, w, h );
X}
X
Xvoid SetHost( host )
Xchar *host;
X{
X	strncpy( HostName, host, STR_LEN );
X	DisplayHost();
X}
X
Xvoid SetInterval( inter )
Xint inter;
X{
X	IntervalVal = inter;
X	DisplayInterval();
X}
X
Xvoid IncInterval()
X{
X	IntervalVal++;
X	IntervalChanged = TRUE;
X}
X
Xvoid DecInterval()
X{
X	IntervalVal--;
X	IntervalChanged = TRUE;
X	if( IntervalVal < 0 ) IntervalVal = 0;
X}
X
Xstatic void DisplayHost()
X{
X	static int len = 0;
X	char buf[1024];
X	int i;
X	int l;
X
X	sprintf( buf, "Host: %s", HostName );
X	l = strlen( buf );
X
X	if( l < len ) {
X		for( i = l; i < len; i++ ) {
X			buf[i] = ' ';
X		}
X		buf[i] = NULL;
X	} else {
X		len = l;
X	}
X
X	XDrawImageString( Dp, MainWin, Text6x10GC, 5, 35, buf, len );
X
X	len = l;
X
X}
X
Xstatic void DisplayInterval()
X{
X	static int len = 0;
X	char buf[1024];
X	int i, l;
X
X	sprintf( buf, "Interval: %d sec", IntervalVal );
X	l = strlen( buf );
X
X	if( l < len ) {
X		for( i = l; i < len; i++ ) {
X			buf[i] = ' ';
X		}
X		buf[i] = NULL;
X	} else {
X		len = l;
X	}
X
X	XDrawImageString( Dp, MainWin, Text6x10GC, 25, 45, buf, len );
X
X	len = l;
X}
X
Xint GetDefaultValInt( str, def )
Xchar *str;
Xint def;
X{
X	extern int atoi();
X	char *ret;
X
X	ret = XGetDefault( Dp, "xtr", str );
X	
X	if( ret == NULL ) {
X		return( def );
X	} else {
X		return( atoi( ret ) );
X	}
X}
X
Xvoid DoEvents( block )
Xint block;
X{
X	XEvent ev;
X	void (*os)();
X	int exp = FALSE;
X
X	while( ( XPending( Dp ) > 0 ) || ( block == TRUE ) ) {
X
X		XNextEvent( Dp, &ev );
X
X	
X		switch( ev.type ) {
X			case Expose:
X				exp = TRUE;
X				break;
X
X			case ButtonPress:
X				os = signal( SIGALRM, SIG_IGN );
X				DoButtonPress( ev.xbutton.window );
X				signal( SIGALRM, os );
X				break;
X
X			case KeyPress:
X				os = signal( SIGALRM, SIG_IGN );
X				DoKeyInput( &(ev.xkey) );
X				signal( SIGALRM, os );
X				break;
X				
X
X		}
X
X
X		block = FALSE;
X
X	}
X
X	os = signal( SIGALRM, SIG_IGN );
X
X	if( exp == TRUE ) {
X		RedrawAllBars();
X		RedrawAllButtons();
X		RedrawAllStrips();
X		RedrawAllInputBoxes();
X		RedrawAllLabels();
X		DisplayHost();
X		DisplayInterval();
X		FlushDpy();
X	}
X
X	if( IntervalChanged == TRUE ) {
X		DisplayInterval();
X		PropagateInterval();
X		IntervalChanged = FALSE;
X	}
X
X	signal( SIGALRM, os );
X
X}
X
Xstatic void PropagateInterval()
X{
X	SetMainTimer( IntervalVal );
X}
X
Xstatic int AfterXlib( dp )
XDisplay *dp;
X{
X	long s;
X
X	s = XNextRequest( Dp );
X	fprintf( stderr, "%ld\n", s );
X}
END_OF_FILE
if test 4264 -ne `wc -c <'display.c'`; then
    echo shar: \"'display.c'\" unpacked with wrong size!
fi
# end of 'display.c'
fi
if test -f 'mask.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mask.c'\"
else
echo shar: Extracting \"'mask.c'\" \(5209 characters\)
sed "s/^X//" >'mask.c' <<'END_OF_FILE'
X/*
X * mask.c
X *
X *
X */
X#include <stdio.h>
X#include <netdb.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <arpa/inet.h>
X#include <ctype.h>
X#include "rpc_stuff.h"
X#include "button.h"
X#include "inbox.h"
X#include "misc.h"
X
Xextern long strtol();
X
Xstatic void MakeMaskButtons();
Xstatic void ShowMaskButtons();
Xstatic void ExitMask();
Xstatic void ResetMask();
Xstatic void ApplyMask();
Xstatic void SourceMask();
Xstatic void DestinationMask();
Xstatic void LenghtMask();
Xstatic void ProtocolMask();
Xstatic void ShowTrueMask();
Xstatic void FreeMask();
X
Xstatic int ButExit;
Xstatic int ButApply;
Xstatic int ButReset;
X
Xstatic int LenIn;
Xstatic int LenLb;
Xstatic char *LenMask = NULL;
X
Xstatic int SrcIn;
Xstatic int SrcLb;
Xstatic char *SrcMask = NULL;
X
Xstatic int DstIn;
Xstatic int DstLb;
Xstatic char *DstMask = NULL;
X
Xstatic int ProtoIn;
Xstatic int ProtoLb;
Xstatic char *ProtoMask = NULL;
X
Xvoid MakeMaskDisplay()
X{
X	MakeMaskButtons();
X
X	LenIn = CreateInputBox( 200, 15, 85, 70, 30 );
X	LenLb = CreateLabel( 35, 80, "Lenght:" );
X
X	ProtoIn = CreateInputBox( 200, 15, 85, 90, 30 );
X	ProtoLb = CreateLabel( 25, 100, "Protocol:" );
X
X	SrcIn = CreateInputBox( 200, 15, 85, 120, 30 );
X	SrcLb = CreateLabel( 35, 130, "Source:" );
X
X	DstIn = CreateInputBox( 200, 15, 85, 145, 30 );
X	DstLb = CreateLabel( 5, 155, "Destination:" );
X
X}
X
Xvoid ShowMaskWindow()
X{
X	ResizeWindow( 400, 180 );
X
X	ShowMaskButtons();
X
X	ShowTrueMask( LenIn, LenMask );
X	ShowInputBox( LenIn );
X	ShowLabel( LenLb );
X
X	ShowTrueMask( SrcIn, SrcMask );
X	ShowInputBox( SrcIn );
X	ShowLabel( SrcLb );
X
X	ShowTrueMask( DstIn, DstMask );
X	ShowInputBox( DstIn );
X	ShowLabel( DstLb );
X
X	ShowTrueMask( ProtoIn, ProtoMask );
X	ShowInputBox( ProtoIn );
X	ShowLabel( ProtoLb );
X
X}
X
Xvoid HideMaskWindow()
X{
X	HideButton( ButExit );
X	HideButton( ButApply );
X	HideButton( ButReset );
X
X	HideInputBox( LenIn );
X	HideLabel( LenLb );
X
X	HideInputBox( SrcIn );
X	HideLabel( SrcLb );
X
X	HideInputBox( DstIn );
X	HideLabel( DstLb );
X
X	HideInputBox( ProtoIn );
X	HideLabel( ProtoLb );
X}
X
Xstatic void ShowTrueMask( id, mask )
Xint id;
Xchar *mask;
X{
X
X	if( mask == NULL ) {
X		SetInputBoxData( id, "" );
X	} else {
X		SetInputBoxData( id, mask );
X	}
X}
X
Xstatic void FreeMask( mask )
Xchar *mask;
X{
X	if( mask != NULL ) {
X		free( mask );
X	}
X}
X
Xstatic void ShowMaskButtons()
X{
X	ShowButton( ButExit );
X	ShowButton( ButApply );
X	ShowButton( ButReset );
X}
X
Xstatic void MakeMaskButtons()
X{
X	ButExit = CreateButton( "Exit", 30, 15, 5, 5, ExitMask );
X	ButApply = CreateButton( "Apply", 40, 15, 40, 5, ApplyMask );
X	ButReset = CreateButton( "Reset", 40, 15, 85, 5, ResetMask );
X}
X
Xstatic void ExitMask()
X{
X	ReturnToMain();
X}
X
Xstatic void ResetMask()
X{
X	SetInputBoxData( SrcIn, "" );
X	SetInputBoxData( DstIn, "" );
X	SetInputBoxData( LenIn, "" );
X	SetInputBoxData( ProtoIn, "" );
X
X	ApplyMask();	/* reset etherd too */
X
X}
X
Xstatic void ApplyMask()
X{
X
X	FreeMask( SrcMask );
X	SrcMask = GetInputBoxData( SrcIn );
X
X	FreeMask( DstMask );
X	DstMask = GetInputBoxData( DstIn );
X	
X	FreeMask( ProtoMask );
X	ProtoMask = GetInputBoxData( ProtoIn );
X
X	FreeMask( LenMask );
X	LenMask = GetInputBoxData( LenIn );
X
X
X	SourceMask( SrcMask );
X	DestinationMask( DstMask );
X	ProtocolMask( ProtoMask );
X	LenghtMask( LenMask );
X
X}
X
Xstatic void SourceMask( mask )
Xchar *mask;
X{
X	unsigned long addr;
X	struct hostent *hinfo;
X
X	
X	if( mask == NULL ) {
X		SetSrcAddrMask( 0, 0 );
X		return;
X	}
X
X	if( isalpha( *mask ) ) {
X
X		hinfo = gethostbyname( mask );
X
X		if( hinfo != NULL ) {
X			
X			addr = (unsigned long)hinfo->h_addr_list[0];
X			bcopy(hinfo->h_addr_list[0], &addr, hinfo->h_length);
X
X		} else {
X			SetInputBoxData( SrcIn, "" );
X			return;
X		}
X
X	} else {
X		addr = inet_addr( mask );
X	}
X
Xprintf( "addr: %x\n", addr );
X
X	SetSrcAddrMask( addr, ~addr );
X
X}
X
Xstatic void DestinationMask( mask )
Xchar *mask;
X{
X	unsigned long addr;
X	struct hostent *hinfo;
X
X	if( mask == NULL ) {
X		SetDstAddrMask( 0, 0 );
X		return;
X	}
X
X	if( isalpha( *mask ) ) {
X
X		hinfo = gethostbyname( mask );
X
X		if( hinfo != NULL ) {
X			
X			addr = (unsigned long)hinfo->h_addr_list[0];
X			bcopy(hinfo->h_addr_list[0], &addr, hinfo->h_length);
X
X		} else {
X			SetInputBoxData( DstIn, "" );
X			return;
X		}
X
X	} else {
X		addr = inet_addr( mask );
X	}
X
X	SetDstAddrMask( addr, ~addr );
X
X}
X
Xstatic void LenghtMask( mask )
Xchar *mask;
X{
X	int min, max;
X	char *p;
X
X
X	if( mask == NULL ) {
X		SetLenMask( 0, 0 );
X		return;
X	}
X		
X	min = (int)strtol( mask, &p, 0 );
X
X	if( p == mask ) {
X		SetInputBoxData( LenIn, "" );
X		return;
X	} else if( *p == NULL ) {
X		max = min;
X	} else if( *p == '-' ) { 
X		mask = p+1;	/* move past '-' */
X		max = (int)strtol( mask, &p, 0 );
X
X		if( p == mask ) {
X			SetInputBoxData( LenIn, "" );
X			return;
X		}
X	} else {
X		SetInputBoxData( LenIn, "" );
X		return; 	
X	}
X	
X	SetLenMask( min, max );
X
X}
X
Xstatic void ProtocolMask( mask )
Xchar *mask;
X{
X	struct protoent *pr;
X	int prn;
X
X	if( mask == NULL ) {
X		SetProtoMask( 0, 0 );
X		return;
X	}
X
X
X	if( isalpha( *mask ) ) {
X		pr = getprotobyname( mask );
X		if( pr == NULL ) {
X			SetInputBoxData( ProtoIn, "" );
X			return;
X		}
X
X		prn = pr->p_proto;
X
X	} else {
X
X		prn = (int)strtol(mask, NULL, 0);
X		
X		if( prn == 0 ) {
X			SetInputBoxData( ProtoIn, "" );
X			return;
X		}
X	}
X
X
X	SetProtoMask( prn, ~prn );
X
X}
END_OF_FILE
if test 5209 -ne `wc -c <'mask.c'`; then
    echo shar: \"'mask.c'\" unpacked with wrong size!
fi
# end of 'mask.c'
fi
if test -f 'rpc_stuff.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rpc_stuff.c'\"
else
echo shar: Extracting \"'rpc_stuff.c'\" \(4760 characters\)
sed "s/^X//" >'rpc_stuff.c' <<'END_OF_FILE'
X/*
X *
X *
X *
X *
X */
X#include <stdio.h>
X#include <rpc/rpc.h>
X#include "ether.h"
X
X#define NDPROTO 0
X#define ICMPPROTO 1
X#define UDPPROTO 2
X#define TCPPROTO 3
X#define ARPPROTO 4
X#define OTHERPROTO 5
X
X
Xstatic CLIENT *Client;
Xstatic etherstat PrevStatData = { { 0, 0 }, 0, 0, 0,
X				  { 0, 0, 0, 0, 0, 0, 0, 0, 
X				    0, 0, 0, 0, 0, 0, 0, 0 },
X				  { 0, 0, 0, 0, 0, 0 } };
Xstatic etherstat *StatData = NULL;
Xstatic long TimeDelta = 1;
X
Xstatic etheraddrs *DstData = NULL;
Xstatic int DstIndex = 0;
Xstatic etherhmem DstPtr = NULL;
X
Xstatic etheraddrs *SrcData = NULL;
Xstatic int SrcIndex = 0;
Xstatic etherhmem SrcPtr = NULL;
X
Xstatic void FreeHostData();
X
X
Xvoid InitRPC( host )
Xchar *host;
X{
X
X	Client = clnt_create( host, ETHERPROG, ETHERVERS, "udp" );
X
X	if( Client == NULL ) {
X		fprintf( stderr, "xtr: Could not create connection to " );
X		fprintf( stderr, "'%s'\n", host );
X		exit( 1 );
X	}
X}
X
X
Xvoid TurnOnEther()
X{
X	int dummy;
X
X	etherproc_on_1( &dummy, Client );
X}
X
Xvoid TurnOffEther()
X{
X	int dummy;
X
X	etherproc_off_1( &dummy, Client );
X}
X
Xvoid SetLenMask( min, max )
Xint min;
Xint max;
X{
X	addrmask am;
X
X	am.a_addr = min;
X	am.a_mask = max;
X
X	etherproc_selectlnth_1( &am, Client );
X}
X
Xvoid SetProtoMask( addr, mask )
Xint addr;
Xint mask;
X{
X	addrmask am;
X
X	am.a_addr = addr;
X	am.a_mask = mask;
X
X	etherproc_selectproto_1( &am, Client );
X}
X
Xvoid SetSrcAddrMask( addr, mask )
Xint addr;
Xint mask;
X{
X	addrmask am;
X
X	am.a_addr = addr;
X	am.a_mask = mask;
X
X	etherproc_selectsrc_1( &am, Client );
X
X}
X
Xvoid SetDstAddrMask( addr, mask )
Xint addr;
Xint mask;
X{
X	addrmask am;
X
X	am.a_addr = addr;
X	am.a_mask = mask;
X
X	etherproc_selectdst_1( &am, Client );
X
X}
X
Xvoid GetStatData()
X{
X	int dummy;
X
X	if( StatData != NULL ) {
X		PrevStatData = *StatData;
X	}
X
X	StatData = etherproc_getdata_1( &dummy, Client );
X
X	TimeDelta = StatData->e_time.tv_seconds-PrevStatData.e_time.tv_seconds;
X
X	if( TimeDelta <= 0 ) {
X		TimeDelta = 1;
X	}
X
X}
X
Xvoid GetSrcData()
X{
X	etherhmem tmp;
X	int dummy, i;
X
X	if( SrcData != NULL ) {
X		FreeHostData( SrcData );
X	}
X
X	SrcData = etherproc_getsrcdata_1( &dummy, Client );
X
X
X}
X
Xvoid GetDstData()
X{
X	int dummy;
X
X	if( DstData != NULL ) {
X		FreeHostData( DstData );
X	}
X
X	DstData = etherproc_getdstdata_1( &dummy, Client );
X}
X
Xvoid TopSrcData()
X{
X	SrcIndex = 0;
X	SrcPtr = SrcData->e_addrs[0];
X}
X
Xvoid TopDstData()
X{
X	DstIndex = 0;
X	DstPtr = DstData->e_addrs[0];
X}
X
Xint GetNextSrcData( addr, count )
Xint *addr;
Xint *count;
X{
X
X	if( SrcPtr != NULL ) {
X		
X		*addr = SrcPtr->h_addr;
X		*count = SrcPtr->h_cnt;
X
X		SrcPtr = SrcPtr->h_nxt;
X		return( 1 );
X	} else {
X		SrcIndex++;	
X	}
X
X	while( SrcIndex < HASHSIZE ) {
X
X		SrcPtr = SrcData->e_addrs[SrcIndex];
X
X		if( SrcPtr == NULL ) {
X			SrcIndex++;
X			continue;
X		}
X
X		*addr = SrcPtr->h_addr;
X		*count = SrcPtr->h_cnt;
X
X		SrcPtr = SrcPtr->h_nxt;
X		return( 1 );
X	}
X
X	return( 0 );
X}
X
X
Xint GetNextDstData( addr, count )
Xint *addr;
Xint *count;
X{
X
X	if( DstPtr != NULL ) {
X		
X		*addr = DstPtr->h_addr;
X		*count = DstPtr->h_cnt;
X
X		DstPtr = DstPtr->h_nxt;
X		return( 1 );
X	} else {
X		DstIndex++;	
X	}
X
X	while( DstIndex < HASHSIZE ) {
X
X		DstPtr = DstData->e_addrs[DstIndex];
X
X		if( DstPtr == NULL ) {
X			DstIndex++;
X			continue;
X		}
X
X		*addr = DstPtr->h_addr;
X		*count = DstPtr->h_cnt;
X
X		DstPtr = DstPtr->h_nxt;
X		return( 1 );
X	}
X
X	return( 0 );
X}
X
Xint GetBytesDelta()
X{
X	return( StatData->e_bytes - PrevStatData.e_bytes );
X}
X
Xint GetPacketsDelta()
X{
X	return( StatData->e_packets - PrevStatData.e_packets );
X}
X
Xint GetBCastDelta()
X{
X	return( StatData->e_bcast - PrevStatData.e_bcast );
X}
X
Xint GetNDProtoDelta()
X{
X	return( StatData->e_proto[NDPROTO] - PrevStatData.e_proto[NDPROTO] );
X}
X
Xint GetICMPProtoDelta()
X{
X	return(StatData->e_proto[ICMPPROTO] - PrevStatData.e_proto[ICMPPROTO]);
X}
X
Xint GetUDPProtoDelta()
X{
X	return(StatData->e_proto[UDPPROTO] - PrevStatData.e_proto[UDPPROTO]);
X}
X
Xint GetTCPProtoDelta()
X{
X	return(StatData->e_proto[TCPPROTO] - PrevStatData.e_proto[TCPPROTO]);
X}
X
Xint GetARPProtoDelta()
X{
X	return(StatData->e_proto[ARPPROTO] - PrevStatData.e_proto[ARPPROTO]);
X}
X
Xint GetOtherProtoDelta()
X{
X	return(StatData->e_proto[OTHERPROTO]-PrevStatData.e_proto[OTHERPROTO]);
X}
X
Xlong GetTimeDelta()
X{
X	return( TimeDelta );
X}
X
Xint GetSizeDelta( s )
Xint s;
X{
X	return( StatData->e_size[s] - PrevStatData.e_size[s] );
X}
X
Xfloat GetNetLoad()
X{
X	long bits;
X	int delta;
X	float load;
X
X	bits = (StatData->e_bytes - PrevStatData.e_bytes) * 8;
X	delta = (StatData->e_time.tv_seconds - PrevStatData.e_time.tv_seconds);
X
X	load = (float)((( (double)bits / (double)delta ) / 
X				((double)(10 * 1024 * 1024))) * 100.0);
X
X	return( load );
X
X}
X
Xstatic void FreeHostData( data )
Xetheraddrs *data;
X{
X	etherhmem tmp;
X	int i;
X
X	for( i = 0; i < HASHSIZE; i++ ) {
X		tmp = data->e_addrs[i];
X
X		while( tmp != NULL ) {
X			free( tmp );
X			tmp = tmp->h_nxt;
X		}
X	}
X}
END_OF_FILE
if test 4760 -ne `wc -c <'rpc_stuff.c'`; then
    echo shar: \"'rpc_stuff.c'\" unpacked with wrong size!
fi
# end of 'rpc_stuff.c'
fi
if test -f 'strip.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'strip.c'\"
else
echo shar: Extracting \"'strip.c'\" \(4916 characters\)
sed "s/^X//" >'strip.c' <<'END_OF_FILE'
X/*
X * strip.c
X *
X *
X */
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include "misc.h"
X#include "display.h"
X
X#define MAX_STRIP	(10)
X#define MAX_LABLE	(100)
X
Xstruct strip {
X	char sp_lable[MAX_LABLE];
X	int sp_width;
X	int sp_height;
X	int sp_x;
X	int sp_y;
X	int sp_min;
X	int sp_max;
X	float sp_delta;
X	int *sp_vals;
X	int sp_head;
X	int sp_tail;
X	int sp_cx;
X	int sp_cut;
X	int sp_clear;
X	Window sp_win;
X	int sp_mapped;
X};
X
Xstatic struct strip StripArray[MAX_STRIP];
Xstatic int LastStrip = 0;
X
Xstatic GC StripGC = 0;
X
Xstatic void DrawStripLables();
X
Xvoid RedrawStrip();
X
Xint CreateStrip( lable, min, max, width, height, x, y )
Xchar *lable;
Xint min;
Xint max;
Xint width;
Xint height;
Xint x;
Xint y;
X{
X	char buf[100];
X	int i;
X	int id;
X
X	if( StripGC == 0 ) {
X		StripGC = XCreateGC( Dp, MainWin, 0, NULL );
X		XSetState(Dp,StripGC, ForGndPix, BackGndPix, GXcopy, AllPlanes);
X	}
X
X	id = LastStrip++;
X
X	StripArray[id].sp_width = width;
X	StripArray[id].sp_height = height;
X	StripArray[id].sp_min = min;
X	StripArray[id].sp_max = max;
X	StripArray[id].sp_x = x;
X	StripArray[id].sp_y = y;
X	StripArray[id].sp_mapped = FALSE;
X	StripArray[id].sp_head = 1;
X	StripArray[id].sp_tail = 0;
X	StripArray[id].sp_cx = 1;
X	StripArray[id].sp_clear = 1;
X	
X	StripArray[id].sp_delta = ( (float)height ) /
X						( (float)max - (float)min );
X	
X	StripArray[id].sp_vals = (int *)malloc( sizeof(int) * width );
X	*(StripArray[id].sp_vals+0) = 0;
X	*(StripArray[id].sp_vals+1) = 0;
X	
X	sprintf( buf, "%d", max );
X	StripArray[id].sp_cut = width - ( strlen( buf ) * 5 + 5 );
X
X	strncpy( StripArray[id].sp_lable, lable, MAX_LABLE );
X	strncat( StripArray[id].sp_lable, " ", MAX_LABLE );
X
X	StripArray[id].sp_win = XCreateSimpleWindow( Dp, MainWin, x, y, width,
X					height, 1, ForGndPix, BackGndPix );
X
X	XSelectInput( Dp, StripArray[id].sp_win,
X		ExposureMask|StructureNotifyMask|ButtonPressMask );
X
X	return( id );
X
X}
X
Xvoid ShowStrip( id )
Xint id;
X{
X	XEvent ev;
X
X	XMapWindow( Dp, StripArray[id].sp_win );
X
X	while( 1 ) {
X		XNextEvent( Dp, &ev );
X		if( ev.type == Expose ) {
X			break;
X		}
X	}
X
X	StripArray[id].sp_mapped = TRUE;
X}
X
Xvoid HideStrip( id )
Xint id;
X{
X	XUnmapWindow( Dp, StripArray[id].sp_win );
X	StripArray[id].sp_mapped = FALSE;
X}
X
Xvoid RedrawAllStrips()
X{
X	int i;
X
X	for( i = 0; i < LastStrip; i++ ) {
X		if( StripArray[i].sp_mapped == TRUE ) {
X			RedrawStrip( i );
X		}
X	}
X
X}
X
Xvoid RedrawStrip( id )
Xint id;
X{
X	struct strip *sp;
X	int x1, y1;
X	int x2, y2;
X	int x, y;
X	int i, pc;
X
X	sp = &StripArray[id];
X
X	x1 = 0;
X	y1 = sp->sp_height - *(sp->sp_vals+sp->sp_tail) - 1;
X
X	for( i = 1; i < sp->sp_width; i++ ) {
X
X		pc = ( sp->sp_tail + i ) % sp->sp_width;
X
X		if( pc == sp->sp_head ) break;
X
X		x2 = i;
X		y2 = sp->sp_height - *(sp->sp_vals+pc) - 1;
X
X		XDrawLine( Dp, sp->sp_win, StripGC, x1, y1, x2, y2 );
X
X		x1 = x2;
X		y1 = y2;
X
X	}
X
X	sp->sp_cx = i - 1;
X
X	DrawStripLables( id );
X
X}
X
Xstatic void DrawStripLables( id )
Xint id;
X{
X	struct strip *sp;
X	char buf[1024];
X	int len;
X	int x, y;
X
X	sp = &StripArray[id];
X
X	len = strlen( sp->sp_lable );
X
X	XDrawImageString(Dp, sp->sp_win, Text5x8GC, 1, 8, sp->sp_lable, len);
X
X	sprintf( buf, "%d", sp->sp_max );
X	len = strlen( buf );
X	x = sp->sp_width - ( len * 5 + 1 );
X	y = 8;
X	XDrawImageString(Dp, sp->sp_win, Text5x8GC, x, y, buf, len);
X
X	sprintf( buf, "%d", sp->sp_min );
X	len = strlen( buf );
X	x = sp->sp_width - ( len * 5 + 1 );
X	y = sp->sp_height - 1;
X	XDrawImageString(Dp, sp->sp_win, Text5x8GC, x, y, buf, len);
X
X}
X
Xvoid UpdateStripVal( id, val )
Xint id;
Xint val;
X{
X	struct strip *sp;
X	int val2;
X	char buf[100];
X	int x1, y1;
X	int x2, y2;
X	int i, len;
X
X	sp = &StripArray[id];
X
X	val2 = val;
X
X	if( val > sp->sp_max ) {
X		val = sp->sp_max;
X	}
X
X	sp->sp_head = ( sp->sp_head + 1 ) % sp->sp_width;
X
X	if( sp->sp_head  == sp->sp_tail ) {
X		sp->sp_tail = ( sp->sp_tail + 1 ) % sp->sp_width;
X	}
X
X	*(sp->sp_vals+sp->sp_head) = (int)(sp->sp_delta * (float)val);
X
X	if( sp->sp_cx >= sp->sp_cut ) {
X		int sx;
X
X		sx = sp->sp_cut / 2 + 1;
X		
X		XCopyArea( Dp, sp->sp_win, sp->sp_win, StripGC, sx, 0, 
X				sx, sp->sp_height, 0, 0 );
X		XClearArea( Dp, sp->sp_win, sx, 0, sx, sp->sp_height, False );
X
X		sp->sp_cx = sx;
X		sp->sp_tail = ( sp->sp_tail + sx ) % sp->sp_width;
X		DrawStripLables( id );
X
X	} else {
X		sp->sp_cx++;
X	}
X
X	x1 = sp->sp_cx - 1;
X	
X	if( sp->sp_head == 0 ) {
X		y1 = *(sp->sp_vals + sp->sp_width - 1 );
X	} else {
X		y1 = *(sp->sp_vals + sp->sp_head - 1 );
X	}
X
X	y1 = sp->sp_height - y1 - 1;
X
X	x2 = sp->sp_cx;
X	y2 = sp->sp_height - *(sp->sp_vals + sp->sp_head ) - 1;
X
X	XDrawLine( Dp, sp->sp_win, StripGC, x1, y1, x2, y2 );
X
X	sprintf( buf, "%d%%", val2 );
X	len = strlen( buf );
X
X	x1 = sp->sp_width / 2;
X
X	XSetForeground( Dp, StripGC, BackGndPix );
X	XSetBackground( Dp, StripGC, ForGndPix );
X
X	XFillRectangle( Dp, sp->sp_win, StripGC, x1, 0, sp->sp_clear, 8 );
X
X	XSetForeground( Dp, StripGC, ForGndPix );
X	XSetBackground( Dp, StripGC, BackGndPix );
X
X	XDrawImageString( Dp, sp->sp_win, Text5x8GC, x1, 7, buf, len );
X
X	sp->sp_clear = len * 5;
X}
END_OF_FILE
if test 4916 -ne `wc -c <'strip.c'`; then
    echo shar: \"'strip.c'\" unpacked with wrong size!
fi
# end of 'strip.c'
fi
if test -f 'xtr.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xtr.c'\"
else
echo shar: Extracting \"'xtr.c'\" \(4499 characters\)
sed "s/^X//" >'xtr.c' <<'END_OF_FILE'
X/*
X *
X *
X *
X */
X#include <sys/time.h>
X#include <signal.h>
X#include <stdio.h>
X#include "misc.h"
X
X#define MAIN_STATE	(1)
X#define STAT_STATE	(2)
X#define HOST_STATE	(3)
X#define MASK_STATE	(4)
X
Xextern void DoStats();
Xextern void DoHosts();
Xextern void MakeStatBars();
Xstatic void MakeMainButtons();
Xstatic void Usaged();
Xstatic void TakeDown();
Xstatic void PutUp();
Xstatic void MainLoop();
Xstatic void SigFunc();
Xstatic void TurnOnAlarm();
Xstatic void TurnOffAlarm();
Xstatic void ResetTimer();
X
Xstatic int QuitStat();
Xstatic int StatFunc();
Xstatic int HostsFunc();
Xstatic int MaskFunc();
Xstatic int InvDown();
Xstatic int InvUp();
X
Xstatic void ShowMainButtons();
Xstatic void HideMainButtons();
X
Xstatic int ButQuit;
Xstatic int ButStat;
Xstatic int ButHosts;
Xstatic int ButMask;
Xstatic int ButInvUp;
Xstatic int ButInvDown;
X
X
Xstatic int MainLoopState = MAIN_STATE;
Xstatic int NewState = MAIN_STATE;
Xstatic int MainTimer = 1;
Xstatic int AlarmOn = FALSE;
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X{
X	int id;
X	int i;
X
X	if( argc != 2 ) {
X		Usaged();
X		exit( 1 );
X	}
X
X	InitRPC( argv[1] );
X	InitWin( argv[1] );
X
X
X	MakeStatDisplay();
X	MakeHostDisplay();
X	MakeMaskDisplay();
X	MakeMainButtons();
X
X	SetHost( argv[1] );
X	SetInterval( 1 );
X	signal( SIGALRM, SigFunc );
X
X	FlushDpy();
X
X	MainLoop();
X
X}
X
Xstatic void MainLoop()
X{
X
X
X	while( 1 ) {
X
X		if( NewState != MainLoopState ) {
X			TurnOffAlarm();
X			TakeDown( MainLoopState );
X			PutUp( NewState );
X			MainLoopState = NewState;
X		}
X
X		DoEvents( TRUE );
X	}
X}
X
X
Xvoid ReturnToMain()
X{
X	NewState = MAIN_STATE;
X	TurnOffEther();
X}
X
Xvoid SetMainTimer( t )
Xint t;
X{
X	MainTimer = t;
X	ResetTimer( MainTimer );
X}
X
Xstatic void TurnOffAlarm()
X{
X	struct itimerval value;
X
X	value.it_interval.tv_sec = 0;
X	value.it_interval.tv_usec = 0;
X
X	value.it_value.tv_sec = 0;
X	value.it_value.tv_usec = 0;
X
X	setitimer( ITIMER_REAL, &value, NULL );
X
X	AlarmOn = FALSE;
X}
X
Xstatic void TurnOnAlarm()
X{
X	AlarmOn = TRUE;
X}
X
Xstatic void ResetTimer( t )
Xint t;
X{
X	struct itimerval value;
X
X	if( AlarmOn == TRUE ) {
X		value.it_interval.tv_sec = t;
X		value.it_interval.tv_usec = 0;
X
X		value.it_value.tv_sec = t;
X		value.it_value.tv_usec = 0;
X
X		setitimer( ITIMER_REAL, &value, NULL );
X	}
X}
X
Xstatic void TakeDown( state )
Xint state;
X{
X	switch( state ) {
X
X		case MAIN_STATE:
X			HideMainButtons();
X			break;
X
X		case STAT_STATE:
X			HideStatWindow();	
X			break;
X
X		case HOST_STATE:
X			HideHostWindow();
X			break;
X
X		case MASK_STATE:
X			HideMaskWindow();
X			break;
X
X	}
X}
X
Xstatic void PutUp( state )
Xint state;
X{
X	switch( state ) {
X
X		case MAIN_STATE:
X			ResizeWindow( MWIN_W, MWIN_H );
X			ShowMainButtons();
X			TurnOffAlarm();
X			break;
X
X		case STAT_STATE:
X			ShowStatWindow();	
X			TurnOnAlarm();
X			ResetTimer( MainTimer );
X			break;
X
X		case HOST_STATE:
X			ShowHostWindow();
X			TurnOnAlarm();
X			ResetTimer( MainTimer );
X			break;
X
X		case MASK_STATE:
X			ShowMaskWindow();
X			TurnOffAlarm();
X			break;
X
X	}
X}
X
Xstatic void SigFunc()
X{
X	signal( SIGALRM, SIG_IGN );
X
X	switch( MainLoopState ) {
X
X		case MAIN_STATE:
X			break;
X
X		case STAT_STATE:
X			DoStats();
X			break;
X
X		case HOST_STATE:
X			DoHosts();
X			break;
X
X	}
X
X	signal( SIGALRM, SigFunc );
X}
X
Xstatic void MakeMainButtons()
X{
X	ButQuit = CreateButton( "Quit", 30, 15, 5, 5, QuitStat );
X	ShowButton( ButQuit );
X	RedrawButton( ButQuit );
X
X	ButStat = CreateButton( "Stat", 30, 15, 40, 5, StatFunc );
X	ShowButton( ButStat );
X	RedrawButton( ButStat );
X
X	ButHosts = CreateButton( "Hosts", 35, 15, 75, 5, HostsFunc );
X	ShowButton( ButHosts );
X	RedrawButton( ButHosts );
X
X	ButMask = CreateButton( "Filters", 45, 15, 115, 5, MaskFunc );
X	ShowButton( ButMask );
X	RedrawButton( ButMask );
X
X	ButInvUp = CreateButton( "+", 8, 5, 5, 38, InvUp );
X	ShowButton( ButInvUp );
X	RedrawButton( ButInvUp );
X
X	ButInvDown = CreateButton( "-", 8, 5, 15, 38, InvDown );
X	ShowButton( ButInvDown );
X	RedrawButton( ButInvDown );
X}
X
Xstatic void HideMainButtons()
X{
X	HideButton( ButQuit );
X	HideButton( ButStat );
X	HideButton( ButHosts );
X	HideButton( ButMask );
X}
X
Xstatic void ShowMainButtons()
X{
X	ShowButton( ButHosts );
X	ShowButton( ButStat );
X	ShowButton( ButQuit );
X	ShowButton( ButMask );
X}
X
Xstatic int QuitStat()
X{
X	TurnOffEther();
X	exit( 0 );
X}
X
Xstatic int StatFunc()
X{
X	NewState = STAT_STATE;
X	TurnOnEther();
X}
X
Xstatic int HostsFunc()
X{
X	NewState = HOST_STATE;
X	TurnOnEther();
X}
X
Xstatic int MaskFunc()
X{
X	NewState = MASK_STATE;
X}
X
Xstatic int InvUp()
X{
X	IncInterval();
X}
X
Xstatic int InvDown()
X{
X	DecInterval();
X}
X
Xstatic void Usaged()
X{
X	fprintf( stderr, "xtr: Usage: xtr host\n" );
X}
X
END_OF_FILE
if test 4499 -ne `wc -c <'xtr.c'`; then
    echo shar: \"'xtr.c'\" unpacked with wrong size!
fi
# end of 'xtr.c'
fi
echo shar: End of archive 2 \(of 3\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

--
Dan Heller
------------------------------------------------
O'Reilly && Associates		 Z-Code Software
Senior Writer			       President
argv@ora.com			argv@zipcode.com
------------------------------------------------
General Email: argv@sun.com
Comp-sources-x stuff: comp-sources.x@uunet.uu.net

pochmara@ogicse.cse.ogi.edu (John Pochmara) (03/15/91)

Article-I.D.: ogicse.18620
Posted: Thu Mar 14 10:04:12 1991
Sender: pochmara@ogicse.ogi.edu
Distribution: usa
Organization: Oregon Graduate Institute (formerly OGC), Beaverton, OR
Lines: 828

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 3)."
# Contents:  host.c stat.c
# Wrapped by pochmara@ogicse on Thu Mar 14 10:00:08 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'host.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'host.c'\"
else
echo shar: Extracting \"'host.c'\" \(5918 characters\)
sed "s/^X//" >'host.c' <<'END_OF_FILE'
X/*
X *
X * host.c
X *
X *
X */
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netdb.h>
X#include <netinet/in.h>
X#include <stdio.h>
X#include "bar.h"
X#include "button.h"
X#include "rpc_stuff.h"
X#include "display.h"
X#include "misc.h"
X
X#define HASH_SIZE	(256)
X#define MAX_NAME	(15)
X
X#define SRC_DATA	(1)
X#define DST_DATA	(2)
X
Xstruct host_node {
X	struct in_addr hn_addr;
X	char hn_name[MAX_NAME];
X	int hn_bar;
X	int hn_count;
X	struct host_node *hn_next;
X};
X
X
Xstatic struct host_node *NewHostNode();
Xstatic struct host_node *FindHostByAddr();
Xstatic void ShowHostsBars();
Xstatic void HideHostsBars();
Xstatic struct host_node *InsertHost();
Xstatic void MakeBars();
Xstatic void MakeHostBar();
Xstatic void LeaveFunc();
Xstatic void DataFunc();
Xstatic void ShowHostButtons();
Xstatic void HideHostButtons();
Xstatic void MakeHostButtons();
Xstatic void GetData();
Xstatic int GetNextData();
Xstatic int HashAddr();
X
Xstatic struct host_node HostTable[HASH_SIZE];
X
Xstatic int NumberOfHosts = 0;
Xstatic int ContinueHosts = TRUE;
Xstatic int DataType = SRC_DATA;
X
Xstatic int ButHostCon;
Xstatic int ButData;
X
Xstatic int WindowWidth = 400;
Xstatic int WindowHeight = 400;
X
Xvoid DoHosts()
X{
X	struct host_node *tmp;
X	int addr, count;
X	int delta;
X
X	GetData();
X
X	while( GetNextData( &addr, &count ) != FALSE ) {
X
X		tmp = FindHostByAddr( (unsigned long)addr );
X
X		if( tmp == NULL ) {
X			tmp = InsertHost( (unsigned long)addr );
X			tmp->hn_count = count - 1;
X		}
X
X		delta = count - tmp->hn_count;
X
X		if( delta > 0 ) {
X			if( tmp->hn_bar != -1 ) {
X				UpdateBarVal(tmp->hn_bar, delta );
X				tmp->hn_count = count;
X			} else {
X				MakeHostBar( tmp );
X				ShowBar( tmp->hn_bar );
X				RedrawBar( tmp->hn_bar );
X				UpdateBarVal(tmp->hn_bar, delta );
X			}
X		} else if( tmp->hn_bar != -1 ) {
X			UpdateBarVal(tmp->hn_bar, delta );
X			tmp->hn_count = count;
X		}
X
X	}
X
X	FlushDpy();
X}
X
Xvoid ShowHostWindow()
X{
X	ResizeWindow( WindowWidth, WindowHeight );
X	ShowHostButtons();
X	ShowHostsBars();
X}
X
Xvoid HideHostWindow()
X{
X	HideHostsBars();
X	HideHostButtons();
X}
X
Xstatic void GetData()
X{
X	if( DataType == SRC_DATA ) {
X		GetSrcData();
X		TopSrcData();
X	} else if( DataType == DST_DATA ) {
X		GetDstData();
X		TopDstData();
X	} else {
X		printf( "xtr: Bad DataType.\n" );
X	}
X}
X
Xstatic int GetNextData( addr, count )
Xint *addr;
Xint *count;
X{
X	if( DataType == SRC_DATA ) {
X		return( GetNextSrcData( addr, count ) );
X	} else if( DataType == DST_DATA ) {
X		return( GetNextDstData( addr, count ) );
X	} else {
X		printf( "xtr: Bad DataType.\n" );
X	}
X}
X
Xvoid MakeHostDisplay()
X{
X	struct host_node *tmp;
X	int addr, count;
X	int i;
X
X	MakeHostButtons();
X	
X	for( i = 0; i < HASH_SIZE; i++ ) {
X		HostTable[i].hn_addr.s_addr = 0;
X		HostTable[i].hn_bar = -1;
X		HostTable[i].hn_name[0] = NULL;
X		HostTable[i].hn_next = NULL;
X		HostTable[i].hn_count = 0;
X	}
X
X	WindowWidth = 2 * 200;
X	WindowHeight = 50 * 15 + 70;
X
X	GetSrcData();	/* Prime the pump */
X	TopSrcData();
X
X	while( GetNextSrcData( &addr, &count ) != FALSE ) {
X		tmp = InsertHost( addr );
X		tmp->hn_count = count;
X	}
X
X}
X
Xstatic void MakeHostButtons()
X{
X	ButHostCon = CreateButton( "Exit", 30, 15, 5, 5, LeaveFunc );
X	ButData = CreateButton( "Change to Dst", 80, 15, 40, 5, DataFunc );
X}
X
Xstatic void ShowHostButtons()
X{
X	ShowButton( ButHostCon );
X	ShowButton( ButData );
X}
X
Xstatic void HideHostButtons()
X{
X	HideButton( ButHostCon );
X	HideButton( ButData );
X}
X
Xstatic void LeaveFunc()
X{
X	ReturnToMain();
X}
X
Xstatic void DataFunc()
X{
X	if( DataType == SRC_DATA ) {
X		DataType = DST_DATA;
X		ChangeButtonLable( ButData, "Change to Src" );
X	} else {
X		DataType = SRC_DATA;
X		ChangeButtonLable( ButData, "Change to Dst" );
X	}
X}
X
Xstatic void MakeHostBar( host )
Xstruct host_node *host;
X{
X	static int ncol = 1;
X	static int xpos = 0;
X	static int ypos = 50;
X	static int count = 0;
X	struct hostent *hinfo;
X
X	if( ncol > ( WindowWidth / 200 ) ) {
X		WindowWidth += 200;
X		ResizeWindow( WindowWidth, WindowHeight );
X	}
X
X/*
X	hinfo = gethostbyaddr( (char *)&host->hn_addr.s_addr, 
X				sizeof( host->hn_addr.s_addr ), AF_INET );
X*/
X	hinfo = NULL;
X
X
X	if( hinfo == NULL ) {
X/*
X		strncpy( host->hn_name, inet_ntoa(host->hn_addr), MAX_NAME );
X*/
X		strncpy( host->hn_name, NetAddrToString(&(host->hn_addr)), MAX_NAME );
X	} else {
X		strncpy( host->hn_name, hinfo->h_name, MAX_NAME );
X	}
X
X	host->hn_bar = CreateBarGraph( host->hn_name, 0, 
X				100, 200, 17, FALSE, 90, xpos, ypos);
X			
X	if( count < 50 ) {
X		ypos += 15;
X		count++;
X	} else {
X		ncol++;
X		xpos += 200;
X		ypos = 50;
X		count = 0;
X	}
X
X}
X
Xstatic void ShowHostsBars()
X{
X	struct host_node *tmp;
X	int i;
X
X
X	for( i = 0; i < HASH_SIZE; i++ ) {
X
X		tmp = HostTable[i].hn_next;
X
X		while( tmp != NULL ) {
X
X			if( tmp->hn_bar != -1 ) {
X				ShowBar( tmp->hn_bar );
X				RedrawBar( tmp->hn_bar );
X			}
X
X			tmp = tmp->hn_next;
X		}
X	}
X}
X
Xstatic void HideHostsBars()
X{
X	struct host_node *tmp;
X	int i;
X
X
X	for( i = 0; i < HASH_SIZE; i++ ) {
X		tmp = HostTable[i].hn_next;
X		while( tmp != NULL ) {
X			if( tmp->hn_bar != -1 ) {
X				HideBar( tmp->hn_bar );
X			}
X			tmp = tmp->hn_next;
X		}
X	}
X}
X
Xstatic struct host_node *InsertHost( addr )
Xunsigned long addr;
X{
X	struct host_node *tmp;
X	int hash;
X
X	tmp = NewHostNode();
X
X	tmp->hn_addr.s_addr = addr;
X
X	hash = HashAddr( addr );
X
X	tmp->hn_next = HostTable[hash].hn_next;
X	HostTable[hash].hn_next = tmp;
X
X	NumberOfHosts++;
X
X	return( tmp );
X
X}
X
Xstatic struct host_node *FindHostByAddr( addr )
Xunsigned long addr;
X{
X	struct host_node *tmp;
X	int hash;
X
X	hash = HashAddr( addr );
X
X	tmp = HostTable[hash].hn_next;
X
X	while( tmp != NULL ) {
X		
X		if( tmp->hn_addr.s_addr == addr ) {
X			return( tmp );
X		}
X
X		tmp = tmp->hn_next;
X	}
X
X	return( NULL );
X
X}
X
Xstatic int HashAddr( addr )
Xunsigned long addr;
X{
X	return( addr % HASH_SIZE );
X}
X
Xstatic struct host_node *NewHostNode()
X{
X	struct host_node *tmp;
X
X	tmp = (struct host_node *)malloc( sizeof(struct host_node) );
X
X	tmp->hn_addr.s_addr = 0;
X	tmp->hn_bar = -1;
X	tmp->hn_name[0] = NULL;
X	tmp->hn_next = NULL;
X	
X	return( tmp );
X
X}
X
X
END_OF_FILE
if test 5918 -ne `wc -c <'host.c'`; then
    echo shar: \"'host.c'\" unpacked with wrong size!
fi
# end of 'host.c'
fi
if test -f 'stat.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'stat.c'\"
else
echo shar: Extracting \"'stat.c'\" \(8741 characters\)
sed "s/^X//" >'stat.c' <<'END_OF_FILE'
X/*
X * stat.c
X *
X *
X */
X#include <stdio.h>
X#include "rpc_stuff.h"
X#include "bar.h"
X#include "button.h"
X#include "strip.h"
X#include "display.h"
X#include "misc.h"
X
X
Xstatic void ShowProto();
Xstatic void ShowSizes();
Xstatic void ShowTraffic();
Xstatic void MakeTrafficBars();
Xstatic void MakeProtoBars();
Xstatic void MakeSizesBars();
Xstatic void HideProto();
Xstatic void HideTraffic();
Xstatic void HideSizes();
Xstatic void MakeStatBars();
Xstatic void MakeButtons();
Xstatic void ShowButtons();
Xstatic void HideButtons();
Xstatic void MakeStrips();
Xstatic void ShowStrips();
Xstatic void HideStrips();
X
Xstatic void LeaveFunc();
Xstatic void SizesBut();
Xstatic void TrafficBut();
Xstatic void ProtoBut();
Xstatic void COrPBut();
X
X/* Bar Graphs for Stats Display */
Xstatic int BarBytes;
Xstatic int BarPack;
Xstatic int BarBCast;
X
Xstatic int BarUDP;
Xstatic int BarND;
Xstatic int BarICMP;
Xstatic int BarTCP;
Xstatic int BarARP;
Xstatic int BarOther;
X
Xstatic int BarSizes[16];
X
X/* Buttons for Stats display */
Xstatic int ButProto;
Xstatic int ButTraffic;
Xstatic int ButSizes;
Xstatic int ButCon;
Xstatic int ButCOrP;
X
X/* Strips of Stat display */
Xstatic int StrLoad;
X
Xstatic int DisplayProto = TRUE;
Xstatic int DisplayTraffic = TRUE;
Xstatic int DisplaySizes = TRUE;
X
Xstatic int PerSecond = TRUE;
X
Xvoid DoStats()
X{
X	long td;
X	int j;
X
X	GetStatData();
X
X	if( PerSecond == TRUE ) {
X		td = GetTimeDelta();
X	} else {
X		td = 1;
X	}
X		
X	if( DisplayTraffic == TRUE ) {
X		UpdateBarVal( BarBytes, GetBytesDelta()/td );
X		UpdateBarVal( BarPack, GetPacketsDelta()/td );
X		UpdateBarVal( BarBCast, GetBCastDelta()/td );
X	}
X
X	if( DisplayProto == TRUE ) {
X		UpdateBarVal( BarND, GetNDProtoDelta()/td );
X		UpdateBarVal( BarUDP, GetUDPProtoDelta()/td );
X		UpdateBarVal( BarICMP, GetICMPProtoDelta()/td );
X		UpdateBarVal( BarTCP, GetTCPProtoDelta()/td );
X		UpdateBarVal( BarARP, GetARPProtoDelta()/td );
X		UpdateBarVal( BarOther, GetOtherProtoDelta()/td );
X	}
X
X	if( DisplaySizes == TRUE ) {
X		for( j = 0; j < 16; j++ ) {
X			UpdateBarVal( BarSizes[j],GetSizeDelta( j )/td);
X		}
X	}
X
X	UpdateStripVal( StrLoad, (int)GetNetLoad() );
X
X	FlushDpy();
X}
X
Xvoid ShowStatWindow()
X{
X	ResizeWindow( 400, 295 );
X	ShowSizes();
X	ShowProto();
X	ShowTraffic();
X	ShowButtons();
X	ShowStrips();
X}
X
Xvoid HideStatWindow()
X{
X	HideProto();
X	HideTraffic();
X	HideSizes();
X	HideButtons();
X	HideStrips();
X}
X
Xvoid MakeStatDisplay()
X{
X	MakeStatBars();
X	MakeButtons();
X	MakeStrips();
X}
X
Xstatic void MakeStatBars()
X{
X	MakeTrafficBars();
X	MakeProtoBars();
X	MakeSizesBars();
X}
X
Xstatic void MakeTrafficBars()
X{
X	int val;
X
X	val = GetDefaultValInt( "Maxbytes", 20000 );
X	BarBytes = CreateBarGraph( "bytes", 0, val, 400, 17, 
X							FALSE, 60, 0, 55 );
X
X	val = GetDefaultValInt( "Maxpackets", 500 );
X	BarPack = CreateBarGraph( "packets", 0, val, 400, 17, 
X							FALSE, 60, 0, 70 );
X
X	val = GetDefaultValInt( "Maxbroadcast", 100 );
X	BarBCast = CreateBarGraph("broadcast", 0, val, 400, 17, 
X							FALSE, 60, 0, 85 );
X}
X
Xstatic void MakeProtoBars()
X{
X	int val;
X
X	val = GetDefaultValInt( "MaxUDP", 100 );
X	BarUDP = CreateBarGraph("UDP", 0, val, 400, 17, FALSE, 60, 0, 105 );
X
X	val = GetDefaultValInt( "MaxTCP", 100 );
X	BarTCP = CreateBarGraph("TCP", 0, val, 400, 17, FALSE, 60, 0, 120 );
X
X	val = GetDefaultValInt( "MaxICMP", 100 );
X	BarICMP = CreateBarGraph("ICMP", 0, val, 200, 17, FALSE, 60, 0, 135 );
X
X	val = GetDefaultValInt( "MaxARP", 100 );
X	BarARP = CreateBarGraph("ARP", 0, val, 200, 17, FALSE, 60, 200, 135 );
X
X	val = GetDefaultValInt( "MaxND", 100 );
X	BarND = CreateBarGraph("ND", 0, val, 200, 17, FALSE, 60, 0, 150 );
X
X	val = GetDefaultValInt( "MaxOther", 100 );
X	BarOther = CreateBarGraph("Other", 0, val, 200, 17, 
X							FALSE, 60, 200, 150 );
X}
X
Xstatic void MakeSizesBars()
X{
X	int val;
X
X	val = GetDefaultValInt( "MaxSize60", 100 );
X	BarSizes[0] = CreateBarGraph("60 - 150", 0, val, 200, 17, 
X							FALSE, 70, 0, 170 );
X
X	val = GetDefaultValInt( "MaxSize151", 100 );
X	BarSizes[1] = CreateBarGraph("151 - 240", 0, val, 200, 17, 
X							FALSE, 70, 0, 185 );
X
X	val = GetDefaultValInt( "MaxSize241", 100 );
X	BarSizes[2] = CreateBarGraph("241 - 330", 0, val, 200, 17, 
X							FALSE, 70, 0, 200 );
X
X	val = GetDefaultValInt( "MaxSize331", 100 );
X	BarSizes[3] = CreateBarGraph("331 - 420", 0, val, 200, 17, 
X							FALSE, 70, 0, 215 );
X
X	val = GetDefaultValInt( "MaxSize421", 100 );
X	BarSizes[4] = CreateBarGraph("421 - 510", 0, val, 200, 17, 
X							FALSE, 70, 0, 230 );
X
X	val = GetDefaultValInt( "MaxSize511", 100 );
X	BarSizes[5] = CreateBarGraph("511 - 600", 0, val, 200, 17, 
X							FALSE, 70, 0, 245 );
X
X	val = GetDefaultValInt( "MaxSize601", 100 );
X	BarSizes[6] = CreateBarGraph("601 - 690", 0, val, 200, 17, 
X							FALSE, 70, 0, 260 );
X
X	val = GetDefaultValInt( "MaxSize691", 100 );
X	BarSizes[7] = CreateBarGraph("691 - 780", 0, val, 200, 17, 
X							FALSE, 70, 0, 275 );
X
X	val = GetDefaultValInt( "MaxSize781", 100 );
X	BarSizes[8] = CreateBarGraph("781 - 870", 0, val, 200,17,
X							FALSE,70,200,170);
X
X	val = GetDefaultValInt( "MaxSize871", 100 );
X	BarSizes[9] = CreateBarGraph("871 - 960", 0, val, 200,17, 
X							FALSE, 70, 200,185);
X
X	val = GetDefaultValInt( "MaxSize961", 100 );
X	BarSizes[10] = CreateBarGraph("961 - 1050",0,val, 200,17, 
X							FALSE, 70, 200,200);
X
X	val = GetDefaultValInt( "MaxSize1051", 100 );
X	BarSizes[11] = CreateBarGraph("1051 - 1140",0,val,200,17, 
X							FALSE, 70, 200,215);
X
X	val = GetDefaultValInt( "MaxSize1141", 100 );
X	BarSizes[12] = CreateBarGraph("1141 - 1230",0,val,200,17,
X							 FALSE, 70, 200,230);
X
X	val = GetDefaultValInt( "MaxSize1231", 100 );
X	BarSizes[13] = CreateBarGraph("1231 - 1320",0,val,200,17, 
X							FALSE, 70, 200,245);
X
X	val = GetDefaultValInt( "MaxSize1321", 100 );
X	BarSizes[14] = CreateBarGraph("1321 - 1410",0,val,200,17, 
X							FALSE, 70, 200,260);
X
X	val = GetDefaultValInt( "MaxSize1410", 100 );
X	BarSizes[15] = CreateBarGraph("1410 - 1514",0,val,200,17, 
X							FALSE, 70, 200,275);
X}
X
Xstatic void ShowSizes()
X{
X	int i;
X
X	for( i = 0; i < 16; i++ ) {
X		ShowBar( BarSizes[i] );
X		RedrawBar( BarSizes[i] );
X	}
X
X}
X
Xstatic void HideSizes()
X{
X	int i;
X
X	for( i = 0; i < 16; i++ ) {
X		HideBar( BarSizes[i] );
X	}
X}
X	
X
Xstatic void ShowTraffic()
X{
X	ShowBar( BarBCast );
X	RedrawBar( BarBCast );
X
X	ShowBar( BarBytes );
X	RedrawBar( BarBytes );
X
X	ShowBar( BarPack );
X	RedrawBar( BarPack );
X
X}
X
Xstatic void HideTraffic()
X{
X	HideBar( BarBCast );
X	HideBar( BarBytes );
X	HideBar( BarPack );
X}
X
Xstatic void ShowProto()
X{
X
X	ShowBar( BarUDP );
X	RedrawBar( BarUDP );
X
X	ShowBar( BarICMP );
X	RedrawBar( BarICMP );
X
X	ShowBar( BarND );
X	RedrawBar( BarND );
X
X	ShowBar( BarTCP );
X	RedrawBar( BarTCP );
X
X	ShowBar( BarARP );
X	RedrawBar( BarARP );
X
X	ShowBar( BarOther );
X	RedrawBar( BarOther );
X
X}
X
Xstatic void HideProto()
X{
X	HideBar( BarUDP );
X	HideBar( BarICMP );
X	HideBar( BarND );
X	HideBar( BarTCP );
X	HideBar( BarARP );
X	HideBar( BarOther );
X
X}
X
Xstatic void ProtoBut()
X{
X
X	if( DisplayProto == TRUE ) {
X		HideProto();
X		ChangeButtonLable( ButProto, "Proto On" );
X		DisplayProto = FALSE;
X	} else {
X		ShowProto();
X		ChangeButtonLable( ButProto, "Proto Off" );
X		DisplayProto = TRUE;
X	}
X}
X
Xstatic void TrafficBut()
X{
X
X	if( DisplayTraffic == TRUE ) {
X		HideTraffic();
X		ChangeButtonLable( ButTraffic, "Traffic On" );
X		DisplayTraffic = FALSE;
X	} else {
X		ShowTraffic();
X		ChangeButtonLable( ButTraffic, "Traffic Off" );
X		DisplayTraffic = TRUE;
X	}
X}
X
Xstatic void SizesBut()
X{
X
X	if( DisplaySizes == TRUE ) {
X		HideSizes();
X		ChangeButtonLable( ButSizes, "Sizes On" );
X		DisplaySizes = FALSE;
X	} else {
X		ShowSizes();
X		ChangeButtonLable( ButSizes, "Sizes Off" );
X		DisplaySizes = TRUE;
X	}
X}
X
Xstatic void COrPBut()
X{
X	if( PerSecond == TRUE ) {
X		ChangeButtonLable( ButCOrP, "Cumulative" );
X		PerSecond = FALSE;
X	} else {
X		ChangeButtonLable( ButCOrP, "Per/sec" );
X		PerSecond = TRUE;
X	}
X}
X
Xstatic void LeaveFunc()
X{
X	ReturnToMain();
X}
X
Xstatic void MakeStrips()
X{
X	int val;
X
X	val = GetDefaultValInt( "MaxLoad", 20 );
X	StrLoad = CreateStrip( "Load", 0, val, 250, 25, 125, 25 );
X}
X
Xstatic void ShowStrips()
X{
X	ShowStrip( StrLoad );
X	RedrawStrip( StrLoad );
X}
X
Xstatic void HideStrips()
X{
X	HideStrip( StrLoad );
X}
X
Xstatic void MakeButtons()
X{
X	ButCon = CreateButton( "Exit", 30, 15, 5, 5, LeaveFunc );
X	ButTraffic = CreateButton( "Traffic Off", 75, 15, 40, 5, TrafficBut );
X	ButProto = CreateButton( "Proto Off", 65, 15, 120, 5, ProtoBut );
X	ButSizes = CreateButton( "Sizes Off", 65, 15, 190, 5, SizesBut );
X	ButCOrP = CreateButton( "Per/sec", 65, 15, 260, 5, COrPBut );
X
X}
X
Xstatic void ShowButtons()
X{
X	ShowButton( ButCon );
X	ShowButton( ButProto );
X	ShowButton( ButTraffic );
X	ShowButton( ButSizes );
X	ShowButton( ButCOrP );
X}
X
Xstatic void HideButtons()
X{
X	HideButton( ButCon );
X	HideButton( ButProto );
X	HideButton( ButTraffic );
X	HideButton( ButSizes );
X	HideButton( ButCOrP );
X}
END_OF_FILE
if test 8741 -ne `wc -c <'stat.c'`; then
    echo shar: \"'stat.c'\" unpacked with wrong size!
fi
# end of 'stat.c'
fi
echo shar: End of archive 3 \(of 3\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

--
Dan Heller
------------------------------------------------
O'Reilly && Associates		 Z-Code Software
Senior Writer			       President
argv@ora.com			argv@zipcode.com
------------------------------------------------
General Email: argv@sun.com
Comp-sources-x stuff: comp-sources.x@uunet.uu.net