[PATCHv2] networking: consolidate the IP checksum code

Joakim Tjernlund joakim.tjernlund at transmode.se
Thu Sep 8 10:57:38 UTC 2011


Baruch Siach <baruch at tkos.co.il> wrote on 2011/09/08 07:06:27:
>
> Hi Joakim,

...

> >        if (nbytes & 1) /* Odd */
> >          sum += *(u_char *)ptr;   /* one byte only */
>
> This breaks big endian systems like PowerPC. The assignment via pointer dance
> of the original implementation is required, because we need the last byte to
> be considered as MSB of a 16bit word, as if we had one more '\0' byte in
> buffer.  Note that the generated checksum is the same on big and little endian
> machines in terms of memory representation.  They differ however in their
> numeric representation.  So, for example the checksum of
>
>     uint8_t buf[] = {0x12, 0x34, 0x56};
>
> is 0xcb97 on little endian machines, and 0x97cb on big endian machines. This
> is OK since we use the memory representation of the network packet.

Ouch, even RFC 1071 got it wrong then.

 Jocke



More information about the busybox mailing list