diff options
author | dzwdz | 2022-08-17 23:10:37 +0200 |
---|---|---|
committer | dzwdz | 2022-08-17 23:10:37 +0200 |
commit | bb05dbe9ab050c420e0cba11f3224bd18dd9d642 (patch) | |
tree | 2aa17b0dd3eac398ac86203f87541932397f6e8b /src/user/app/ethdump/util.c | |
parent | 6ffb06af70faa5657f2c6091fe23500007e2bd44 (diff) |
user/net: respond to pings
Diffstat (limited to 'src/user/app/ethdump/util.c')
-rw-r--r-- | src/user/app/ethdump/util.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/user/app/ethdump/util.c b/src/user/app/ethdump/util.c index b0d8785..8c29340 100644 --- a/src/user/app/ethdump/util.c +++ b/src/user/app/ethdump/util.c @@ -31,3 +31,15 @@ uint32_t crc32(const uint8_t *buf, size_t len) { c = crc_table[(c ^ buf[i]) & 0xff] ^ (c >> 8); return ~c; } + +uint16_t ip_checksum(const uint8_t *buf, size_t len) { + uint32_t c = 0; + while (len >= 2) { + c += nget16(buf); + buf += 2; len -= 2; + } + if (len) c += (*buf) << 8; + while (c >= 0xFFFF) + c = (c & 0xFFFF) + (c >> 16); + return ~c; +} |