Created
February 22, 2016 20:17
-
-
Save tjs-w/98e0bdb28053c79ba812 to your computer and use it in GitHub Desktop.
TCP Checksum
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
uint32_t __core_csum_tcp(uint16_t *addr, uint32_t count) | |
{ | |
register uint32_t sum = 0; | |
while (count > 1) { | |
sum += *addr++; | |
count -= 2; | |
} | |
/* Add left-over byte, if any, (zero padding) */ | |
if (count) | |
sum += *(uint8_t *) addr; | |
/* Fold 32-bit sum to 16 bits */ | |
while (sum >> 16) | |
sum = (sum & 0xffff) + (sum >> 16); | |
return ~sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment