2 #include <ip_checksum.h>
4 unsigned long compute_ip_checksum(void *addr
, unsigned long length
)
13 /* In the most straight forward way possible,
14 * compute an ip style checksum.
18 for(i
= 0; i
< length
; i
++) {
24 /* Add the new value */
26 /* Wrap around the carry */
28 sum
= (sum
+ (sum
>> 16)) & 0xFFFF;
31 value
.byte
[0] = sum
& 0xff;
32 value
.byte
[1] = (sum
>> 8) & 0xff;
33 return (~value
.word
) & 0xFFFF;
36 unsigned long add_ip_checksums(unsigned long offset
, unsigned long sum
, unsigned long new)
38 unsigned long checksum
;
42 /* byte swap the sum if it came from an odd offset
43 * since the computation is endian independent this
46 new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00);
49 if (checksum
> 0xFFFF) {
52 return (~checksum
) & 0xFFFF;