From f5ae0cd2d26d312a8eb441dba290771f683a75d3 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Sun, 6 Dec 2020 17:37:11 -0600 Subject: fix makefile and finish P4??? --- P4/Makefile | 2 +- P4/util.c | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 21 deletions(-) (limited to 'P4') diff --git a/P4/Makefile b/P4/Makefile index 6f8b473..2829f78 100644 --- a/P4/Makefile +++ b/P4/Makefile @@ -6,4 +6,4 @@ web_server: server.c util.c ${CC} -Wall -o web_server server.c util.c ${LDFLAGS} clean: - rm web_server + rm web_server webserver_log diff --git a/P4/util.c b/P4/util.c index f9b8d1b..03da8b8 100644 --- a/P4/util.c +++ b/P4/util.c @@ -16,7 +16,7 @@ #include "util.h" //Global socket -int sockfd, new_socket; +int sockfd; /********************************************** * init @@ -67,11 +67,11 @@ void init(int port) { int accept_connection(void) { struct sockaddr_in address; - int addrlen = sizeof(address); + int addrlen = sizeof(address), new_socket = 0; if ((new_socket = accept(sockfd, (struct sockaddr *)&address, (socklen_t*)&addrlen))<0) { perror("Accept"); return -1; - } + }; return(new_socket); } @@ -97,22 +97,22 @@ int get_request(int fd, char *filename) { char get[100], http[100]; read(fd, buffer, 2048); - + printf("%s\n", buffer); if(sscanf(buffer, "%s %s %s", get, filename, http) < 2) { // Read HTTP Get request and parse - close(fd); + perror("Cannot parse request"); return -1; } else if (strcmp(get, "GET")) { - close(fd); + printf("Not a GET\n"); return -2; } else if (strlen(filename) > 1023) { - close(fd); + printf("Not sure but bad\n"); return -3; } for (int i=0; i