From f22f019aeba00ccb3cc35fe763c3e87bf5690040 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 20 Aug 2022 11:11:57 +0200 Subject: user/ethdump: turn into a file server --- src/user/app/ethdump/ethdump.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src/user/app/ethdump/ethdump.c') diff --git a/src/user/app/ethdump/ethdump.c b/src/user/app/ethdump/ethdump.c index 4047962..17592a1 100644 --- a/src/user/app/ethdump/ethdump.c +++ b/src/user/app/ethdump/ethdump.c @@ -5,6 +5,7 @@ #include #include #include +#include struct net_state state = { // TODO dynamically get mac @@ -12,23 +13,29 @@ struct net_state state = { .ip = (192 << 24) + (168 << 16) + 11, }; -int main(void) { - const char *path = "/kdev/eth"; - state.raw_h = _syscall_open(path, strlen(path), 0); - if (state.raw_h < 0) { - eprintf("couldn't open %s", path); - return 1; - } - +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; - printf("\npacket of length %u\n", ret); - hexdump(buf, ret); ether_parse((void*)buf, ret); } free(buf); +} + +void fs_thread(void *arg); + +int main(void) { + const char *path = "/kdev/eth"; + state.raw_h = _syscall_open(path, strlen(path), 0); + if (state.raw_h < 0) { + eprintf("couldn't open %s", path); + return 1; + } + + thread_create(0, network_thread, NULL); + thread_create(0, fs_thread, NULL); + _syscall_await(); return 0; } -- cgit v1.2.3