#! /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 shell archive."
# Contents:  Makefile README README.vms agg.awk aggday.awk ciscotalk.c
#   ciscotalk_vms.c getipacct.sh hosts.awk martians.sh nameipacct.c
#   nameipacct_vms.c sum.awk
# Wrapped by schaefer@dirt on Fri Jul 12 09:53:07 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(2332 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# get cisco IP accounting stuff
X# 1.5 90/06/20
X#
X###### configuration
X
X# directory where the binaries and scripts go
XETCDIR = /usr/local/etc
X# file for the raw accounting data
XLOGFILE = /usr/spool/log/ipacct
X# file for the processed and compressed accounting samples
XCOMPFILE = /usr/spool/log/ipcomp
X
X# command to query ripe database (comment out if you don't have this)
XRIPEDBCMD = /usr/local/net
X
X# maximum number of values in summaries
XNTOP = 30
X# cutoff percentage for summaries 
X# (lines representing less traffic are suppressed)
XCUTPCT = 1
X
X# default gateway
XSERVER = cwi-gw.cwi.nl
X
X# prompts for input during dialogue
X# these should really be determined by the program
XPROMPT1 = Password:
XPROMPT2 = cwi-gw>
XPROMPT3 = cwi-gw\#
X
X# the passwords 
XNORMALPASSWORD = example
XENABLEPASSWORD = example
X
X#########################################
X
XCFLAGS = -O
XTARGETS = getipacct nameipacct ciscotalk
X
Xall: $(TARGETS)
X
Xparam.sed: Makefile
X	echo "s:ETCDIR:$(ETCDIR):g" >param.sed
X	echo "s:LOGFILE:$(LOGFILE):g" >>param.sed
X	echo "s:COMPFILE:$(COMPFILE):g" >>param.sed
X	echo "s:NTOP:$(NTOP):g" >>param.sed
X	echo "s:CUTPCT:$(CUTPCT):g" >>param.sed
X	echo "s:NORMALPASSWORD:$(NORMALPASSWORD):g" >>param.sed
X	echo "s:ENABLEPASSWORD:$(ENABLEPASSWORD):g" >>param.sed
X	chmod 600 param.sed
X
Xciscotalk.h: Makefile
X	echo '#define SERVER "$(SERVER)"' > ciscotalk.h
X	echo '#define PROMPT1 "$(PROMPT1)"' >> ciscotalk.h
X	echo '#define PROMPT2 "$(PROMPT2)"' >> ciscotalk.h
X	echo '#define PROMPT3 "$(PROMPT3)"' >> ciscotalk.h
X
Xnameipacct.h: Makefile
X	echo '#define RIPEDBCMD "$(RIPEDBCMD)"' >> nameipacct.h
X
Xciscotalk: ciscotalk.h ciscotalk.c
X	$(CC) $(CFLAGS) -o ciscotalk ciscotalk.c
X
Xnameipacct: nameipacct.h nameipacct.c
X	$(CC) $(CFLAGS) -o nameipacct nameipacct.c
X
Xgetipacct: getipacct.sh param.sed
X	sed -f param.sed  <getipacct.sh >getipacct
X	chmod 700 getipacct
X
Xinstall: $(TARGETS)
X	cp ciscotalk getipacct nameipacct $(ETCDIR)
X	chmod 700 $(ETCDIR)/getipacct
X	chmod 770 $(ETCDIR)/ciscotalk
X	chmod 770 $(ETCDIR)/nameipacct
X	
Xagg:	$(LOGFILE) agg.awk
X	awk -f agg.awk <$(LOGFILE) | sort -rn +3 >agg
Xclean: 
X	rm -f $(TARGETS) *.o ,* core tmp* param.sed ciscotalk.h nameipacct.h
X
Xdistrib: 
X	mv Makefile Makefile.bak
X	sed -f distrib.sed <Makefile.bak >Makefile
X	packmail -odistrib -t'ipacct stuff' `cat DISTRIB`
X	rm -f Makefile
X	mv Makefile.bak Makefile
END_OF_FILE
if test 2332 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2860 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X1.4 90/06/20
X
XThis is a bunch of stuff to read out IP accounting data from CISCO
Xgateways and some few attempts at processing that data in menaingful
Xways. 
X
X
X	It certainly is not finished nor polished ! 
X
X
XThe data is read and stored in a standard format whioch can be processed
Xby various scripts.  This format consists of blank separated lines.  The
Xnormal data line has four fields:
X
X	<ip-from> <ip-to> <npackets> <nbytes>
X
XExample:
X
X	192.16.202.1   128.96.128.120   4   272
X
X
XA line beginning with the word "SAMPLE" separates the different samples
Xand gives the date and time for the sample represented by the data lines
Xthat follow the SAMPLE line:
X
X	SAMPLE <year> <month> <day> <hour> <minutes> <seconds>
X
XExample:
X
X	SAMPLE 90 04 12 15 00 06
X
X
XThe data can also be stored in a summary form.  Currently one summary
Xform giving the <NTOP> data lines with the most bytes transferred is
Xproduced.  Lines representing less than
X<CUTPCT> percent of the traffic are suppressd. In addition a SUM
Xline is produced giving the total number of data lines and the sums of
Xpackets and bytes:
X
X	SUM <npairs> <packets> <bytes>
X
XExample:
X
X	SUM 539 75950 15647439
X
X
X
XFiles in this distribution:
X
X Makefile		obvious
X			This file has all configuration parameters
X			(passwords, prompts). Be sure to protect it. 
X
X
X ciscotalk.c		simple minded program to talk
X			to the cisco console and get information.
X			This just ignores the TELNET protocol
X
X getipacct.sh		Shell script to run periodically (from cron)
X			to read out samples. I appends to a file
X			containing raw samples and to a file containing
X			summaries. Some tuning can be done in the
X			file itself. This will be edited into
X			getipacct which will actually be run.
X			getipacct will contain paswords. so be careful.
X
X martians.sh		script to detect martian packets in the logging files
X
X nameipacct.c		translates IP addresses to DNS names
X			and makes output more readable
X
X agg.awk		awk script to do aggregates of sample files
X
X aggday.awk		day by day aggregation
X
X sum.awk		do byte and packet sums
X
X hosts.awk		do sums by hosts
X
X
XInstallation:
X
X- Edit Makefile and set the configuration parameters to apropriate
Xvalues for your site. 
X
X- make install
X
X- Try "getipacct" to see if it creates both files and if they contain
Xwhat you expect (be sure the cisco concerned has accounting turned on)
X
X- arrange for cron to call getipacct regularly
X
X- arrange for the files to be cleaned up regularly
X
X
X
XI am very grateful for comments and more data reducing software.  I am
Xalso interested in generating alarms from the samples in real time. 
XExample: This host uses more than 50% of a line! 
X
X
XAlso:
X	Maybe a database of what has been used by hosts (perl script with dbm)?
X	A perpetual list of hosts that a gateway has ever seen:
X		"This gateway has been used by 30.000 hosts last month".
X
XDaniel <dfk@mcsun.eu.net>
END_OF_FILE
if test 2860 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'README.vms' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README.vms'\"
else
echo shar: Extracting \"'README.vms'\" \(550 characters\)
sed "s/^X//" >'README.vms' <<'END_OF_FILE'
X        Please find  enclosed  the versions of ciscotalk.c and of
Xipname.c (my  version  of  nameipacct.c).  The header ciscotalk.h
Xhas not been changed so I don't copy it.  On my VMS  system I use
XUCX V1.3, but I  think  that  the  programs should run as well on
XMultinet and possibly Wollongong (I  never  tried,  anyway)  when
Xlinked with the appropriate library (in my case, UCX$IPC).
X
X        Davide Salomoni
X        INFN/CNAF
X        v.le Ercolani, 8
X        I-40128 Bologna (Italy)
X        Tel. + 39-51-498267
X        salomoni@deccnaf.infn.it
END_OF_FILE
if test 550 -ne `wc -c <'README.vms'`; then
    echo shar: \"'README.vms'\" unpacked with wrong size!
fi
# end of 'README.vms'
fi
if test -f 'agg.awk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'agg.awk'\"
else
echo shar: Extracting \"'agg.awk'\" \(257 characters\)
sed "s/^X//" >'agg.awk' <<'END_OF_FILE'
X# 1.1 90/02/07  dfk@cwi.nl
X
X/[0-9]*\.[0-9]*\./ {
X
X	bytes[$1 " " $2] += $4;
X	packets[$1 " " $2] += $3;
X}
X
XEND {
X
X	for (i in bytes)
X	{
X		split(i, fromto);
X		printf "%-16.16s %-16.16s ", fromto[1], fromto[2];
X		printf "%10d %15d\n", packets[i], bytes[i];
X	}
X}
END_OF_FILE
if test 257 -ne `wc -c <'agg.awk'`; then
    echo shar: \"'agg.awk'\" unpacked with wrong size!
fi
# end of 'agg.awk'
fi
if test -f 'aggday.awk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'aggday.awk'\"
else
echo shar: Extracting \"'aggday.awk'\" \(823 characters\)
sed "s/^X//" >'aggday.awk' <<'END_OF_FILE'
X# 1.1 90/04/12 dfk@cwi.nl
X
XBEGIN {
X	first = 1;
X	pct = .5;
X}
X
X/^SAMPLE/ {
X	if (first)
X		first = 0;
X	else 
X	{
X		if ($4 != day)
X		{
X			print sampl;
X			printf "\n";
X
X			thresh = sb*pct/100;
X			for (i in bytes)
X			{
X				if (bytes[i]>thresh)
X				{
X					printf "%-33.33s ", i;
X					printf "%10d ", packets[i];
X					printf "%15d\n", bytes[i];
X				} 
X				packets[i] = 0;
X				bytes[i] = 0;
X			}
X			printf "\n\n";
X			sb = 0;
X		}
X	}
X	sampl = $0;
X	day = $4;
X}
X
X/[0-9]*\.[0-9]*\./ {
X
X	bytes[$1 " " $2] += $4;
X	packets[$1 " " $2] += $3;
X	sb += $4;
X}
X
XEND {
X	if (first)
X		first = 0;
X	else 
X	{
X		if ($4 != day)
X		{
X			print sampl;
X			printf "\n";
X			for (i in bytes)
X			{
X				if (packets[i]>thresh)
X				{
X					printf "%-33.33s ", i;
X					printf "%10d ", packets[i];
X					printf "%15d\n", bytes[i];
X				} 
X			}
X			printf "\n\n"; 
X		} 
X	} 
X}
END_OF_FILE
if test 823 -ne `wc -c <'aggday.awk'`; then
    echo shar: \"'aggday.awk'\" unpacked with wrong size!
fi
# end of 'aggday.awk'
fi
if test -f 'ciscotalk.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ciscotalk.c'\"
else
echo shar: Extracting \"'ciscotalk.c'\" \(2099 characters\)
sed "s/^X//" >'ciscotalk.c' <<'END_OF_FILE'
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <stdio.h>
X#include <netdb.h>
X
X#include "ciscotalk.h"
X
Xextern char *index();
Xextern char *optarg;
Xextern int optind;
X
Xchar host[255] = SERVER;
Xchar lbuf[80];
Xchar verbose = 0;
X
X
X/*   1.1 90/02/07 dfk@cwi.nl */
X
Xmain(argc, argv)
Xint argc; char **argv;
X{
X
X	register int i;
X	register int s;
X	char c;
X	struct sockaddr_in sin;
X	struct hostent *hp;
X	struct servent *sp;
X	register FILE *socks;
X
X	while ((i=getopt(argc, argv, "vh:")) != EOF)
X	{
X		switch(i)
X		{
X		case 'h':
X			strncpy(host, optarg, sizeof(host));
X			break;
X
X		case 'v':
X			verbose++;
X			break;
X
X		case '?':
X			fprintf(stderr, "usage: ciscotalk [-h host]\n");
X			exit(1);
X		}
X	}
X
X	if ((hp=gethostbyname(host)) == NULL)
X	{
X		fprintf(stderr, "ciscotalk: %s unknown\n", host);
X		exit(1);
X	}
X
X	if ((s=socket(hp->h_addrtype, SOCK_STREAM, 0)) <0)
X	{
X		perror("ciscotalk: cannot create socket");
X		exit(1);
X	}
X
X	if ((sp=getservbyname("telnet", "tcp")) == NULL)
X	{
X		fprintf(stderr, "ciscotalk: can't find service\n");
X		exit(1);
X	}
X
X	sin.sin_family = hp->h_addrtype;
X	bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
X	sin.sin_port = sp->s_port;
X
X	if (verbose)
X		fprintf(stderr, "connecting to %s ...\n\n", hp->h_name);
X
X	if (connect(s, &sin, sizeof (sin), 0) < 0) 
X	{
X		perror("ciscotalk: connect");
X		exit(1);
X	}
X
X	if ((socks= fdopen(s, "r")) == NULL)
X	{
X		perror("ciscotalk: fdopen");
X		exit(0);
X	}
X
X		sleep(1);
X		write(s, "\r\n", 2);
X		readcmd(socks);
X		while(read(0, &c, 1) == 1)
X		{
X			if (c == '\n')
X			{
X				write(s, "\r\n", 2);
X				readcmd(socks);
X			}
X			else
X				write(s, &c, 1);
X		}
X		exit(0);
X}
X
Xreadcmd(fd)
XFILE *fd;
X{
X		while (fgets(lbuf, sizeof(lbuf)-1, fd) !=NULL)
X		{
X			fputs(lbuf, stdout);
X			if (   occurs(lbuf, PROMPT1) 
X			    || occurs(lbuf, PROMPT2)
X			    || occurs(lbuf, PROMPT3)
X			   )
X			{
X				fflush(stdout);
X				return;
X			}
X		}
X		fflush(stdout);
X}
X
Xoccurs(str, pat)
Xchar *str, *pat;
X{
X	register char *point = str;
X
X	while (point=index(point, *pat))
X	{
X		if (strncmp(point, pat, strlen(pat)) == 0)
X			return(1);
X		point++;
X	}
X	return(0);
X}
END_OF_FILE
if test 2099 -ne `wc -c <'ciscotalk.c'`; then
    echo shar: \"'ciscotalk.c'\" unpacked with wrong size!
fi
# end of 'ciscotalk.c'
fi
if test -f 'ciscotalk_vms.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ciscotalk_vms.c'\"
else
echo shar: Extracting \"'ciscotalk_vms.c'\" \(3119 characters\)
sed "s/^X//" >'ciscotalk_vms.c' <<'END_OF_FILE'
X/* ciscotalk.c
X *
X * portable across unix/ultrix & vms systems
X * first version (90/02/07) by Daniel Karrenberg (dfk@cwi.nl)
X * this version (91/07/08) by Davide Salomoni (salomoni@cnaf.infn.it)
X * to be linked on VMS systems with the appropriate socket library and 
X * with a version of the getopt() function.
X */
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <netdb.h>
X
X#ifdef VAXC
X#include <unixio.h>
X#include <types.h>
X#include <socket.h>
X#include <in.h>
X#else
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#endif
X
X#include "ciscotalk.h"
X
Xextern int getopt(int, char **, char *);
Xstatic char *iogets(char *string,int n,int descr);
Xstatic readcmd(int s);
X
Xchar host[255] = SERVER;
Xchar lbuf[80];
Xchar verbose = 0;
X
Xmain(int argc, char **argv)
X{
X
X	extern int optind;
X	extern char *optarg;
X	int i,s;
X	char c;
X	static struct sockaddr_in sin;
X	struct hostent *hp,hs;
X	struct servent *sp;
X
X	while ((i=getopt(argc,argv,"vh:"))!=EOF) {
X		switch(i) {
X			case 'h':
X				strncpy(host,optarg,sizeof(host));
X				break;
X			case 'v':
X				verbose++;
X				break;
X			case '?':
X				fprintf(stderr,"usage: ciscotalk [-vh host]\n");
X				exit(1);
X		}
X	}
X
X	if ((hp=gethostbyname(host)) == NULL) {
X		fprintf(stderr, "ciscotalk: %s unknown\n", host);
X		exit(1);
X	}
X	hs = *hp;
X	/*
X	 * hp is a pointer to a static area that could be overwritten by
X	 * other processes or by a subsequent call to a function that uses
X	 * the same area; it's therefore necessary to copy the data to a safe
X	 * place.
X	 */
X
X	if ((s=socket(hs.h_addrtype, SOCK_STREAM, 0)) <0) {
X		perror("ciscotalk: cannot create socket");
X		exit(1);
X	}
X
X#ifdef VAXC
X/* 
X * the vms/ultrix connection does not support the getservbyname() function,
X * so we define the port statically converting it first to network byte order.
X */
X	sin.sin_port = htons(23);
X#else
X	if ((sp=getservbyname("telnet", "tcp")) == NULL)
X	{
X		fprintf(stderr, "ciscotalk: can't find service\n");
X		exit(1);
X	}
X	sin.sin_port = sp->s_port;
X#endif
X
X	sin.sin_family = hs.h_addrtype;
X	sin.sin_addr = * ((struct in_addr *) hs.h_addr);
X
X	if (verbose)
X		fprintf(stderr, "connecting to %s ...\n\n", hp->h_name);
X
X	if (connect(s, &sin, sizeof (sin))) {
X		perror("ciscotalk: connect");
X		exit(1);
X	}
X
X	sleep(1);
X	write(s, "\r\n", 2);
X	readcmd(s);
X	while (read(0,&c,1) ==1) {
X		if (c=='\n') {
X			write(s,"\r\n",2);
X			readcmd(s);
X		}
X		else
X			write(s, &c, 1);
X	}
X	exit(0);
X
X}
X
X
X/*
X * read a line from the socket using the low-level i/o, since the vms/ultrix
X * connection does not support standard i/o with sockets.
X */
Xstatic readcmd(int s)
X{
X	while (iogets(lbuf,sizeof(lbuf)-1,s)) {
X		fputs(lbuf,stdout);
X		if (strstr(lbuf,PROMPT1) || 
X		    strstr(lbuf,PROMPT2) || 
X		    strstr(lbuf,PROMPT3)) {
X			fflush(stdout);
X			return;
X		}
X	}
X	fflush(stdout);
X}
X
X
X/* iogets() works like fgets() but uses low-level i/o functions. */
Xstatic char *iogets(char *string,int n,int descr)
X{
X	char ch;
X	int i;
X
X	if (!n) return((string=NULL));
X	i=0;
X	while (read(descr,&ch,1)==1) {
X		string[i]=ch;
X		if (++i==n || ch=='\n') {
X			string[i]='\0';
X			return(string);
X		}
X	}
X	return(NULL);
X}
END_OF_FILE
if test 3119 -ne `wc -c <'ciscotalk_vms.c'`; then
    echo shar: \"'ciscotalk_vms.c'\" unpacked with wrong size!
fi
# end of 'ciscotalk_vms.c'
fi
if test -f 'getipacct.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getipacct.sh'\"
else
echo shar: Extracting \"'getipacct.sh'\" \(1716 characters\)
sed "s/^X//" >'getipacct.sh' <<'END_OF_FILE'
X#!/bin/sh
X#
X# 1.2 90/04/12
X
Xumask 077
X
X# remove tempfiles upon exit or interruption
Xtrap "rm -f /tmp/getipacct*.$$" 0 1 2
X
X# create awk script to reduce and mark cisco output with date
Xcat <<'EOF' >/tmp/getipacctawk.$$
XBEGIN {
X	months["Jan"] = 1;
X	months["Feb"] = 2;
X	months["Mar"] = 3;
X	months["Apr"] = 4;
X	months["May"] = 5;
X	months["Jun"] = 6;
X	months["Jul"] = 7;
X	months["Aug"] = 8;
X	months["Sep"] = 9;
X	months["Oct"] = 10;
X	months["Nov"] = 11;
X	months["Dec"] = 12;
X}
X
XNR==1{
X	year = substr($NF, 3, 2);
X	month = months[$2];
X	day = $3;
X	split($4, time, ":");
X	hour = time[1];
X	minutes = time[2];
X	seconds = time[3] + 6;
X	
X	printf "\nSAMPLE %02d %02d %02d %02d %02d %02d\n\n", year, month, day, hour, minutes, seconds;
X}
XEOF
X
X
X# put date in a file
X#
Xdate | awk -f /tmp/getipacctawk.$$  >/tmp/getipacctlog.$$
X
Xcat <<'EOF' >/tmp/getipacctawk.$$
X/ [0-9]*\.[0-9]*\.[0-9]*/ {
X	$4 = substr($4, 1, length($4)-1);
X	printf "%s %s %d %d\n", $1, $2, $3, $4;
X}
XEOF
X
X# get cisco data, compress, sort and append to file
X#
XETCDIR/ciscotalk <<'EOF'  | awk -f /tmp/getipacctawk.$$ \
X| sort -rn +3 >> /tmp/getipacctlog.$$
XNORMALPASSWORD
Xterm len 0
Xshow ip acc
Xena
XENABLEPASSWORD
Xclear ip acc
Xclear ip acc
Xquit
XEOF
X
X
X# append file to logfile
X#
Xcat /tmp/getipacctlog.$$ >>LOGFILE
X
Xcat <<'EOF' >/tmp/getipacctawk.$$
XBEGIN {
X	cutpct = CUTPCT;
X	ntop = NTOP;
X	n = 0;
X	nby = 0;
X	npk = 0;
X}
X
X/^SAMPLE/ {
X	print $0;
X}
X
X/[0-9]*\.[0-9]*\./ {
X	if (n<ntop)
X	{
X		top[n] = $0;
X		bytes[n] = $4;
X	}
X	n++;
X	npk += $3;
X	nby += $4;
X}
X
XEND {
X	for (i=0; i<ntop; i++)
X	{
X		if (bytes[i] > nby*cutpct/100)
X			print top[i];
X	}
X	printf "SUM %d %d %d\n\n", n, npk, nby;
X}
XEOF
X
Xawk -f /tmp/getipacctawk.$$ </tmp/getipacctlog.$$ | ETCDIR/nameipacct >>COMPFILE
X
X
END_OF_FILE
if test 1716 -ne `wc -c <'getipacct.sh'`; then
    echo shar: \"'getipacct.sh'\" unpacked with wrong size!
fi
# end of 'getipacct.sh'
fi
if test -f 'hosts.awk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'hosts.awk'\"
else
echo shar: Extracting \"'hosts.awk'\" \(209 characters\)
sed "s/^X//" >'hosts.awk' <<'END_OF_FILE'
X# 1.1 90/06/20 dfk@cwi.nl
X
X/[0-9]*\.[0-9]*\./ {
X
X	b[$2] += $4;
X	b[$1] += $4;
X	p[$2] += $3;
X	p[$1] += $3;
X	s[$2] = 1;
X	s[$1] = 1;
X}
X
XEND {
X
X	for (h in s)
X	{
X		printf "%-30.30s %15d %15d\n", h, p[h], b[h];
X	}
X}
END_OF_FILE
if test 209 -ne `wc -c <'hosts.awk'`; then
    echo shar: \"'hosts.awk'\" unpacked with wrong size!
fi
# end of 'hosts.awk'
fi
if test -f 'martians.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'martians.sh'\"
else
echo shar: Extracting \"'martians.sh'\" \(542 characters\)
sed "s/^X//" >'martians.sh' <<'END_OF_FILE'
X#!/bin/sh
X#
X# 1.1 90/06/20 dfk@cwi.nl
X
Xumask 077
X
X# remove tempfiles upon exit or interruption
Xtrap "rm -f /tmp/getipbcst*.$$" 0 1 2
X
X# create awk script 
Xcat <<'EOF' >/tmp/getipbcstawk.$$
X{
X	pairpkt[$1":"$2] += $3;
X	pairbyt[$1":"$2] += $4;
X}
X
XEND {
X	for (p in pairpkt)
X	{
X		split(p, pp, ":");
X		printf "%-15.15s %-15.15s %6d %9d\n", pp[1], pp[2], pairpkt[p], pairbyt[p];
X	}
X}
XEOF
X
X# grep the interesting lines from stdin, format, sort and write to stdout
Xegrep "\.0 |\.255 " | \
Xawk -f /tmp/getipbcstawk.$$ | \
Xsort -t. +0 -1n +1 -2n +2 -3n
END_OF_FILE
if test 542 -ne `wc -c <'martians.sh'`; then
    echo shar: \"'martians.sh'\" unpacked with wrong size!
fi
# end of 'martians.sh'
fi
if test -f 'nameipacct.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nameipacct.c'\"
else
echo shar: Extracting \"'nameipacct.c'\" \(3139 characters\)
sed "s/^X//" >'nameipacct.c' <<'END_OF_FILE'
X#include <sys/param.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <arpa/inet.h>
X#include <netdb.h>
X#include <stdio.h>
X#include <ctype.h>
X#include <sys/time.h>
X#include <errno.h>
X#include <ctype.h>
X#include <setjmp.h>
X
X#include "nameipacct.h"
X/*   1.3 90/06/20 dfk@cwi.nl */
X
X#define MAXRC 200		/* length reverse cache */
X#define DEFTOUTS 15
X
Xjmp_buf env;
Xint timeout ();
Xunsigned touts = 0;
X
Xextern char *netname();
X
Xextern char *optarg;
Xextern int optind;
X
Xmain(argc, argv)
X    int	    argc;
X    char    *argv[];
X{
X	register int i;
X	char from[16];
X	char to[16];
X	char l[80];
X	int bytes;
X	int packets;
X
X	while ((i=getopt(argc, argv, "t:")) != EOF)
X	{
X		switch(i)
X		{
X		case 't':
X			touts = atoi(optarg);
X			break;
X
X		case '?':
X			fprintf(stderr, "usage: nameipacct [-t secs]\n");
X			exit(1);
X		}
X	}
X
X	if (touts == 0)
X		touts = DEFTOUTS;
X	signal(SIGALRM, timeout);
X
X	while (fgets(l, sizeof l, stdin) != NULL)
X	{
X		if (isdigit(l[0]))
X		{
X			sscanf(l, "%s %s %d %d\n", from, to, &packets, &bytes);
X			display(from, to, packets, bytes);
X		}
X		else
X			fputs(l, stdout);
X	}
X}
X
Xdisplay(froma, toa, packets, bytes)
Xchar *froma;
Xchar *toa;
Xint packets;
Xint bytes;
X{
X    char from[40];
X    char to[40];
X    struct in_addr ha;
X    struct hostent *h;
X    register int len;
X
X    ha.s_addr = inet_addr(froma);
X
X    alarm(touts);
X    if (!setjmp(env) && !rchit(&ha) && (h=gethostbyaddr(&ha, 4, AF_INET)) != NULL)
X    {
X        len = strlen(h->h_name);
X        strncpy(from, len>29 ? h->h_name+(len-29) : h->h_name, sizeof(from));
X    }
X    else
X    {
X	rcenter(&ha);
X        sprintf(from, "%s", netname(ha));
X    }
X    alarm(0);
X        
X    ha.s_addr = inet_addr(toa);
X
X    alarm(touts);
X    if (!setjmp(env) && !rchit(&ha) && (h=gethostbyaddr(&ha, 4, AF_INET)) != NULL)
X    {
X        len = strlen(h->h_name);
X        strncpy(to, len>29 ? h->h_name+(len-29) : h->h_name, sizeof(to));
X    }
X    else
X    {
X	rcenter(&ha);
X        sprintf(to, "%s", netname(ha));
X    }
X    alarm(0);
X        
X    /* print data */
X    printf("%-29.29s %-29.29s%8d%10d K\n", from, to, packets, bytes/1024);
X}
X
Xstatic unsigned rccurent = 0;
Xstatic unsigned	rc[MAXRC];
X
Xrcenter(a)
Xstruct in_addr *a;
X{
X	if (rccurent < MAXRC)
X		rc[rccurent++] = (unsigned) a->s_addr;
X}
X
Xrchit(a)
Xstruct in_addr *a;
X{
X	register int i;
X	register unsigned aa;
X
X	aa = (unsigned) a->s_addr;
X	for (i=0; i<rccurent; i++)
X	{
X		if (rc[i] == aa)
X			return(1);
X	}
X	
X	return(0);
X}
X
Xtimeout ()
X{
X
X	alarm(0);
X	longjmp(env, 1);
X}
X	
X
X
Xchar *
Xnetname(ha)
Xstruct in_addr ha;
X{
X	static char cmd[80];
X	static char buf[80];
X	static char quadname[16];
X	register FILE *pipe;
X	register char *p;
X
X	strncpy(quadname, inet_ntoa(ha), sizeof quadname);
X#ifdef RIPEDBCMD
X        sprintf(cmd, "%s %s", RIPEDBCMD, inet_ntoa(inet_makeaddr(inet_netof(ha),0)));
X	if ((pipe=popen(cmd, "r")) == NULL)
X		return(quadname);
X	
X	while (fgets(buf, sizeof buf, pipe) != NULL)
X	{
X		if (strncmp(buf, "*na: ", 5) == 0)
X		{
X			for (p=buf+strlen(buf)-1; isspace(*p); p--)
X				*p = 0;
X			sprintf(cmd, "%s-%s", buf+5, quadname);
X			return(cmd);
X		}
X	}
X#else RIPEDBCMD
X	return(quadname);
X#endif RIPEDBCMD
X}
X			
END_OF_FILE
if test 3139 -ne `wc -c <'nameipacct.c'`; then
    echo shar: \"'nameipacct.c'\" unpacked with wrong size!
fi
# end of 'nameipacct.c'
fi
if test -f 'nameipacct_vms.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nameipacct_vms.c'\"
else
echo shar: Extracting \"'nameipacct_vms.c'\" \(2177 characters\)
sed "s/^X//" >'nameipacct_vms.c' <<'END_OF_FILE'
X/* ipname.c
X *
X * portable across unix/ultrix & vms systems
X * first version (90/06/20) by Daniel Karrenberg (dfk@cwi.nl)
X * this version (91/07/10) by Davide Salomoni (salomoni@cnaf.infn.it)
X * to be linked on VMS systems with the appropriate socket library.
X * Usage: ipname [secs]
X * [secs] are the max seconds to wait for the gethostbyname() function
X * to return (default=DEFSEC).
X */
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <ctype.h>
X#include <netdb.h>
X#include <signal.h>
X#include <setjmp.h>
X
X#ifdef VAXC
X#include <socket.h>
X#include <in.h>
X#else
X#include <sys/socket.h>
X#include <netinet/in.h>
X#endif
X
X#define CACHE 50    /* dimension of the cyclic cache (don't exaggerate!) */
X#define DEFSEC 15   /* max seconds to wait for gethostbyname() to return */
X
Xchar *giveme(char *string);
Xint timeout();
X
Xunsigned sec=0;
Xjmp_buf env;
X
Xstruct entry {
X	int addr;
X	char name[40];
X};
Xstatic struct entry *p[CACHE];
X
Xmain(int argc, char **argv)
X{
X	char l[81],from[40],to[40];
X	unsigned int packets,bytes;
X
X	if (argc>1) sec=atoi(argv[1]);
X	if (!sec) sec=DEFSEC;
X	signal(SIGALRM,timeout);
X
X	while (fgets(l, sizeof(l), stdin) != NULL) {
X		if (isdigit(l[0])) {
X			sscanf(l, "%s %s %d %d\n", from, to, &packets, &bytes);
X			printf("%-29.29s %-29.29s%8d%10d K\n", 
X				giveme(from), giveme(to), packets, bytes/1024);
X		}
X		else
X			fputs(l, stdout);
X	}
X	exit(0);
X}
X
X
Xchar *giveme(char *string)
X{
X	struct in_addr ha;
X	struct hostent *h;
X	register int j;
X	static int i=0,max=0;
X	int l;
X
X	ha.s_addr=inet_addr(string);
X	for (j=0;j<max;j++)
X		if (ha.s_addr==p[j]->addr)
X			return(strcpy(string,p[j]->name));  /* cache hit */
X
X	/* cache miss */
X	if (p[i]==NULL) 
X		if ((p[i]=(struct entry *)malloc(sizeof(struct entry)))==NULL) {
X			fprintf(stderr,"ipname: memory allocation error\n");
X			exit(1);
X		}
X	p[i]->addr=ha.s_addr;
X
X	alarm(sec);
X	if (!setjmp(env) && (h=gethostbyaddr(&ha, 4, AF_INET))!=NULL) {
X		l=strlen(h->h_name);
X		strcpy(p[i]->name,l>29?h->h_name+(l-29):h->h_name);
X		strcpy(string,p[i]->name);
X	} else strcpy(p[i]->name,string);
X	alarm(0);
X
X	i = ++i % CACHE;
X	if (max<CACHE) max++;
X	return(string);
X}
X
X
Xint timeout()
X{
X	alarm(0);
X	longjmp(env,1);
X}
END_OF_FILE
if test 2177 -ne `wc -c <'nameipacct_vms.c'`; then
    echo shar: \"'nameipacct_vms.c'\" unpacked with wrong size!
fi
# end of 'nameipacct_vms.c'
fi
if test -f 'sum.awk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sum.awk'\"
else
echo shar: Extracting \"'sum.awk'\" \(132 characters\)
sed "s/^X//" >'sum.awk' <<'END_OF_FILE'
X# 1.1 90/06/20 dfk@cwi.nl
X
X{
X	nby += $4;
X	nby += $5;
X	npk += $2;
X	npk += $3;
X}
X
XEND {
X	printf "%d bytes, %d packets\n", nby, npk;
X}
END_OF_FILE
if test 132 -ne `wc -c <'sum.awk'`; then
    echo shar: \"'sum.awk'\" unpacked with wrong size!
fi
# end of 'sum.awk'
fi
echo shar: End of shell archive.
exit 0
