#! /usr/local/bin/perl # crl2fr.pl -- converts oc3mon output to fr format # # usage: # crl2fr.pl inputfile interface > outputfile # # 0 1 2 3 # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #0 | timestamp | Header # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #1 | timestamp | FIFO depth | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #2 | ATM header | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #3 | LLC/SNAP | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #4 | LLC/SNAP | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #5 |Version| IHL |Type of Service| Total Length | IP # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #6 | Identification |Flags| Fragment Offset | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #7 | Time to Live | Protocol | Header Checksum | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #8 | Source Address | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #9 | Destination Address | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # # option or other header # # | Source Port | Destination Port | TCP # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # | Sequence Number | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # | Acknowledgment Number | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # | Data | |U|A|P|R|S|F| | # | Offset| Reserved |R|C|S|S|Y|I| Window | # | | |G|K|H|T|N|N| | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # open(infile,$ARGV[0]) || die("Can't open input file\n"); $if=$ARGV[1]; # requested interface if(!$if){printf stderr "Warning, no interface selected, continuing....\n";} $tdelta=1; # skip header while(read(infile,$record,512)){ $cflag=vec($record,0,16); #non-byte-swapped clock if -1 $cellcount=vec($record,2,8)*256+vec($record,3,8); $interface=vec($record,4,8)*256+vec($record,5,8); printf stderr "$interface\t$cellcount\n"; # Start reading in entries for ($lccnt = 1; $lccnt <= 17408; $lccnt++) { read(infile,$record,60) || exit; if($lccnt > $cellcount){next;} if(($if ne "") && ($if != $interface)){next;} if($cflag == 0xffff) { $ts1= vec($record,3,8); $ts2= vec($record,2,8); }else{ $ts1= vec($record,4,8); $ts2= vec($record,5,8); } $clock=($ts1<<8)+$ts2; if($clock < $oldclock){$clock2++;} $oldclock=$clock; $timestamp=(($clock2*65536)+$clock)*0.00000004; $tstampsec =int($timestamp); $tstampusec=int(($timestamp-$tstampsec)*1e6); if((vec($record,18,8) == 0x08) && ((vec($record,20,8)&0xf0) == 0x40)){ $src =vec($record,8,32); $dst =vec($record,9,32); $plen =vec($record,22,8)*256+vec($record,23,8); $prot =vec($record,29,8); $tflags=vec($record,53,8)&0x3f; $ihl =(vec($record,20,8)&0xf)*4; $sport =vec($record,$ihl+20,8)*256+vec($record,$ihl+21,8); $dport =vec($record,$ihl+22,8)*256+vec($record,$ihl+23,8); vec($record2,0,32) = $tstampsec; vec($record2,1,32) = $tstampusec; vec($record2,2,32) = $src; vec($record2,3,32) = $dst; vec($record2,8,16) = $plen; vec($record2,18,8) = $prot; vec($record2,19,8) = $tflags; vec($record2,10,16)= $sport; vec($record2,11,16)= $dport; syswrite(stdout,$record2,24); } } }