attempt to send binary data (for images, etc)

master
Drake 2 years ago
parent a6428d1b1b
commit 3ff8f9a0c6

Binary file not shown.

Binary file not shown.

@ -4,7 +4,7 @@
#include <string.h>
#include <errno.h>
char* readFile(char* path) {
void* readFile(char* path) {
path++;
if (strlen(path) <= 1) {
printf("/ converted to /index.html\n");
@ -17,15 +17,13 @@ char* readFile(char* path) {
errno = -1;
return "";
}
char* buf = NULL;
void* buf = NULL;
fseek(fp, 0, SEEK_END);
int length = ftell(fp);
rewind(fp);
buf = (char*)malloc(sizeof(char) * (length + 1));
buf = malloc(sizeof(char) * (length + 1));
fread(buf, sizeof(char), length, fp);
buf[length] = '\0';
char* tmp = buf;
return tmp;
return buf;
}

@ -45,7 +45,7 @@ int srv(char* ADDR, int PORT) {
char* tPath = request.path;
char* dot = strrchr(tPath, '.');
char *file = readFile(request.path);
void *file = readFile(request.path);
ResHeader rawHeader;
rawHeader.protocol = request.protocol;
rawHeader.status = 200;
@ -75,8 +75,9 @@ 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%s", (char*)tmpHeader, file);
sprintf(resHeader, "%s", (char*)tmpHeader);
send(client, resHeader, strlen(resHeader), 0);
send(client, (void*)(&file), sizeof(file), 0);
close(client);
}
}

Loading…
Cancel
Save