pochmara@cse.ogi.edu (John Pochmara) (03/20/91)
Submitted-by: John Pochmara <pochmara@cse.ogi.edu> Posting-number: Volume 12, Issue 45 Archive-name: xtr/part02 Path: ogicse!ogicse.cse.ogi.edu!pochmara From: pochmara@ogicse.cse.ogi.edu (John Pochmara) Newsgroups: comp.sources.x Subject: xtr - X front end to etherd (Part 2/3) Message-ID: <18619@ogicse.ogi.edu> Date: 14 Mar 91 18:03:29 GMT 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