Re: Bug#284729: libnet1: UDP checksums are bogus in odd sized packets

Frédéric Raynal <[email protected]> Thu, 9 Dec 2004 14:08:49 +0100
Newsgroups gmane.comp.security.libnet
Message-ID <[email protected]>
On Thu, Dec 09, 2004 at 01:06:59PM +0100, Domenico Andreoli wrote:
>=20
>=20
> On Thu, Dec 09, 2004 at 06:16:30AM +0100, Fr=E9d=E9ric Raynal wrote:
> >=20
> > Hi,
>=20
> hi, thank you for the fast response :)
>=20
> > Here is a replacement function for libnet_in_cksum() (file
> > libnet/src/libnet_checksum.c) Several fix have been proposed on
> > libnet's ML, and that the one _I_ prefer, but I dont know if that is
> > the one Mike kept.
>=20
> i'm leaving few days to Mike to comment the thread, then i'll use
> your fix.


Note that I did not said it was my fix, but the one I adopted. We had
long discussion on libnet's ML, and that fix have been proposed by Wu
Yongwei.

Cheers,=20

	Fred

int
libnet_in_cksum(u_int16_t *addr, size_t len)
{
    int sum;
    u_int16_t last_byte;

    sum =3D 0;
    last_byte =3D 0;
    while (len > 1)
    {
        sum +=3D *addr++;
        len -=3D 2;
    }
    if (len =3D=3D 1)
    {
        *(u_int8_t*)&last_byte =3D *(u_int8_t*)addr;
        sum +=3D last_byte;
    }
    return sum;
}