title: problem with showing the default page in web server
body: <p>I have a simple webserver and When I run my webserver and try to access it through firefox it gives me bin file to download instead of showing the default page which is index.html
  If I write it like localhost:8001/index.html it works fine and it shows the content of the index.html file
  how can I fix it so that when i enter like localhost:8001 it just open the index.html file and show the content of it?</p>
  
  <p>The main function of my code:</p>
  
  <pre><code>#define PORT 8001
  
  int main()
  {
          int server_socket, new_socket;
          long value;
          struct sockaddr_in address;
          int addrlen = sizeof(address);
    char response_data[1024];
  
  
          //open a file to serve
    FILE *html_data = fopen("/home/seclab/www/index.html","r");
  
          fgets(response_data, 1024, html_data);
  
          char http_header[2048] = "HTTP/1.0 200 OK\r\n\n";
          strcat(http_header, response_data);
  
          //create a socket
          if((server_socket = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)
          {
                      perror("can not create socket");
                      return 0;
          }
  
          //define the address
          //memset(address.sin_zero, '\0' , sizeof address.sin_zero );
          address.sin_family = AF_INET;
        address.sin_port = htons(PORT);
        address.sin_addr.s_addr = INADDR_ANY;
  
          if(bind(server_socket, (struct sockaddr *) &amp;address, sizeof(address)) &lt; 0 )
          {
                      perror("can't bind the address to the socket");
                      return 0;
          }
  
          if(listen(server_socket, 8) &lt; 0)
          {
                      perror("In listen");
                      exit(EXIT_FAILURE);
          }
  
          while(1)
          {
                      //printf("\nwaiting for a connection\n\n");
                       if((new_socket = accept(server_socket,NULL , NULL)) &lt; 0)
                       {
                                  perror("In accept");
                                  exit(EXIT_FAILURE);
                       }
  
                      send(new_socket, http_header, sizeof(http_header), 0);
                      printf("%s",http_header);
                      //char buffer[30000] = {0};
                      //value=read(new_socket, buffer , 30000);
                      //printf("%s\n",buffer);
                    //write(new_socket, response_data , strlen(response_data));
                      //printf("Greeting message sent\n");    
                      close(new_socket);
          }
          return 0;
  }
  </code></pre>
  
  <p>Screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/YRAfH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YRAfH.jpg" alt="enter image description here"></a></p>