"long" does not necessarily mean "32-bit integral data type"; the union

used to treat a 32-bit quantity either as 2 16-bit quantities or a
32-bit quantity should use "guint32", not "long", for the latter.

We should also use "guint8" for the two 8-bit quantities in "s_util",
although that shouldn't make a difference in practice (we store into
them, but fetch only the 16-bit overlapping quantity, which is already
unsigned).

svn path=/trunk/; revision=3533
This commit is contained in:
Guy Harris 2001-06-09 01:02:29 +00:00
parent e52dd802c4
commit 58304dd1f7
1 changed files with 6 additions and 6 deletions

View File

@ -2,7 +2,7 @@
* 4.4-Lite-2 Internet checksum routine, modified to take a vector of
* pointers/lengths giving the pieces to be checksummed.
*
* $Id: in_cksum.c,v 1.3 2001/01/10 23:34:06 guy Exp $
* $Id: in_cksum.c,v 1.4 2001/06/09 01:02:29 guy Exp $
*/
/*
@ -79,12 +79,12 @@ in_cksum(const vec_t *vec, int veclen)
int byte_swapped = 0;
union {
char c[2];
guint8 c[2];
guint16 s;
} s_util;
union {
guint16 s[2];
long l;
guint32 l;
} l_util;
for (; veclen != 0; vec++, veclen--) {
@ -100,7 +100,7 @@ in_cksum(const vec_t *vec, int veclen)
* s_util.c[0] is already saved when scanning previous
* chunk.
*/
s_util.c[1] = *(char *)w;
s_util.c[1] = *(const guint8 *)w;
sum += s_util.s;
w = (const guint16 *)((const guint8 *)w + 1);
mlen = vec->len - 1;
@ -145,13 +145,13 @@ in_cksum(const vec_t *vec, int veclen)
sum <<= 8;
byte_swapped = 0;
if (mlen == -1) {
s_util.c[1] = *(char *)w;
s_util.c[1] = *(const guint8 *)w;
sum += s_util.s;
mlen = 0;
} else
mlen = -1;
} else if (mlen == -1)
s_util.c[0] = *(char *)w;
s_util.c[0] = *(const guint8 *)w;
}
if (mlen == -1) {
/* The last mbuf has odd # of bytes. Follow the