blob: e31f7c4224b61b8f0d66d32eac73ad149814087a [file] [log] [blame] [raw]
@P=();
$line = 0;
while (<>) {
s/\=192.168.1.188/\=c0a8:0100::bc/g;
s/\=192.168.1.188/\=c0a8:0100::bc/g;
@F = split;
if (/^#/) {
@P[$nline++] = join(" ",@F);
next;
}
$line = 0 if (/^\[/);
if ($line == 1) {
$len = hex($F[1]) - 20;
$pr = hex($F[4]) & 0xff;
$pr = 58 if ($pr == 1);
$ttl = hex($F[4]) >> 8;
&replaceip($_, $len, $pr, $ttl);
$ipline = $nline;
$err = 0;
} elsif ($line == 2) {
if ($pr == 58) {
#
# Map the ICMP type codes from IPv4 to IPv6
# and update the checksum to compensate.
#
if ($F[0] =~ /^0800/) {
$F[0] =~ s/^0800/8000/;
$d = 0x7800;
}
if ($F[0] =~ /^0000/) {
$F[0] =~ s/^0000/8100/;
$d = 0x8100;
}
if ($F[0] =~ /^0304/) {
$F[0] =~ s/^0304/0200/;
$d = 0xfefc;
$err = 1;
}
if ($F[0] =~ /^03/) {
$F[0] =~ s/^03/01/;
$d = 0xfe00;
$err = 1;
}
if ($F[0] =~ /^0b/) {
$F[0] =~ s/^0b/03/;
$d = 0xf800;
$err = 1;
}
if ($F[0] =~ /^0c/) {
$F[0] =~ s/^0c/04/;
$d = 0xf800;
$err = 1;
}
$F[1] = sprintf "%04x", hex($F[1]) - $d;
}
@P[$nline++] = join(" ",@F);
} elsif ($line == 3) {
if ($pr == 58 && $err == 1 && $F[0] =~ /^45/) {
local($l) = hex($F[1]) - 20;
local($p) = hex($F[4]) & 0xff;
$p = 58 if ($p == 1);
local($t) = hex($F[4]) >> 8;
&replaceip(join(" ", @F), $l, $p, $t);
@H = split(/ /, $P[$ipline]);
$H[2] += 20;
$P[$ipline] = join(" ",@H);
} else {
@P[$nline++] = join(" ",@F);
}
} else {
@P[$nline++] = join(" ",@F);
}
$line++;
}
for ($li = 0; $li < $nline; $li++) {
print "$P[$li]\n";
}
exit(0);
sub replaceip {
local(@G) = split(/\s/,$_[0]);
local($p) = "";
$p = sprintf "6000 0000 %04x %02x%02x", $_[1], $_[2], $_[3];
if ($G[6] =~ /^c0a8/) {
$fmt = " %02x%02x %02x00 0000 0000 0000 0000 0000 00%02x";
} else {
if ($G[6] =~ /^0[4a]../) {
$fmt = " 00%02x 00%02x 00%02x 0000 0000 0000 0000 00%02x";
} else {
$fmt = " 00%02x 0000 0000 0000 0000 00%02x 00%02x 00%02x";
}
if ($G[6] =~ /^0a/) {
$G[6] =~ s/^0a/10/;
}
if ($G[6] =~ /0a$/) {
$G[6] =~ s/0a$/10/;
}
if ($G[7] =~ /^0a/) {
$G[7] =~ s/^0a/10/;
}
if ($G[7] =~ /0a$/) {
$G[7] =~ s/0a$/10/;
}
}
$p = $p.sprintf $fmt, hex($G[6]) >> 8, hex($G[6]) & 0xff,
hex($G[7]) >> 8, hex($G[7]) & 0xff;
if ($G[6] =~ /^c0a8/) {
$fmt = " %02x%02x %02x00 0000 0000 0000 0000 0000 00%02x";
} else {
if ($G[8] =~ /^0[4a]../) {
$fmt = " 00%02x 00%02x 00%02x 0000 0000 0000 0000 00%02x";
} else {
$fmt = " 00%02x 0000 0000 0000 0000 00%02x 00%02x 00%02x";
}
if ($G[8] =~ /^0a/) {
$G[8] =~ s/^0a/10/;
}
if ($G[8] =~ /0a$/) {
$G[8] =~ s/0a$/10/;
}
if ($G[9] =~ /^0a/) {
$G[9] =~ s/^0a/10/;
}
if ($G[9] =~ /0a$/) {
$G[9] =~ s/0a$/10/;
}
}
$p = $p.sprintf $fmt, hex($G[8]) >> 8, hex($G[8]) & 0xff,
hex($G[9]) >> 8, hex($G[9]) & 0xff;
$P[$nline++] = $p;
}