fix parsing and pcap generation for packets with multiple output lines

(those that are > 16 bytes).
This commit is contained in:
Mariano Alvira 2011-01-07 11:29:07 -05:00
parent 5660024bcd
commit f4a2efa221

View file

@ -45,6 +45,9 @@ my $sig = 0;
my $snaplen = 0xffff; my $snaplen = 0xffff;
my $network = 195; # 802.15.4 my $network = 195; # 802.15.4
my $newpacket = 0;
my $len = 0;
print pack('LSSLLLL',($magic,$major,$minor,$zone,$sig,$snaplen,$network)); print pack('LSSLLLL',($magic,$major,$minor,$zone,$sig,$snaplen,$network));
while(1) { while(1) {
@ -55,30 +58,33 @@ while(1) {
# match if ends in \n or \r and process line # match if ends in \n or \r and process line
if(($str =~ /\n$/) || if(($str =~ /\n$/) ||
($str =~ /\r$/)) { ($str =~ /\r$/)) {
if($str =~ /^rftest/) { if($str =~ /^rftest-rx --- len 0x(\w\w)/) {
#new packet #new packet
($sec, $usec) = gettimeofday; ($sec, $usec) = gettimeofday;
print STDERR "rftestline: $sec $usec $str"; $len = hex($1);
print STDERR "rftestline: $sec $usec $len $str";
$newpacket = 1;
} elsif($str =~ /^\w+/) { } elsif($str =~ /^\w+/) {
#packet payload # dataline, write out pcap entry
print STDERR "dataline: ";
print STDERR $str;
chomp $str;
$str =~ /(.+)/; $str =~ /(.+)/;
chomp $str;
my @data = split(' ',$1); my @data = split(' ',$1);
#write out pcap entry
print pack('LLLL',($sec,$usec,scalar(@data),scalar(@data)+2)); # do header if this is a new packet
print STDERR "new packet: $sec $usec " . scalar(@data) . " " . (scalar(@data)+2) . "\n\r"; if($newpacket == 1) {
@frame = @data[0,1]; $newpacket = 0;
print pack ('CC',(hex($frame[0]),hex($frame[1]))); print pack('LLLL',($sec,$usec,$len,$len));
print STDERR "$frame[0] $frame[1] "; print STDERR "new packet: $sec $usec $len " . ($len) . "\n\r";
foreach my $data (@data[2..scalar(@data)-1]) { }
print pack ('C',hex($data));
print STDERR "$data "; # packet payload
print STDERR "dataline: ";
print STDERR $str . "\n\r";
foreach my $data (@data) {
print pack ('C',hex($data));
} }
print STDERR "\n\r";
} }
print STDERR "\n\r";
$str = ''; $str = '';
} }
} }