c programming http get request
Hello,
I am trying to work out how to write a web server program that will serve a single file via a HTTP GET request if the file exists otherwise give the user a 404 error.
I have started by figuring out what libraries I would need, the size of the buffer and a basic struct
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define BUFZ 8096;
struct
{
char *file_type;
char *ext;
}
extensions [] =
{
{"gif", "image/gif" },
{"jpg", "image/jpeg"},
{"jpeg","image/jpeg"},
{"png", "image/png" },
{"htm", "text/html" },
{"html","text/html" },
{0,0}
};
I am not sure exactly where to take it from here. I am trying to get the web server to listen on port 10076 and requests should be outputted in the browser, through the network card ie the request would be http://ipofethcard:10076/path/file.html
Any ideas on how to achieve this or what functions I would need to look at? Perhaps an example code/skeleton I could refer to?
Thanks for any suggestions,