Skip to content

Commit

Permalink
cksum is computed incorrectly
Browse files Browse the repository at this point in the history
The previous code read off the end of *buf, and also produced incorrect TCP checksums, when nbytes was odd.
  • Loading branch information
ewust committed Jan 22, 2014
1 parent 7257579 commit fc7832b
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions cksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
__u16 cksum(__u16 *buf, int nbytes)
{
__u32 sum;
__u16 oddbyte;

sum = 0;
while (nbytes > 1) {
Expand All @@ -18,9 +17,7 @@ __u16 cksum(__u16 *buf, int nbytes)
}

if (nbytes == 1) {
oddbyte = 0;
*((__u16 *) &oddbyte) = *(__u16 *) buf;
sum += oddbyte;
sum += *((__u8*)buf);
}

sum = (sum >> 16) + (sum & 0xffff);
Expand Down

0 comments on commit fc7832b

Please sign in to comment.