-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-server.c
49 lines (42 loc) · 1.24 KB
/
web-server.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
45
46
47
48
49
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <dirent.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int main(int argc, char *argv[]) {
unsigned short port;
DIR* directory = NULL;
int acceptorSocket;
struct sockaddr_in server, client;
/* (1) Überprüfen, ob Port angegeben wurde */
if (argc != 3) {
fprintf(stderr, "arguments error\r\n");
exit(1);
}
/* Port setzen */
port = (unsigned short) atoi(argv[1]);
/* (2) Verzeichnis setzen */
directory = opendir(argv[2]);
if (directory == NULL) {
fprintf(stderr, "directory error\r\n");
exit(2);
}
/* (3) Socket zum akzeptieren von Clients erstellen */
if ((acceptorSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
fprintf(stderr, "acceptorSocket error\r\n");
exit(3);
}
/* (4) Socket zum akzeptieren an Server binden */
server.sin_family = AF_INET;
server.sin_port = htons(port);
server.sin_addr.s_addr = INADDR_ANY;
if (bind(acceptorSocket, (struct sockaddr *)&server, sizeof(server)) < 0)
{
fprintf(stderr, "bind socket error\r\n");
exit(4);
}
//kurzer Test
}