Subject: | Checksum bug with odd-length packet (e.g., odd-length TCP frame) |
For NetPacket::in_cksum(), a special case is made for "packets" that are of odd length. However, what that special case does it not quite correct.
This is what is there now:
if($count == 1) {
$chk += unpack("C", substr($packet, $plen -1, 1));
}
However, the odd length packets are padded with zeros *at the end*, so the 16-bit quantity being added here should have the last octet as the upper 8 bits and a zero as the lower 8 bits, instead of the other way around. This should fix that:
if($count == 1) {
$chk += (unpack("C", substr($packet, $plen -1, 1)) << 8);
}
There are probably other places where this manifests iteself, but this is apparent when encoding a TCP packet where the payload length is odd.