From 642b5fb0007b64c77d186fcb018d571152ee1d47 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 14 Aug 2023 18:51:07 +0200 Subject: reorganization: first steps --- src/cmd/netstack/netstack.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/cmd/netstack/netstack.c (limited to 'src/cmd/netstack/netstack.c') diff --git a/src/cmd/netstack/netstack.c b/src/cmd/netstack/netstack.c new file mode 100644 index 0000000..2636429 --- /dev/null +++ b/src/cmd/netstack/netstack.c @@ -0,0 +1,53 @@ +#include "proto.h" +#include "util.h" +#include +#include +#include +#include +#include +#include +#include + +struct net_state state = { + // TODO dynamically get mac + .mac = {0x52, 0x54, 0x00, 0xCA, 0x77, 0x1A}, +}; + +void network_thread(void *arg) { (void)arg; + const size_t buflen = 4096; + char *buf = malloc(buflen); + for (;;) { + long ret = _sys_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 < 4) { + eprintf("usage: netstack iface ip gateway"); + return 1; + } + state.raw_h = camellia_open(argv[1], OPEN_RW); + if (state.raw_h < 0) { + eprintf("couldn't open %s", argv[1]); + return 1; + } + if (ip_parse(argv[2], &state.ip) < 0) { + eprintf("invalid ip"); + return -1; + } + if (ip_parse(argv[3], &state.gateway) < 0) { + eprintf("invalid gateway"); + return -1; + } + setproctitle(argv[2]); + arp_request(state.gateway); + thread_create(0, network_thread, NULL); + thread_create(0, fs_thread, NULL); + _sys_await(); + return 0; +} -- cgit v1.2.3