summaryrefslogtreecommitdiff
path: root/app/v3_c/src
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2011-01-22 17:14:23 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2011-01-22 17:14:23 +0000
commit97916409eb9cdaf9b4f6ed12a5693c5e6f3ee0d8 (patch)
tree71a42ed7468ee7724d2a6a9af3b372038da92957 /app/v3_c/src
parentcebbe1cd7fe8be10d51a1d8fc4007407b1ba77c7 (diff)
download2011-usi-97916409eb9cdaf9b4f6ed12a5693c5e6f3ee0d8.tar.gz
2011-usi-97916409eb9cdaf9b4f6ed12a5693c5e6f3ee0d8.tar.bz2
2011-usi-97916409eb9cdaf9b4f6ed12a5693c5e6f3ee0d8.zip
Version du C qui compile et qui accepte des clients
git-svn-id: file:///var/svn/2011-usi/trunk@11 db941bf7-0cb3-4dda-9634-87faf64f93a7
Diffstat (limited to 'app/v3_c/src')
-rw-r--r--app/v3_c/src/include/utils.h5
-rw-r--r--app/v3_c/src/myhttpd.c37
-rw-r--r--app/v3_c/src/myhttpd.h.in3
-rw-r--r--app/v3_c/src/utils.c7
4 files changed, 45 insertions, 7 deletions
diff --git a/app/v3_c/src/include/utils.h b/app/v3_c/src/include/utils.h
index 285f79b..faa4e8e 100644
--- a/app/v3_c/src/include/utils.h
+++ b/app/v3_c/src/include/utils.h
@@ -1,6 +1,9 @@
#ifndef UTILS_H
#define UTILS_H
-int tobedone();
+#ifdef DEBUG
+#include <stdio.h>
+void logs(char *s);
+#endif
#endif
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;
}
+
diff --git a/app/v3_c/src/myhttpd.h.in b/app/v3_c/src/myhttpd.h.in
index ab0a40a..ce022b8 100644
--- a/app/v3_c/src/myhttpd.h.in
+++ b/app/v3_c/src/myhttpd.h.in
@@ -4,5 +4,8 @@
#define MYHTTPD_VERSION_MAJOR @NetLemmings_VERSION_MAJOR@
#define MYHTTPD_VERSION_MINOR @NetLemmings_VERSION_MINOR@
+#define LISTEN_PORT 8080
+#define LISTEN_BACKLOG 5
+
#endif
diff --git a/app/v3_c/src/utils.c b/app/v3_c/src/utils.c
index cabb464..750a926 100644
--- a/app/v3_c/src/utils.c
+++ b/app/v3_c/src/utils.c
@@ -1,5 +1,8 @@
#include "utils.h"
-int tobedone() {
- return 0;
+#ifdef DEBUG
+#include <stdio.h>
+void logs(char *s) {
+ fprintf(stderr, "%s\n", s);
}
+#endif