Created
July 1, 2013 20:50
-
-
Save cmouse/5904527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uin16_t icmp6_checksum(const u_char *src_addr, const u_char *dest_addr, u_char *buff, size_t dlen, uint16_t *target) { | |
uint16_t word16; | |
uint32_t sum=0; | |
size_t i; | |
uint16_t pad; | |
pad=dlen&1; | |
for (i=0;i<16;i=i+2){ | |
word16 =((src_addr[i]<<8)&0xFF00)+(src_addr[i+1]&0xFF); | |
sum += (uint32_t)word16; | |
} | |
for (i=0;i<16;i=i+2){ | |
word16 =((dest_addr[i]<<8)&0xFF00)+(dest_addr[i+1]&0xFF); | |
sum += (uint32_t)word16; | |
} | |
sum += ntohl(dlen); | |
sum += 0x003A; // ICMPv6 | |
for (i=0;i<dlen+pad;i=i+2){ | |
word16 =((buff[i]<<8)&0xff00)+(buff[i+1]&0xff); | |
sum += (uint32_t)word16; | |
} | |
sum = (sum & 0xFFFF)+(sum >> 16); | |
(*target) = htons((uint16_t)~sum); | |
return *target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment