fix parsing and pcap generation for packets with multiple output lines

(those that are > 16 bytes).
This commit is contained in:
maralvira 2011-01-17 15:47:23 +00:00
parent d82b004154
commit 6fb75263f9

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+/) {
# dataline, write out pcap entry
$str =~ /(.+)/;
chomp $str;
my @data = split(' ',$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 # packet payload
print STDERR "dataline: "; print STDERR "dataline: ";
print STDERR $str; print STDERR $str . "\n\r";
chomp $str;
$str =~ /(.+)/; foreach my $data (@data) {
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]) {
print pack ('C',hex($data)); print pack ('C',hex($data));
print STDERR "$data ";
} }
print STDERR "\n\r";
} }
print STDERR "\n\r";
$str = ''; $str = '';
} }
} }