diff options
author | dzwdz | 2022-08-20 15:05:19 +0200 |
---|---|---|
committer | dzwdz | 2022-08-20 15:05:19 +0200 |
commit | 7519e57749e176be60b7185d7bbdc298b1744c3c (patch) | |
tree | f320249b75a90a016451acab06c09dbcefdbc89a /src/user/app/netdog/nd.c | |
parent | f22f019aeba00ccb3cc35fe763c3e87bf5690040 (diff) |
user/ethdump: UDP support
Diffstat (limited to 'src/user/app/netdog/nd.c')
-rw-r--r-- | src/user/app/netdog/nd.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/user/app/netdog/nd.c b/src/user/app/netdog/nd.c new file mode 100644 index 0000000..363c6c6 --- /dev/null +++ b/src/user/app/netdog/nd.c @@ -0,0 +1,47 @@ +#include <camellia/syscalls.h> +#include <stdio.h> +#include <string.h> +#include <user/lib/thread.h> + +#define eprintf(fmt, ...) fprintf(stderr, "netdog: "fmt"\n" __VA_OPT__(,) __VA_ARGS__) + +handle_t conn; + +void send_stdin(void *arg) { (void)arg; + static char buf[4096]; + for (;;) { + // TODO define STDIN_FILENO + long ret = _syscall_read(0, buf, sizeof buf, -1); + if (ret <= 0) return; /* instead of sending an empty packet, quit. */ + ret = _syscall_write(conn, buf, ret, -1, 0); + if (ret < 0) return; + } +} + +void recv_stdout(void *arg) { (void)arg; + static char buf[4096]; + for (;;) { + long ret = _syscall_read(conn, buf, sizeof buf, -1); + if (ret < 0) return; + ret = _syscall_write(1, buf, ret, -1, 0); + if (ret < 0) return; + } +} + +int main(int argc, char **argv) { + if (argc < 2) { + eprintf("no argument"); + return 1; + } + + conn = _syscall_open(argv[1], strlen(argv[1]), 0); + if (conn < 0) { + eprintf("couldn't open '%s', err %u", argv[1], -conn); + return -conn; + } + + thread_create(0, send_stdin, NULL); + thread_create(0, recv_stdout, NULL); + _syscall_await(); + return 0; +} |