Implementing HEAD and GET requests, simple web server in C
<p>I'm making a simple web server in C, and I need to handle both simple and full versions of http 1.0 methods HEAD and GET requests. All other requests should result in status code 501. It's my first time programming a web server and finding what you need is kind of hard. Can someone help me get on the right track here. How do I handle the requests? 
My code so far:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/types.h&gt; 
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;netdb.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;time.h&gt;

#define SIZE 512




int main(int argc, char *argv[])
{
    int portnumber;
    int sockfd; //for new client connections
    int sockfd_current; //for accepted clients
    struct sockaddr_in sockIn;
    struct sockaddr_in portIn;
    char buffert[SIZE];
    int addrlen;
    char ipAddress[INET_ADDRSTRLEN]; //incomming IP-address to server with length


    portnumber= atoi(argv[1]);  //second parameter passed from main into portnumber


    if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)  //trying to create socket address-family
    {   
        perror ("socket");
        exit(1);
    }

    memset(&amp;sockIn, 0, sizeof(sockIn)); //assign memory and set socket address structure
    sockIn.sin_family= AF_INET;
    sockIn.sin_addr.s_addr =INADDR_ANY;
    sockIn.sin_port = htons(portnumber); //assign port to network byteorder: hostToNetwork

    if(bind(sockfd, (struct sockaddr *) &amp;sockIn, sizeof(sockIn)) == -1)//trying to assign address to socket
    {
    perror("bind");
    exit(1);
    }

    if(listen(sockfd, 10) == -1)    //trying to Listen for clients that fulfills the requirements  
    {
        perror("listen");
        exit(1);
    }
    addrlen = sizeof(portIn);
    if((sockfd_current = accept(sockfd, (struct sockaddr*) &amp;portIn, (socklen_t*) &amp;addrlen)) == -1)  //trying to Create a new socket for the accepted client
    {
        perror("accept");
        exit(1);
    }

//Start communication aka HEAD/GET from client...
    printf("Accepting connection...\n\n");
    if(recv(sockfd_current, buffert, sizeof(buffert), 0) == -1) //trying to recive message from client
    {
        perror("Failed to recive request from client");
        exit(1);
    }

    inet_ntop(AF_INET, &amp;portIn.sin_addr, ipAddress, sizeof(ipAddress)); //convert binary-ip from client to "networkToPresentable" string
    printf("Request from %s:%i\n", ipAddress, ntohs(portIn.sin_port));
    printf("Message: %s\n", buffert);


//Responds to clients request
    printf("Send Response:\n\n");
    fgets(buffert, SIZE - 1, stdin);

    if(send(sockfd_current, buffert, strlen(buffert) + 1, 0) == -1) 
    {
        perror("send");
        exit(1);
    }


    close(sockfd_current);
    close(sockfd);
    return 0;
}
</code></pre>

<p>The assignment i got was to only make the server and not the client, so I should only have to handle the requests.</p>