summaryrefslogtreecommitdiff
path: root/app/v3_c/src/myhttpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/v3_c/src/myhttpd.c')
-rw-r--r--app/v3_c/src/myhttpd.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/app/v3_c/src/myhttpd.c b/app/v3_c/src/myhttpd.c
index d662dd3..1e0c3e8 100644
--- a/app/v3_c/src/myhttpd.c
+++ b/app/v3_c/src/myhttpd.c
@@ -5,17 +5,46 @@
#include <stdio.h>
#include <stdlib.h>
+#include <strings.h>
#include <errno.h>
#include "myhttpd.h"
+#include "utils.h"
int main() {
- //int res;
-
- int sockServ;
+ 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 -1) { perror("socket"); exit(1); }
+ 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;
}
+