From owner-freebsd-hackers Tue Nov 23 12:10:57 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from alpo.whistle.com (alpo.whistle.com [207.76.204.38]) by hub.freebsd.org (Postfix) with ESMTP id 89DAC1514E for ; Tue, 23 Nov 1999 12:10:52 -0800 (PST) (envelope-from julian@whistle.com) Received: from home.elischer.org (home.elischer.org [207.76.204.203]) by alpo.whistle.com (8.9.1a/8.9.1) with ESMTP id MAA93916; Tue, 23 Nov 1999 12:09:56 -0800 (PST) Date: Tue, 23 Nov 1999 12:09:55 -0800 (PST) From: Julian Elischer X-Sender: julian@home.elischer.org To: Clinton Xavier Berni Cc: "Parthasarathy M. Aji" , freebsd-hackers@FreeBSD.ORG Subject: Re: ip checksum In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 23 Nov 1999, Clinton Xavier Berni wrote: > Hey, > I am sort of confused with the parameters for IPsumReplaceShort function, > I understand that I will pass the &ip-ip_sum for the cksump parameter. > > but I am not able to understand wht oldvap & newvalp stand for.. cksump points to the existing checksum IN THE PACKET oldvalp points to the old value that will be replaecd IN THE PACKET newval is the value that will replace the old value. The function will replace the old value with the new value, and update the checksum accordigly. julian > > Xavier. > > > > On Mon, 22 Nov 1999, Julian Elischer wrote: > > > How many bytes have you changed? > > > > is it possible that some of the values have already been ntohs()'d > > or something similar? > > > > rather than recalculate the whole packet, just update the exisitng > > value. > > > > there is an rfc for this but it took me a while to get > > the code right in C on a 386. The trick is getting the 1s complement > > arithmetic right. > > > > > > > > #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) > > > > > > /* > > * IpsumReplaceShort() > > * > > * Replace a 16 bit aligned (relative to the checksum) 16 bit value > > * in a packet and change the IP/TCP/UDP checksum at the same time. > > * > > * Works with both big and little endian machines(!) > > * > > * If for some wierd reason you want to replace a nonaligned value, > > * you need to byteswap it and the old value before doing the > > * subtractions. > > */ > > > > void > > IpsumReplaceShort(u_int16_t *cksump, u_int16_t *oldvalp, u_int16_t newval) > > { > > register int cksum; > > > > cksum = *cksump; > > FIXSUM16(cksum, oldvalp, &newval); > > *cksump = cksum; > > *oldvalp = newval; > > } > > > > > > On Tue, 23 Nov 1999, Parthasarathy M. Aji wrote: > > > > > Hey, > > > > > > I am trying to recompute the checksum of an IP packet. I use > > > netinet/in_chksum.c to do this. The values returned are not correct. I've > > > reset the ip_sum field to 0 before doing the sum. Is there something > > > missing? > > > > > > thanks > > > > > > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > > with "unsubscribe freebsd-hackers" in the body of the message > > > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message