From 712e3910ad577266204fa78308e62eeb91ed5800 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Sat, 10 Nov 2018 21:18:12 +0100 Subject: [PATCH] Fix bug in client and change the Makefiles --- http/Makefile | 2 +- http/client.c | 6 +++--- mygrep/Makefile | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/http/Makefile b/http/Makefile index 2980989..fa2fb08 100644 --- a/http/Makefile +++ b/http/Makefile @@ -28,4 +28,4 @@ clean: $(RM) *.tgz package: - tar -cvzf server.tgz $(TARGET_1).c $(TARGET_2).c shared public Makefile + tar -cvzf http.tgz $(TARGET_1).c $(TARGET_2).c shared public Makefile diff --git a/http/client.c b/http/client.c index 2c1ed82..d95e5d4 100644 --- a/http/client.c +++ b/http/client.c @@ -82,15 +82,15 @@ int main(int argc, char *argv[]) { char *base_url = strstr(url, "http://") + 7; //< the base url starts after http:// - const char *path = strstr(base_url, "/"); + char *path = malloc(strlen(base_url) + 1); + strcpy(path, base_url); //< Copying so that strtok() doesn't change it + path = strstr(path, "/"); if(path == NULL) path = "/"; //< Set the root path if there is none const char *hostname = strtok(base_url, ";/?:@=&"); //< Get the FQDN of the remote - struct addrinfo* config = get_host_info(hostname, port); //< Check if the address is resolvable char header[strlen(base_url) + 100]; //< Create a variable to store the header - snprintf(header, sizeof header, "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", path, hostname); //< Build the header int sockfd = create_socket(config); diff --git a/mygrep/Makefile b/mygrep/Makefile index b6c7638..1a5a230 100644 --- a/mygrep/Makefile +++ b/mygrep/Makefile @@ -11,4 +11,8 @@ install: clean: $(RM) $(TARGET).o - $(RM) $(TARGET) \ No newline at end of file + $(RM) $(TARGET) + $(RM) *.tgz + +package: + tar -cvzf mygrep.tgz $(TARGET).c Makefile