Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 09 Apr 2002 17:18:47 -0700
From:      Bakul Shah <bakul@bitblocks.com>
To:        Julian Elischer <julian@elischer.org>
Cc:        net@freebsd.org
Subject:   Re: IP checksup update 
Message-ID:  <200204100018.UAA13907@sheffield.cnchost.com>
In-Reply-To: Your message of "Tue, 09 Apr 2002 16:02:01 PDT." <Pine.BSF.4.21.0204091557570.57350-100000@InterJet.elischer.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
> to update a checksum when changing a word
> 
>   #define FIXSUM16(c, op, np)                                 \
>     do {                                                      \
>       (c) -= (u_int16_t) ~*((u_int16_t *) (op));              \
>       if ((c) < 0) {                                          \
>         (c) += 0xffff;                                        \
>       }                                                       \
>       (c) -= (u_int16_t)  *((u_int16_t *) (np));              \
>       if ((c) < 0) {                                          \
>         (c) += 0xffff;                                        \
>       }                                                       \
>     } while (0)
>
> The question is:
> apparently there are several "tricks" with this checksum
> and + and - 0. Does anyone know how to test if this macro gets it
> right?

Looks like a straight forward implementation of rfc1624 eqn 4.
"if (c < 0) c += 0xffff;" is needed to turn two's complement
subtraction to one's complement.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204100018.UAA13907>