From 03c5dd9462492e291c6a49b88e1cd9ab34d86b6f Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 23 Aug 2022 17:58:42 +0200 Subject: user/netstack: TCP listen and close --- src/user/app/netstack/util.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/user/app/netstack/util.c') 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; } -- cgit v1.2.3