/
main.c
44 lines (27 loc) · 898 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<netdb.h> // struct addrinfo
struct addrinfo *servinfo;
// linked list -dyn allocated -needs to be global
void configureHints ( struct addrinfo *hints );
void gai ( struct addrinfo *hints, char *port );
int getSocketFD ( ) ;
void registerSigHandler ();
void listenLoop ( int sockfd );
int main ( int argc , char *argv[] ) {
printf("Usage: The default port is 8000. \n");
printf("An example of suppling a different port: \n");
printf("$./httpServer01 8080\n");
char port[5] = "8000";
if(argc > 1) sprintf( port , argv[1] );
printf("Currently set listening port to %s\n", port);
struct addrinfo hints;
configureHints( &hints );
gai( &hints , port);
int sockfd = getSocketFD( );
registerSigHandler( );
listenLoop( sockfd );
// handleClient();
// called from fork'ed child process in
// listenLoop for each client connection
return 0;
}