diff options
Diffstat (limited to 'src/user/app/netstack/util.c')
-rw-r--r-- | src/user/app/netstack/util.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/user/app/netstack/util.c b/src/user/app/netstack/util.c index e9d3118..68092aa 100644 --- a/src/user/app/netstack/util.c +++ b/src/user/app/netstack/util.c @@ -25,8 +25,20 @@ uint16_t ip_checksum(const uint8_t *buf, size_t len) { buf += 2; len -= 2; } if (len) c += (*buf) << 8; - while (c > 0xFFFF) - c = (c & 0xFFFF) + (c >> 16); + while (c > 0xFFFF) c = (c & 0xFFFF) + (c >> 16); + return ~c; +} + +uint16_t ip_checksumphdr( + const uint8_t *buf, size_t len, + uint32_t ip1, uint32_t ip2, + uint16_t proto) +{ + uint32_t c = (uint16_t)~ip_checksum(buf, len); + c += (ip1 & 0xFFFF) + (ip1 >> 16); + c += (ip2 & 0xFFFF) + (ip2 >> 16); + c += proto + len; + while (c > 0xFFFF) c = (c & 0xFFFF) + (c >> 16); return ~c; } |