########################################################################
#  By accessing this software, USER_FILE.PL, you are duly informed of
#  and agree to be bound by the conditions described below in
#  this notice:
#
#  This software product, USER_FILE.PL, is developed by Bradley Huffaker, and
#  copyrighted(C) 1998 by the University of California, San Diego (UCSD),
#  with all rights reserved.  UCSD administers the NLANR Cache grants,
#  NCR-9796082 and NCR-9616602, under which most of this code was
#  developed.
#
#  USER_FILE.PL is a free software. You can redistribute it and/or modify it
#  under the terms of the CAIDA/NLANR General Public License v.1 as
#  published by UCSD and is incorporated by reference herein.  USER_FILE.PL is
#  distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY
#  OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not
#  infringe on any third party's intellectual property rights.
#
#  You should have received a copy of the CAIDA/NLANR General Public
#  License v.1 along with the USER_FILE.PL program.  If for any reason you
#  have not received a copy, please write to
#
#                       University of California, San Diego
#                       SDSC/CAIDA/NLANR
#                       9500 Gilman Dr., MS-0505
#                       La Jolla, CA 92093 - 0505  USA
#
#  Or contact INFO@NLANR.NET
#######################################################################


sub ProcessNode
{
	my ($node) = @_;
	CreatePipe("mrinfo $node");
	$SIG{'ALRM'} = handler;
	alarm(18);
	my @nodes;
	my %alias;
	while ($line = <TR>)
	{
		if ($line=~/^([\d|\.]+) \(([^\)]+)\) \[([^\]]+)\]\:/)
		{
			$ip = $1;
			$node = $2;
			print ": $node($ip) $3\n";
		}
		elsif ($line=~/^\s+([\d|\.]+) -> ([\d|\.]+) \(([^\)]+)\) ([^\n]+)/)
		{
			my ($ip_a,$ip_o, $node_o, $rest) = ($1,$2,$3,$4);
			
			if (!($ip_o=~/0\.0\.0\.0/))
			{
				if ($ip_a ne $ip && !$alias{$ip_a})
				{
					$reached{$ip_a} = 1;
					$alias{$ip_a} = 1;
					my ($alias_n,$alias_i) 
						= nslookup($ip_a);
					$alias_n = $ip_a
						if (!$alias_n);
					print "= $node($ip) $alias_n($ip_a)\n"
				}
				push (@nodes,$ip_o);
				$ip2name{$ip_o} = $node_o;
				print "> $node($ip) $node_o($ip_o) $rest\n";
			}
		}
	}
	close IN;
	return @nodes;
}

sub CreatePipe
{
	my ($command) = @_;
        pipe(TR,TW);
        $pid = fork;
        if ($pid == 0)
        {
                close STDIN; close STDOUT; close STDERR; close TR;
                open (STDOUT,">&TW");
                open (STDERR,">&STDOUT");
                exec $command;
                die("I failed!");
        }
        elsif ($pid < 0)
        {
                die("I was not able to fork");
        }
                
        close TW;
}

sub handler
{
	kill 9, $pid
		if ($pid);
	undef $pid;
	print STDERR ("handler was called\n");
}
1;
