blob: 1e0c3e85b7014d7f0af84b4f0555f254a986ee0a (
plain)
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
50
|
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include "myhttpd.h"
#include "utils.h"
int main() {
int res;
int sockServ, sockCli;
struct sockaddr_in servAddr, cliAddr;
size_t cliAddrLen;
int ending;
// Création socket
sockServ = socket(AF_INET, SOCK_STREAM, 0);
if (sockServ < 0) { perror("socket"); exit(1); }
// Accrochage du socket (adresse et port locaux)
bzero((char *) &servAddr, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = INADDR_ANY;
servAddr.sin_port = htons(LISTEN_PORT);
res=bind(sockServ, (struct sockaddr *) &servAddr, sizeof(servAddr));
if (res < 0) { perror("bind"); exit(2); }
// On la:nce l'écoute
listen(sockServ,LISTEN_BACKLOG);
if (res < 0) { perror("listen"); exit(3); }
// Boucle d'acceptation des clients
cliAddrLen = sizeof(cliAddr);
ending=0;
while ( ! ending ) {
sockCli=accept(sockServ, (struct sockaddr *) &cliAddr, &cliAddrLen);
#ifdef DEBUG
logs("Client accepté");
#endif
}
return 0;
}
|