From owner-freebsd-net Tue Apr 9 17:18:54 2002 Delivered-To: freebsd-net@freebsd.org Received: from sheffield.cnchost.com (sheffield.concentric.net [207.155.252.12]) by hub.freebsd.org (Postfix) with ESMTP id 080DA37B41B for ; Tue, 9 Apr 2002 17:18:50 -0700 (PDT) Received: from bitblocks.com (adsl-209-204-185-216.sonic.net [209.204.185.216]) by sheffield.cnchost.com id UAA13907; Tue, 9 Apr 2002 20:18:47 -0400 (EDT) [ConcentricHost SMTP Relay 1.14] Message-ID: <200204100018.UAA13907@sheffield.cnchost.com> To: Julian Elischer Cc: net@freebsd.org Subject: Re: IP checksup update In-reply-to: Your message of "Tue, 09 Apr 2002 16:02:01 PDT." Date: Tue, 09 Apr 2002 17:18:47 -0700 From: Bakul Shah Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > 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