X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/5cdf53e257a7e947e1e72b590eea8c1471b9be6c..cc2d4cbd8ca150504127f375d8b51b194958d95b:/in_cksum.c diff --git a/in_cksum.c b/in_cksum.c index b81f2baf..eb7c634f 100644 --- a/in_cksum.c +++ b/in_cksum.c @@ -35,14 +35,13 @@ * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93 */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H -# include "config.h" +# include #endif -#include +#include "netdissect-stdinc.h" -#include "interface.h" +#include "netdissect.h" /* * Checksum routine for Internet Protocol family headers (Portable Version). @@ -54,27 +53,27 @@ #define ADDCARRY(x) {if ((x) > 65535) (x) -= 65535;} #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);} -u_int16_t +uint16_t in_cksum(const struct cksum_vec *vec, int veclen) { - register const u_int16_t *w; - register int sum = 0; - register int mlen = 0; + const uint16_t *w; + int sum = 0; + int mlen = 0; int byte_swapped = 0; union { - u_int8_t c[2]; - u_int16_t s; + uint8_t c[2]; + uint16_t s; } s_util; union { - u_int16_t s[2]; - u_int32_t l; + uint16_t s[2]; + uint32_t l; } l_util; for (; veclen != 0; vec++, veclen--) { if (vec->len == 0) continue; - w = (const u_int16_t *)(void *)vec->ptr; + w = (const uint16_t *)(const void *)vec->ptr; if (mlen == -1) { /* * The first byte of this chunk is the continuation @@ -84,20 +83,20 @@ in_cksum(const struct cksum_vec *vec, int veclen) * s_util.c[0] is already saved when scanning previous * chunk. */ - s_util.c[1] = *(const u_int8_t *)w; + s_util.c[1] = *(const uint8_t *)w; sum += s_util.s; - w = (const u_int16_t *)(void *)((const u_int8_t *)w + 1); + w = (const uint16_t *)(const void *)((const uint8_t *)w + 1); mlen = vec->len - 1; } else mlen = vec->len; /* * Force to even boundary. */ - if ((1 & (unsigned long) w) && (mlen > 0)) { + if ((1 & (uintptr_t) w) && (mlen > 0)) { REDUCE; sum <<= 8; - s_util.c[0] = *(const u_int8_t *)w; - w = (const u_int16_t *)(void *)((const u_int8_t *)w + 1); + s_util.c[0] = *(const uint8_t *)w; + w = (const uint16_t *)(const void *)((const uint8_t *)w + 1); mlen--; byte_swapped = 1; } @@ -129,13 +128,13 @@ in_cksum(const struct cksum_vec *vec, int veclen) sum <<= 8; byte_swapped = 0; if (mlen == -1) { - s_util.c[1] = *(const u_int8_t *)w; + s_util.c[1] = *(const uint8_t *)w; sum += s_util.s; mlen = 0; } else mlen = -1; } else if (mlen == -1) - s_util.c[0] = *(const u_int8_t *)w; + s_util.c[0] = *(const uint8_t *)w; } if (mlen == -1) { /* The last mbuf has odd # of bytes. Follow the @@ -154,10 +153,10 @@ in_cksum(const struct cksum_vec *vec, int veclen) * that the checksum covers (including the checksum itself), compute * what the checksum field *should* have been. */ -u_int16_t -in_cksum_shouldbe(u_int16_t sum, u_int16_t computed_sum) +uint16_t +in_cksum_shouldbe(uint16_t sum, uint16_t computed_sum) { - u_int32_t shouldbe; + uint32_t shouldbe; /* * The value that should have gone into the checksum field @@ -197,5 +196,5 @@ in_cksum_shouldbe(u_int16_t sum, u_int16_t computed_sum) shouldbe += ntohs(computed_sum); shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); - return shouldbe; + return (uint16_t)shouldbe; }