summaryrefslogtreecommitdiff
path: root/Userland/tc.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-14 15:19:20 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-14 15:19:20 +0100
commit4629272135074ed5fbc322b6837741bd59701e5a (patch)
treefa81e6530e434736b06df339ecf736ad07e8be9b /Userland/tc.cpp
parent2c3cf22bc9de55d7ef4301f292a3f516f13cf813 (diff)
downloadserenity-4629272135074ed5fbc322b6837741bd59701e5a.zip
Userland: Turn the tc test util into a simple dumb HTTP client.
Diffstat (limited to 'Userland/tc.cpp')
-rw-r--r--Userland/tc.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/Userland/tc.cpp b/Userland/tc.cpp
index 1e68839ef2..374d61474c 100644
--- a/Userland/tc.cpp
+++ b/Userland/tc.cpp
@@ -35,7 +35,7 @@ int main(int argc, char** argv)
memset(&dst_addr, 0, sizeof(dst_addr));
dst_addr.sin_family = AF_INET;
- dst_addr.sin_port = htons(8080);
+ dst_addr.sin_port = htons(80);
rc = inet_pton(AF_INET, addr_str, &dst_addr.sin_addr);
if (rc < 0) {
perror("inet_pton");
@@ -52,7 +52,7 @@ int main(int argc, char** argv)
printf("ok!\n");
char buffer[BUFSIZ];
- const char* msg = "I am a TCP client.";
+ const char* msg = "GET / HTTP/1.0\r\n\r\n";
printf("Sending a greeting...");
rc = send(fd, (const char*)msg, strlen(msg), 0);
@@ -63,16 +63,21 @@ int main(int argc, char** argv)
printf("ok!\n");
printf("Waiting for response...");
- ssize_t nrecv = recv(fd, buffer, sizeof(buffer), 0);
- if (nrecv < 0) {
- perror("recvfrom");
- return 1;
+ size_t total_recv = 0;
+ for (;;) {
+ ssize_t nrecv = recv(fd, buffer, sizeof(buffer), 0);
+ if (nrecv < 0) {
+ perror("recvfrom");
+ return 1;
+ }
+ if (nrecv == 0)
+ break;
+ total_recv += nrecv;
+ buffer[nrecv] = '\0';
+ printf("\033[36;1m%s\033[0m", buffer);
}
- buffer[nrecv] = '\0';
- printf("ok! Got response:\n");
- printf("\033[36;1m%s\033[0m", buffer);
- printf("(%d bytes received)\n", nrecv);
+ printf("(%u bytes received)\n", total_recv);
rc = close(fd);
if (rc < 0) {
perror("close");