#!/usr/local/bin/perl #Encode IP addresses for fr/er packet trace files. #The output format equals the input format, except that the IP #addresses are encoded and consist of a 12 bit wide encoded network number #field, followed by a 20 bit wide encoded host number field. $infile=$ARGV[0]; open(infile,$infile) || die; while(read(infile,$record,24)){ $count++; ($tsec,$tusec,$src,$dst,$misc,$ports)=unpack(L6,$record); $srcn = $src & 0xffffff00; $srch = $src & 0x000000ff; if($src < 0xc0000000) {$srcn = $src & 0xffff0000;$srch = $src & 0x0000ffff;} if($src < 0x80000000) {$srcn = $src & 0xff000000;$srch = $src & 0x00ffffff;} if(!$id{$srcn,-1}) {$id{$srcn,-1} = ++$netcount;} if(!$id{$srcn,$srch}) {$id{$srcn,$srch} = ++$hstcount{$srcn};} $src=($id{$srcn,-1}<<16) + $id{$srcn,$srch}; $dstn = $dst & 0xffffff00; $dsth = $dst & 0x000000ff; if($dst < 0xc0000000) {$dstn = $dst & 0xffff0000;$dsth = $dst & 0x0000ffff;} if($dst < 0x80000000) {$dstn = $dst & 0xff000000;$dsth = $dst & 0x00ffffff;} if(!$id{$dstn,-1}) {$id{$dstn,-1} = ++$netcount;} if(!$id{$dstn,$dsth}) {$id{$dstn,$dsth} = ++$hstcount{$dstn};} $dst=($id{$dstn,-1}<<16) + $id{$dstn,$dsth}; $record = pack("L6", $tsec, $tusec, $src, $dst, $misc, $ports); syswrite(stdout,$record,24) || die; } close(infile); close(stdout); printf "Processed $count records.\n";