#! /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:  checkguard.pl checkguard.1 Makefile
# Wrapped by tony@mature.ripe.net on Wed Mar  9 11:49:37 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f checkguard.pl -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"checkguard.pl\"
else
echo shar: Extracting \"checkguard.pl\" \(3678 characters\)
sed "s/^X//" >checkguard.pl <<'END_OF_checkguard.pl'
X#!PERL
X#
X# This is a simple program to check the syntax of a guarded file
X# to make help the guardians out a little bit.
X#
X#	
X#	$RCSfile: checkguard.pl,v $
X#	$Revision: 1.2 $
X#	$Author: tony $
X#	$Date: 1994/03/09 10:49:08 $
X#	
X#	
X#	
Xrequire "getopts.pl";
X&Getopts('v');
Xif ( $opt_v ) {
X    $verbose = 1;
X}
Xif ( $#ARGV) {
X    print STDERR "No configfile given, assuming stdin\n";
X}
X$lineno = 0;
X$B = &quad2int("128.0.0.0");
X$C = &quad2int("192.0.0.0");
Xwhile (<ARGV>) {
X    chop;
X    $lineno++;
X    if (/^\#/ || /^\;/) {
X	$comment++;
X	next;
X    }
X    s/^inetnum:\s*//;		# Allow the database formats
X    s/^\*in:\s*//;		# Both of them
X    if (/^\s*$/) {
X	$empty++;		# Count empty lines
X	next;
X    }
X
X    if (/ \- /) {		# Assume a range
X	
X	@range = split(/\s+/, $_, 3);
X	if ($range[1] ne "-") {
X	    &ps;
X	    next;
X	} elsif (!&isnetnum($range[0])) {
X	    &ps(" = $range[0] is not a valid IP network");
X	    next;
X	} elsif (!&isnetnum($range[2])) {
X	    &ps(" = $range[0] is not a valid IP network");
X	    next;
X	} else {
X	    $bot = &quad2int($range[0]);
X	    $top = &quad2int($range[2]);
X	    if ($top <= $bot) {
X		&ps(" = invalid range given");
X		next;
X	    }
X# Now break out the range and add to the $seen array
X	    if($bot >= $C) {
X		$inc = 256;
X		$class = "c";
X	    } elsif ($bot >= $B) {
X		$inc = 256**2;
X		$class = "b";
X	    } else {
X		$inc = 256**3;
X		$class = "a";
X	    }
X
X	    for ($i = $bot ; $i <= $top ; $i += $inc) {
X		$val = &int2quad($i);
X		if ($seen{"$val"}) {
X		    &pw("= $val already seen on line $seen{$val}");
X		} else {
X			eval "\$class$class ++;"; # This is yuck !!
X		}
X		$seen{"$val"} = $lineno;   
X	    }
X	    next;
X	}
X    } else {
X	if (!&isnetnum($_)) {
X	    &ps(" = $_ is not a valid IP network");
X	    next;
X	}
X    }
X    if ($seen{"$_"}) {
X	&pw(" = $_ already seen on line $seen{$_}");
X    }
X    $netval = &quad2int($_);
X    if($netval >= $C) {
X	$class = "c";
X    } elsif ($netval >= $B) {
X	$class = "b";
X    } else {
X	$class = "a";
X    }
X    eval "\$class$class ++;"; # This is yuck !!
X    $seen{"$_"} = $lineno;
X    next;
X}
X# If they want verbose they get verbose ;-)
Xif($opt_v) {
X    printf "The file contains:\n%s%s%s%s%s%s",
X    $lineno ? "\t$lineno lines\n" : "",
X    $comment ? "\t$comment comment lines\n" : "",
X    $empty ? "\t$empty emtpy lines\n" : "",
X    $classa ? "\t$classa Class A networks\n" : "",
X    $classb ? "\t$classb Class B networks\n" : "",
X    $classc ? "\t$classc Class C networks\n" : "";
X}
Xsub pw {
X    local($str) = @_;
X    printf "warning at line $lineno $str\n";
X}
Xsub ps {
X    local($str)  = @_;
X    printf "syntax error at line $lineno $str\n";
X}       
Xsub isnetnum {
X    local($str) = @_;
X    local($ind) = 0;
X    local(@add) = split(/\./, $str);
X    if ($#add != 3) {
X	return 0;
X    }
X    foreach $ind (0..$#add) {
X	if (($add[$ind] !~ /^[0-9][0-9]*$/) || ($add[$ind] > 255)) {
X	    return 0;
X	}
X    }
X    if (($add[0] < 128) && (($add[1] != 0 ) || 
X			    ($add[2] != 0 ) || ($add[3] != 0 ))) {
X	return 0;
X    } elsif (($add[0] < 192) && (($add[2] != 0 ) || ($add[3] != 0 ))) {
X	return 0;
X    } elsif (($add[0] < 224) && ($add[3] != 0 )) {
X	return 0;
X    }
X    return 1;
X}				 
X
Xsub quad2int {
X    local($quad) = @_;
X    local(@quads);
X    local($i, $j, $result);
X    # 
X    @quads = split(/\./, $quad);
X    
X    $result = 0;
X    for ($i=0; $i<4; $i++) {
X	$j = $quads[$i];
X	($j>=0&&$j<256) || die "quad2int: illegal ip number '$quad'\n";
X	$result += ($j<<(8*(3-$i)));
X    }
X    return $result;
X}
X
Xsub int2quad {
X    local($int) = @_;
X    local($i, $j, $result);
X
X    $result = "";
X    for ($i=3; $i>=0; $i--) {
X	$j = ($int>>($i*8))&0xff;
X	$result = $result . "$j.";
X    }
X    chop($result);
X    return $result;
X}
END_OF_checkguard.pl
if test 3678 -ne `wc -c <checkguard.pl`; then
    echo shar: \"checkguard.pl\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f checkguard.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"checkguard.1\"
else
echo shar: Extracting \"checkguard.1\" \(1652 characters\)
sed "s/^X//" >checkguard.1 <<'END_OF_checkguard.1'
X.\"
X.\"
X.\" Copyright (c) 1993 The RARE Association
X.\"
X.\" All Rights Reserved
X.\"
X.\" Permission to use, copy, modify, and distribute this software and its
X.\" documentation for any purpose and without fee is hereby granted,
X.\" provided that the above copyright notice appear in all copies and that
X.\" both that copyright notice and this permission notice appear in
X.\" supporting documentation, and that the name of the author not be
X.\" used in advertising or publicity pertaining to distribution of the
X.\" software without specific, written prior permission.
X.\"
X.\" THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X.\" ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
X.\" AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
X.\" DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
X.\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
X.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X.\"
X.\"	$RCSfile: checkguard.1,v $ 
X.\"	$Revision: 1.2 $ 
X.\"	$Author: tony $ 
X.\"	$Date: 1994/03/09 10:49:08 $ 
X.\"
X.\"
X.\"
X.TH checkguard 1 "February, 1994"
X.UC 6
X.SH NAME
Xcheckguard \- check the syntax of a guardian file.
X.SH SYNOPSIS
X.B checkguard
X[
X.B \-v
X]
X.I guardian_file
X.SH DESCRIPTION
XThis is a little program to check the syntax of a guardian file. It will also
Xreport on duplicate and overlapping blocks. This expects `classful' network
Xnumbers only.
X.PP
XOptions are:
X.SH OPTIONS
X.TP 6
X.B \-v
XVerbose output. This will summarise the number of networks.
X.SH AUTHORS
XTony Bates, RIPE NCC
X.br
XT.Bates@ripe.net
END_OF_checkguard.1
if test 1652 -ne `wc -c <checkguard.1`; then
    echo shar: \"checkguard.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(917 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X#
X#
X#       $RCSfile: Makefile,v $
X#       $Revision: 1.2 $ 
X#       $Author: tony $ 
X#       $Date: 1994/03/09 10:49:08 $ 
X#
X# Makefile for checkguard
X
XSRC=		checkguard.pl
XMAN=		checkguard.1
X
XBINDIR=		/usr/local/bin
XPERL=		/usr/local/bin/perl
XMANDIR=		/usr/local/man
XMANEXT=		1
XSHAR=		shar -odist.shar
X
XOBJ=		checkguard
XDIST=		$(SRC) $(MAN) Makefile
X
Xcheckguard: checkguard.pl Makefile $(DEP)
X	sed     -e 's:PERL:$(PERL):' \
X		< checkguard.pl | \
X	$(PERL) -e 'while(<>) { chop; s/\s*$$//; next if (/^# #/); if(/(^.*)(# #.*$$)/) { printf "$$1\n"; next; } print "$$_\n"; }' > $@
X	chmod 755 $@
X
Xinstall: $(OBJ) Makefile $(MAN) $(DEP)
X	-install -m 755 $(OBJ) $(BINDIR)
X	-install -m 644 ${MAN} ${MANDIR}/man${MANEXT}/${MAN}
X
Xdist.shar: $(DIST) 
X	$(SHAR) $(DIST)
X	
X
Xdist: dist.shar
X
Xall: checkguard 
X
Xman: $(MAN)
X	-install -m 644 ${MAN} ${MANDIR}/man${MANEXT}/${MAN}
X
Xclean:
X	-rm -f core a.out dist.shar *.o ,* $(OBJ)
X
X
END_OF_Makefile
if test 917 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
