From 3607f742f940077622828ac3539514f89b22e079 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 26 Mar 2016 14:50:18 +0000 Subject: [PATCH] socktest: remove hardcoded /test path We now ask for the path specified and save to the matching local basename. --- Applications/util/socktest.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Applications/util/socktest.c b/Applications/util/socktest.c index 121aa0c1..7f235e23 100644 --- a/Applications/util/socktest.c +++ b/Applications/util/socktest.c @@ -28,6 +28,7 @@ int main(int argc, char *argv[]) static char line[81]; char *lp; char *p; + char *fn; int state = 0; if (argc != 2) { @@ -49,6 +50,8 @@ int main(int argc, char *argv[]) exit(1); } *p++ = 0; + fn = p; + lp = strchr(argv[1] + 7, ':'); if (lp == NULL) addr.sin_port = htons(80); @@ -84,12 +87,19 @@ int main(int argc, char *argv[]) perror("connect"); exit(1); } - if (writes(fd, "GET /test HTTP/1.1\r\nHost: test.test\r\n\r\n") == - -1) { + if (writes(fd, "GET /") == -1 || + writes(fd, fn) == -1 || + writes(fd, " HTTP/1.1\r\nHost: ") == -1 || + writes(fd, argv[1] + 7) == -1 || + writes(fd, "\r\n\r\n") == -1) { perror("write"); exit(1); } + p = strrchr(fn, '/'); + if (p) + fn = p + 1; + lp = line; while ((r = read(fd, buf, 512)) > 0) { @@ -128,7 +138,7 @@ int main(int argc, char *argv[]) p++; /* nl/nl end of headers - begin xfer */ fd2 = - open("output", + open(fn, O_WRONLY | O_TRUNC | O_CREAT, 0700); if (fd2 == -1) { -- 2.34.1