#!/usr/bin/perl -w

#
#  intermediate_join_map
#  Copyright (C) 2010 by USC/ISI
#  $Id$
#  
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License,
#  version 2, as published by the Free Software Foundation.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License along
#  with this program; if not, write to the Free Software Foundation, Inc.,
#  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#  
#  
#  This code was originally written by Xun Fan <xunfan@isi.edu>.
#

use Fsdb::IO::Reader;
use Fsdb::IO::Writer;

my $input_stream = new Fsdb::IO::Reader(-fh => \*STDIN, -fscode => 't');

#my $c_prefix_mask = ~(2**8 - 1);

#my $output_stream = new Fsdb::IO::Writer(-fh => \*STDOUT, -fscode => 't', -cols => [qw(PREFIX IP HISTROTY VALUE)]);

my @input_arow;

sub read_rows{
        $input_stream->read_row_to_aref(\@input_arow) or return undef;
 	#print "$input_arow[0]\t$input_arow[1]\t$input_arow[2]\t$input_arow[3]\n";	
	return ($input_arow[0], $input_arow[1]);
}



# only extract 128.0.0.0/9 addresses
# my $match_prefix_mask = ~(2**(32-9)-1); # mask length 9 
# my $match_prefix_net = $match_prefix_mask & hex(substr("80". "00000000", 0, 8)); #  128.0.0.0/9

for(;;){
	my($ip, $history) = &read_rows;
	last if (!defined($ip)); #EOF

#	$ip_hex = hex($ip);
        # get prefix
#	my $prefix = $ip_hex & $c_prefix_mask;
#	my $prefix_print = sprintf("%08x", $prefix);

	print "$ip\t$history\n";
}
