From 68737770318f2ca4ec26c0623933e7c01f552fba Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 10 Dec 2020 16:11:08 -0500 Subject: [PATCH] took a first pass at implementing dial --- bin/dial.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/bin/dial.c b/bin/dial.c index 3429c39..ef5373f 100644 --- a/bin/dial.c +++ b/bin/dial.c @@ -1,5 +1,6 @@ #include #include +#include int main(int argc, char** argv) { @@ -9,16 +10,34 @@ int main(int argc, char** argv) return 1; } - int fd = netdial(argv[1]); - if (argc > 2) - { - /* execute command with socket as stdio */ - } - else + int sockfd = netdial(argv[1]); + + char buf[8192]; + struct pollfd fds[] = { + { .fd = sockfd, .events = POLLIN }, + { .fd = STDIN_FILENO, .events = POLLIN }, + }; + + while(1) { - /* copy data to/from stdio */ + if (poll(fds, nelem(fds), -1) < 0) + { + fatal("poll():"); + } + + if (fds[0].revents & POLLIN) + { + write(fds[1].fd, buf, read(fds[0].fd, buf, sizeof(buf))); + fds[0].revents = 0; + } + + if (fds[1].revents & POLLIN) + { + write(fds[0].fd, buf, read(fds[1].fd, buf, sizeof(buf))); + fds[0].revents = 0; + } } - close(fd); + close(sockfd); return 0; } \ No newline at end of file -- 2.52.0