1 /*****************************************************************************\
2 * compute_ip_checksum.c
3 \*****************************************************************************/
6 #include "ip_checksum.h"
8 /* Note: The contents of this file were borrowed from the coreboot source
9 * code which may be obtained from https://www.coreboot.org.
10 * Specifically, this code was obtained from coreboot (LinuxBIOS)
14 unsigned long compute_ip_checksum(void *addr
, unsigned long length
)
23 /* In the most straight forward way possible,
24 * compute an ip style checksum.
28 for (i
= 0; i
< length
; i
++) {
34 /* Add the new value */
36 /* Wrap around the carry */
38 sum
= (sum
+ (sum
>> 16)) & 0xFFFF;
41 value
.byte
[0] = sum
& 0xff;
42 value
.byte
[1] = (sum
>> 8) & 0xff;
43 return (~value
.word
) & 0xFFFF;