summaryrefslogtreecommitdiff
path: root/src/user/app/netstack/netstack.c
diff options
context:
space:
mode:
authordzwdz2022-08-21 22:33:09 +0200
committerdzwdz2022-08-21 22:33:09 +0200
commite35d6a4fde9a0671bc7d2527ff6b55b0ce1b4b1e (patch)
treebeb45a1ea334c18a29297684c009e9fb479bebeb /src/user/app/netstack/netstack.c
parentdc5098f83ac55722744a97d2950f50ef2a221f1a (diff)
user: rename ethdump to netstack
Diffstat (limited to 'src/user/app/netstack/netstack.c')
-rw-r--r--src/user/app/netstack/netstack.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/user/app/netstack/netstack.c b/src/user/app/netstack/netstack.c
new file mode 100644
index 0000000..0451511
--- /dev/null
+++ b/src/user/app/netstack/netstack.c
@@ -0,0 +1,43 @@
+#include "proto.h"
+#include "util.h"
+#include <camellia/syscalls.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <user/lib/thread.h>
+
+struct net_state state = {
+ // TODO dynamically get mac
+ .mac = {0x52, 0x54, 0x00, 0xCA, 0x77, 0x1A},
+ .ip = (192 << 24) + (168 << 16) + 11,
+};
+
+void network_thread(void *arg) { (void)arg;
+ const size_t buflen = 4096;
+ char *buf = malloc(buflen);
+ for (;;) {
+ long ret = _syscall_read(state.raw_h, buf, buflen, -1);
+ if (ret < 0) break;
+ ether_parse((void*)buf, ret);
+ }
+ free(buf);
+}
+
+void fs_thread(void *arg);
+
+int main(int argc, char **argv) {
+ if (argc < 2) {
+ eprintf("no argument");
+ return 1;
+ }
+ state.raw_h = _syscall_open(argv[1], strlen(argv[1]), 0);
+ if (state.raw_h < 0) {
+ eprintf("couldn't open %s", argv[1]);
+ return 1;
+ }
+ thread_create(0, network_thread, NULL);
+ thread_create(0, fs_thread, NULL);
+ _syscall_await();
+ return 0;
+}