summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authordzwdz2022-08-17 12:49:34 +0200
committerdzwdz2022-08-17 12:49:34 +0200
commit2341a0705164e94d0874572505b60680fdbe631f (patch)
treeaea0bcd5c2339076b10d9e416ea1af4d1fb48400 /src/user
parent63fd7ce362c7f1d59365045f19cf1ca87ffe2db9 (diff)
amd64: rtl8139 driver with basic rx support
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/ethdump/ethdump.c39
1 files changed, 39 insertions, 0 deletions
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 <camellia/syscalls.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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);
+ }
+}