X-Git-Url: http://git.thejh.net/?p=tools.git;a=blobdiff_plain;f=tools%2Fwriteonlynet.c;fp=tools%2Fwriteonlynet.c;h=3bef9f9b2d6b39a2f53e93f01c9ee3325ebeb1a7;hp=0000000000000000000000000000000000000000;hb=7ebc44a8d838298394178687975cf9d2994ff8be;hpb=86973028b439986f4b2a7722c92e44c643ff5869 diff --git a/tools/writeonlynet.c b/tools/writeonlynet.c new file mode 100644 index 0000000..3bef9f9 --- /dev/null +++ b/tools/writeonlynet.c @@ -0,0 +1,27 @@ +#include +#include + +int main(int argc, char **argv) { + if (argc != 3) xperror("invocation: ", 0); + int s = netopen(argv[1], argv[2], JH_TCP_HINTS); + if (s < 0) { + fprintf(stderr, "unable to connect: %s\n", gai_strerror(s)); + exit(1); + } + while (1) { + char buf[4096]; + fprintf(stderr, "reading...\n"); + ssize_t count = fail_on_neg(read(0, buf, sizeof(buf)), "read failed", 1); + if (count == 0) return 0; + fprintf(stderr, "read %zd chars, writing...\n", count); + ssize_t wcount = fail_on_neg(write(s, buf, count), "write failed", 1); + if (wcount == 0) { + fprintf(stderr, "zero write! ending.\n"); + return 1; + } + if (wcount != count) { + fprintf(stderr, "wrong write size! ending.\n"); + return 1; + } + } +}