summaryrefslogtreecommitdiff
path: root/src/user/app/netstack/util.c
diff options
context:
space:
mode:
authordzwdz2022-08-23 17:58:42 +0200
committerdzwdz2022-08-23 17:58:42 +0200
commit03c5dd9462492e291c6a49b88e1cd9ab34d86b6f (patch)
tree8c8d8e73c8c07b83f5aede18d83671369d0f7589 /src/user/app/netstack/util.c
parentfcdadf5df39e1d72f9ac79fa384fc6b98be0b1aa (diff)
user/netstack: TCP listen and close
Diffstat (limited to 'src/user/app/netstack/util.c')
-rw-r--r--src/user/app/netstack/util.c16
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;
}