diff --git a/url_manipulation.c b/url_manipulation.c index 76186e7..98841ee 100644 --- a/url_manipulation.c +++ b/url_manipulation.c @@ -1,5 +1,8 @@ #include #include +#include + +#define DEFAULT_PATH "/index.html" char* url_to_proto(char* url) { size_t length = strlen(url); @@ -22,20 +25,49 @@ char* url_to_hostname(char* url) { size_t length = strlen(url); char* protocol = url_to_proto(url); - char* to_return = malloc(sizeof(char) * 256); - + char* temp_substring = malloc(sizeof(char) * 256); + char* to_return = malloc(sizeof(char) * 256); /* This is a very roundabout way of saying that, starting from a certain point in the - URL (length of protocol string + 3), we are copying the rest of the string into another + URL (length of protocol string + 3 (':','/','/'), we are copying the rest of the string into another substring. */ - strncpy(to_return,url+(strlen(protocol) + 3),(length - (strlen(protocol) + 3))); - - + strncpy(temp_substring,url+(strlen(protocol) + 3),(length - (strlen(protocol) + 3))); + + /* Now we need to substring _this_ substring, by returning only the part before the next slash. */ + int sentinel = 0; + for (int i=0;i