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