From 2341a0705164e94d0874572505b60680fdbe631f Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 17 Aug 2022 12:49:34 +0200 Subject: amd64: rtl8139 driver with basic rx support --- src/user/app/ethdump/ethdump.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/user/app/ethdump/ethdump.c (limited to 'src/user/app') diff --git a/src/user/app/ethdump/ethdump.c b/src/user/app/ethdump/ethdump.c new file mode 100644 index 0000000..249ecd7 --- /dev/null +++ b/src/user/app/ethdump/ethdump.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +#define eprintf(fmt, ...) fprintf(stderr, "ethdump: "fmt"\n" __VA_OPT__(,) __VA_ARGS__) + +void hexdump(void *vbuf, size_t len) { + uint8_t *buf = vbuf; + for (size_t i = 0; i < len; i += 16) { + printf("%08x ", i); + + for (size_t j = i; j < i + 8 && j < len; j++) + printf("%02x ", buf[j]); + printf(" "); + for (size_t j = i + 8; j < i + 16 && j < len; j++) + printf("%02x ", buf[j]); + printf("\n"); + } +} + +int main(void) { + const char *path = "/kdev/eth"; + handle_t h = _syscall_open(path, strlen(path), 0); + if (h < 0) { + eprintf("couldn't open %s", path); + return 1; + } + + const size_t buflen = 4096; + char *buf = malloc(buflen); + for (;;) { + long ret = _syscall_read(h, buf, buflen, -1); + if (ret < 0) break; + printf("packet of length %u\n", ret); + hexdump(buf, ret); + } +} -- cgit v1.2.3