From e35d6a4fde9a0671bc7d2527ff6b55b0ce1b4b1e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 21 Aug 2022 22:33:09 +0200 Subject: user: rename ethdump to netstack --- src/user/app/netstack/util.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/user/app/netstack/util.h (limited to 'src/user/app/netstack/util.h') diff --git a/src/user/app/netstack/util.h b/src/user/app/netstack/util.h new file mode 100644 index 0000000..5472b05 --- /dev/null +++ b/src/user/app/netstack/util.h @@ -0,0 +1,38 @@ +#pragma once +#include +#include +#include +#include + +#define eprintf(fmt, ...) fprintf(stderr, "netstack: "fmt"\n" __VA_OPT__(,) __VA_ARGS__) + +uint32_t crc32(const uint8_t *buf, size_t len); +uint16_t ip_checksum(const uint8_t *buf, size_t len); + +static inline void nput16(void *vbuf, uint16_t n) { + uint8_t *b = vbuf; + b[0] = n >> 8; + b[1] = n >> 0; +} + +static inline void nput32(void *vbuf, uint32_t n) { + uint8_t *b = vbuf; + b[0] = n >> 24; + b[1] = n >> 16; + b[2] = n >> 8; + b[3] = n >> 0; +} + +static inline uint16_t nget16(const void *vbuf) { + const uint8_t *b = vbuf; + return (b[0] << 8) + | (b[1] << 0); +} + +static inline uint32_t nget32(const void *vbuf) { + const uint8_t *b = vbuf; + return (b[0] << 24) + | (b[1] << 16) + | (b[2] << 8) + | (b[3] << 0); +} -- cgit v1.2.3