diff options
author | dzwdz | 2022-08-20 11:11:57 +0200 |
---|---|---|
committer | dzwdz | 2022-08-20 11:11:57 +0200 |
commit | f22f019aeba00ccb3cc35fe763c3e87bf5690040 (patch) | |
tree | 6f7338b526dca6eebc865096dbdbd3af90cda335 /src/user/app/ethdump/ethdump.c | |
parent | 2a16c1f6f9118e7127d532421ae19b959b3f1d87 (diff) |
user/ethdump: turn into a file server
Diffstat (limited to 'src/user/app/ethdump/ethdump.c')
-rw-r--r-- | src/user/app/ethdump/ethdump.c | 27 |
1 files changed, 17 insertions, 10 deletions
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 <stddef.h> #include <stdlib.h> #include <string.h> +#include <user/lib/thread.h> 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; } |