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