Created
October 9, 2011 14:39
-
-
Save GreenRecycleBin/1273762 to your computer and use it in GitHub Desktop.
IP checksum
This file contains hidden or 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
| uint16_t ip_checksum(struct ip *p_ip_header, size_t len) | |
| { | |
| register int sum = 0; | |
| uint16_t *ptr = (unsigned short*)p_ip_header; | |
| while (len > 1){ | |
| sum += *ptr++; | |
| len -= 2; | |
| } | |
| sum = (sum >> 16) + (sum & 0xFFFF); | |
| sum += (sum >> 16); | |
| return ~sum; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment