#include <agnix/agnix.h>
#include <agnix/net/net.h>
Include dependency graph for ip_checksum.c:
Go to the source code of this file.
Functions | |
u16 | ip_checksum (struct ip_hdr_s *ip) |
|
Definition at line 17 of file ip_checksum.c. Referenced by ip_recv(). 00018 { 00019 u32 sum; 00020 u16 word; 00021 u16 *ptr; 00022 int len; 00023 00024 ptr = (u16 *)ip; 00025 00026 sum = 0; 00027 for (len = sizeof(struct ip_hdr_s); len > 1; len -= 2, ptr++) { 00028 sum += *ptr; 00029 } 00030 00031 if (len == 1) { 00032 word = 0; 00033 *((u8 *) &word) = *(u8 *)ptr; 00034 sum += word; 00035 } 00036 00037 sum = (sum >> 16) + (sum & 0xffff); 00038 sum += (sum >> 16); 00039 00040 return (u16)(~sum); 00041 };
|