diff --git a/bin/httpsrv b/bin/httpsrv index d4d0c49..bd95929 100755 Binary files a/bin/httpsrv and b/bin/httpsrv differ diff --git a/bin/main b/bin/main new file mode 100755 index 0000000..5840d7c Binary files /dev/null and b/bin/main differ diff --git a/lib/file.h b/lib/file.h index 2a29ba2..30c0599 100644 --- a/lib/file.h +++ b/lib/file.h @@ -4,7 +4,7 @@ #include #include -void* readFile(char* path) { +char* readFile(char* path) { path++; if (strlen(path) <= 1) { printf("/ converted to /index.html\n"); @@ -17,13 +17,15 @@ void* readFile(char* path) { errno = -1; return ""; } - void* buf = NULL; + char* buf = NULL; fseek(fp, 0, SEEK_END); int length = ftell(fp); rewind(fp); - buf = malloc(sizeof(char) * (length + 1)); + buf = (char*)malloc(sizeof(char) * (length + 1)); fread(buf, sizeof(char), length, fp); + buf[length] = '\0'; - return buf; + char* tmp = buf; + return tmp; } diff --git a/src/srv.c b/src/srv.c index e469737..d8d8ee8 100644 --- a/src/srv.c +++ b/src/srv.c @@ -45,7 +45,7 @@ int srv(char* ADDR, int PORT) { char* tPath = request.path; char* dot = strrchr(tPath, '.'); - void *file = readFile(request.path); + char *file = readFile(request.path); ResHeader rawHeader; rawHeader.protocol = request.protocol; rawHeader.status = 200; @@ -75,9 +75,8 @@ int srv(char* ADDR, int PORT) { char tmpHeader[1024]; makeHeader(tmpHeader, &rawHeader); char resHeader[1024]; //= "HTTP/1.1 200 OK\r\n\nHello, world!"; - sprintf(resHeader, "%s", (char*)tmpHeader); + sprintf(resHeader, "%s%s", (char*)tmpHeader, file); send(client, resHeader, strlen(resHeader), 0); - send(client, (void*)(&file), sizeof(file), 0); close(client); } }