diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-09-26 11:56:23 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-09-26 11:56:23 +0000 |
commit | 0c2cbd736e70e82bd9a44b5b54ec136db6726cc0 (patch) | |
tree | 55435768e1f8c8c9a186eda33de12b20f47fc8d0 /usr.sbin/ospfd/in_cksum.c | |
parent | da4e07fb245f1df5f3d9a05737e9a537e5046259 (diff) |
Sync in_cksum.c to the same version dvmrpd has. This fixes problems with odd
packet lenght even though ospfd does not produce such packets.
OK norby@
Diffstat (limited to 'usr.sbin/ospfd/in_cksum.c')
-rw-r--r-- | usr.sbin/ospfd/in_cksum.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/usr.sbin/ospfd/in_cksum.c b/usr.sbin/ospfd/in_cksum.c index cdd61baec16..c2998040e4e 100644 --- a/usr.sbin/ospfd/in_cksum.c +++ b/usr.sbin/ospfd/in_cksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_cksum.c,v 1.4 2006/04/25 08:22:14 claudio Exp $ */ +/* $OpenBSD: in_cksum.c,v 1.5 2006/09/26 11:56:22 claudio Exp $ */ /* $NetBSD: in_cksum.c,v 1.3 1995/04/22 13:53:48 cgd Exp $ */ /* @@ -55,7 +55,7 @@ u_int16_t in_cksum(void *p, size_t l) { unsigned int sum = 0; - int len, oddbyte = 0, v = 0; + int len; u_char *cp = p; /* ensure that < 2^16 bytes being summed */ @@ -63,28 +63,24 @@ in_cksum(void *p, size_t l) fatalx("in_cksum: packet to big"); len = (int)l; - while (len > 0) { - if (oddbyte) { - sum += v + *cp++; - len--; + if (((long)cp & 1) == 0) { + while (len > 1) { + sum += htons(*(u_short *)cp); + cp += 2; + len -= 2; } - if (((long)cp & 1) == 0) { - while ((len -= 2) >= 0) { - sum += *(u_short *)cp; - cp += 2; - } - } else { - while ((len -= 2) >= 0) { - sum += *cp++ << 8; - sum += *cp++; - } + } else { + while (len > 1) { + sum += *cp++ << 8; + sum += *cp++; + len -= 2; } - if ((oddbyte = len & 1) != 0) - v = *cp << 8; } - if (oddbyte) - sum += v; + if (len == 1) + sum += *cp << 8; + sum = (sum >> 16) + (sum & 0xffff); /* add in accumulated carries */ sum += sum >> 16; /* add potential last carry */ + sum = ntohs(sum); return (0xffff & ~sum); } |