Commit 1a2c5f60f3e15f360675b2c962f5aab22abdefd1
1 parent
5940bf6e
Quelques modifs finales
Showing
4 changed files
with
45 additions
and
37 deletions
Show diff stats
Network/sender.c
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | #include <errno.h> |
10 | 10 | |
11 | 11 | |
12 | -int initializeSocketUDP(char* service) | |
12 | +int initializeSocketUDP(char* service, char* adresse) | |
13 | 13 | { |
14 | 14 | int sock_id; |
15 | 15 | struct addrinfo precisions, *resultat=NULL, *origine; // On stocke dans précisions nos besoins pour le socket, dans resultat l'adresse qui respectera les requêtes |
... | ... | @@ -21,7 +21,7 @@ int initializeSocketUDP(char* service) |
21 | 21 | //precisions.ai_flags = AI_PASSIVE; |
22 | 22 | |
23 | 23 | /*"172.26.145.35"*/ |
24 | - if(getaddrinfo("192.168.1.66", service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | |
24 | + if(getaddrinfo(adresse, service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | |
25 | 25 | |
26 | 26 | int n=0; |
27 | 27 | |
... | ... | @@ -70,7 +70,7 @@ int sendUDPBroadcast(char* message, int port) |
70 | 70 | |
71 | 71 | char tmp_str[15]; |
72 | 72 | sprintf(tmp_str, "%d", port); |
73 | - int sock_id=initializeSocketUDP( tmp_str ); | |
73 | + int sock_id=initializeSocketUDP( tmp_str , "255.255.255.255"); | |
74 | 74 | |
75 | 75 | printf("Initialize via Broadcast %d\n", sock_id); |
76 | 76 | |
... | ... | @@ -93,7 +93,7 @@ int sendUDPUnicast(char* address, char* message, int port) |
93 | 93 | |
94 | 94 | char tmp_str[15]; |
95 | 95 | sprintf(tmp_str, "%d", port); |
96 | - int sock_id=initializeSocketUDP( tmp_str ); | |
96 | + int sock_id=initializeSocketUDP( tmp_str , address); | |
97 | 97 | printf("Initialize via Unicast %d\n", sock_id); |
98 | 98 | |
99 | 99 | if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto %d\n", errno); return(-1); } | ... | ... |
Network/sniffer.c
Threads/Page.html deleted
Threads/threadSocket.c
... | ... | @@ -13,20 +13,25 @@ |
13 | 13 | #include "libthrd.h" |
14 | 14 | |
15 | 15 | |
16 | -void vider_interfaces(struct interface_info* interfaces[20]) | |
16 | +void vider_interfaces(Arg_Thread* argument) | |
17 | 17 | { |
18 | + pthread_mutex_lock(&(argument->requete_mutex)); // Section critique | |
19 | + | |
18 | 20 | for(int i=0; i<20; i++) |
19 | 21 | { |
20 | - if(interfaces[i]!=NULL) | |
22 | + if(argument->interfaces[i]!=NULL) | |
21 | 23 | { |
22 | - free(interfaces[i]); | |
23 | - interfaces[i]=NULL; | |
24 | + free(argument->interfaces[i]); | |
25 | + argument->interfaces[i]=NULL; | |
24 | 26 | } |
25 | 27 | } |
28 | + | |
29 | + pthread_mutex_unlock(&(argument->requete_mutex)); // Libération de la section critique | |
30 | + | |
26 | 31 | } |
27 | 32 | |
28 | 33 | |
29 | -int httpReponse(FILE* sockdial_stream, struct interface_info* interfaces[20]) | |
34 | +int httpReponse(FILE* sockdial_stream, Arg_Thread* argument) | |
30 | 35 | { |
31 | 36 | char message[]={0x00,0x00}; |
32 | 37 | |
... | ... | @@ -34,9 +39,13 @@ int httpReponse(FILE* sockdial_stream, struct interface_info* interfaces[20]) |
34 | 39 | |
35 | 40 | struct PageWeb* page; |
36 | 41 | |
37 | - sleep(2); // Temps d'attente avant de recevoir les informations | |
42 | + sleep(10); // Temps d'attente avant de recevoir les informations | |
38 | 43 | |
39 | - createPage(&page, interfaces); // Permet de creer la pageweb (http.c) | |
44 | + pthread_mutex_lock(&(argument->requete_mutex)); // Section critique | |
45 | + | |
46 | + createPage(&page, argument->interfaces); // Permet de creer la pageweb (http.c) | |
47 | + | |
48 | + pthread_mutex_unlock(&(argument->requete_mutex)); // Libération de la section critique | |
40 | 49 | |
41 | 50 | char buffer[BUFF_SIZE]; // Le buffer de message pour l'emission |
42 | 51 | // char buff_rec[BUFF_SIZE]; // Le buffer de message à la reception |
... | ... | @@ -57,26 +66,30 @@ int httpReponse(FILE* sockdial_stream, struct interface_info* interfaces[20]) |
57 | 66 | |
58 | 67 | |
59 | 68 | |
60 | -int interfaceReponse(FILE* sockdial_stream, char packet[BUFF_SIZE], struct interface_info* interfaces[20], char adresse[20]) | |
69 | +int interfaceReponse(FILE* sockdial_stream, char packet[BUFF_SIZE], Arg_Thread* argument, char adresse[20]) | |
61 | 70 | { |
62 | 71 | printf("Interface : %x %x - Adresse : %s - Taille : %ld\n", packet[0], packet[1], adresse, strlen(packet)); |
63 | 72 | |
64 | 73 | char buffer[BUFF_SIZE]; |
65 | 74 | |
75 | + // On lock le mutex car on rentre dans la section critique (modification de la structure interfaces) | |
76 | + | |
77 | + pthread_mutex_lock(&(argument->requete_mutex)); | |
78 | + | |
66 | 79 | int i=0; |
67 | - while(interfaces[i]!=NULL && strcmp(adresse,interfaces[i]->adresse)!=0) | |
80 | + while(argument->interfaces[i]!=NULL && strcmp(adresse, argument->interfaces[i]->adresse)!=0) | |
68 | 81 | { |
69 | 82 | i++; |
70 | 83 | } |
71 | 84 | |
72 | - if(interfaces[0]!=NULL) | |
85 | + if(argument->interfaces[0]!=NULL) | |
73 | 86 | printf("Il y a %d associations\n", i+1); |
74 | 87 | else |
75 | 88 | printf("Il n'y aucune association\n"); |
76 | 89 | |
77 | 90 | |
78 | - if(interfaces[i]!=NULL) | |
79 | - interfaces[i]->status=-1; | |
91 | + if(argument->interfaces[i]!=NULL) | |
92 | + argument->interfaces[i]->status=-1; | |
80 | 93 | |
81 | 94 | |
82 | 95 | if(packet[0]==0x20 && (packet[1]==0x01 || packet[1]==0x00) ) |
... | ... | @@ -84,21 +97,24 @@ int interfaceReponse(FILE* sockdial_stream, char packet[BUFF_SIZE], struct inter |
84 | 97 | //L'interface a correctement répondu, on la rajoute à la liste des interfaces |
85 | 98 | printf("L'interface a correctement répondu\n"); |
86 | 99 | |
87 | - if(interfaces[i]==NULL) | |
100 | + if(argument->interfaces[i]==NULL) | |
88 | 101 | { |
89 | - interfaces[i]=malloc(sizeof(struct interface_info)); | |
90 | - strcpy(interfaces[i]->adresse, adresse); | |
102 | + argument->interfaces[i]=malloc(sizeof(struct interface_info)); | |
103 | + strcpy(argument->interfaces[i]->adresse, adresse); | |
91 | 104 | } |
92 | 105 | |
93 | 106 | if(packet[1]==0x01) |
94 | - interfaces[i]->status=1; | |
107 | + argument->interfaces[i]->status=1; | |
95 | 108 | else |
96 | - interfaces[i]->status=0; | |
109 | + argument->interfaces[i]->status=0; | |
97 | 110 | |
98 | 111 | } |
99 | 112 | else |
100 | 113 | { // L'interface n a pas correctement répondu |
114 | + | |
115 | + pthread_mutex_unlock(&(argument->requete_mutex)); // Libération de la section critique | |
101 | 116 | printf("L'interface n'a pas correctement répondu\n"); |
117 | + | |
102 | 118 | return -1; |
103 | 119 | } |
104 | 120 | |
... | ... | @@ -121,6 +137,9 @@ int interfaceReponse(FILE* sockdial_stream, char packet[BUFF_SIZE], struct inter |
121 | 137 | } |
122 | 138 | */ |
123 | 139 | |
140 | + | |
141 | + pthread_mutex_unlock(&(argument->requete_mutex)); // Libération de la section critique | |
142 | + | |
124 | 143 | return 0; |
125 | 144 | } |
126 | 145 | |
... | ... | @@ -144,13 +163,13 @@ void* reponseConnexion(void* arg_sock_interf) |
144 | 163 | printf("Le message reçu : %s\n", buff_rec); |
145 | 164 | |
146 | 165 | |
147 | - //pthread_mutex_lock(&(argument->requete_mutex)); | |
166 | + | |
148 | 167 | |
149 | 168 | //Distingue la requête HTTP... |
150 | 169 | if(strstr(buff_rec, "GET")!=NULL && strstr(buff_rec, "HTTP")!=NULL) |
151 | 170 | { |
152 | - vider_interfaces(argument->interfaces); | |
153 | - httpReponse(sockdial_stream, argument->interfaces); | |
171 | + vider_interfaces(argument); | |
172 | + httpReponse(sockdial_stream, argument); | |
154 | 173 | } |
155 | 174 | else //.. d'une requête interface |
156 | 175 | { |
... | ... | @@ -160,11 +179,10 @@ void* reponseConnexion(void* arg_sock_interf) |
160 | 179 | { |
161 | 180 | char adresse[20]; |
162 | 181 | sprintf(adresse, "%s", inet_ntoa(((struct sockaddr_in*)&tmp_addr)->sin_addr)); |
163 | - interfaceReponse(sockdial_stream, buff_rec, argument->interfaces, adresse); | |
182 | + interfaceReponse(sockdial_stream, buff_rec, argument, adresse); | |
164 | 183 | } |
165 | 184 | } |
166 | 185 | |
167 | - //pthread_mutex_unlock(&(argument->requete_mutex)); | |
168 | 186 | |
169 | 187 | printf("Sock : %d // Stream : %p \n", sock, sockdial_stream); |
170 | 188 | ... | ... |