From 0c2cbd736e70e82bd9a44b5b54ec136db6726cc0 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Tue, 26 Sep 2006 11:56:23 +0000 Subject: 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@ --- usr.sbin/ospfd/in_cksum.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'usr.sbin/ospfd/in_cksum.c') 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); } -- cgit v1.2.3