Fix bug in client and change the Makefiles

This commit is contained in:
Ivaylo Ivanov 2018-11-10 21:18:12 +01:00
parent 36495526b5
commit 712e3910ad
3 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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);

View File

@ -11,4 +11,8 @@ install:
clean:
$(RM) $(TARGET).o
$(RM) $(TARGET)
$(RM) $(TARGET)
$(RM) *.tgz
package:
tar -cvzf mygrep.tgz $(TARGET).c Makefile