diff options
author | dzwdz | 2022-08-17 21:26:29 +0200 |
---|---|---|
committer | dzwdz | 2022-08-17 21:26:29 +0200 |
commit | 6ffb06af70faa5657f2c6091fe23500007e2bd44 (patch) | |
tree | 8228cdda29cda0c44ff6a09d5a76314fa9760ce9 /src/user/app/ethdump/util.h | |
parent | 5abcc66cb6e83f02b5218802d3eca74c0d29bebf (diff) |
user/ethdump: file per protocol, ethernet frame functions
Diffstat (limited to 'src/user/app/ethdump/util.h')
-rw-r--r-- | src/user/app/ethdump/util.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/user/app/ethdump/util.h b/src/user/app/ethdump/util.h new file mode 100644 index 0000000..536f270 --- /dev/null +++ b/src/user/app/ethdump/util.h @@ -0,0 +1,38 @@ +#pragma once +#include <stdint.h> +#include <stdio.h> + +#define eprintf(fmt, ...) fprintf(stderr, "ethdump: "fmt"\n" __VA_OPT__(,) __VA_ARGS__) + +void hexdump(const void *vbuf, size_t len); + +uint32_t crc32(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); +} |