Commit c35daaf678677555cf1884d1e5abe4419482975c
1 parent
685f1984
Organisation, création des librairies et des Makefiles
Showing
305 changed files
with
337 additions
and
78 deletions
Show diff stats
Network/.sender.c.swp deleted
No preview for this file type
@@ -2,29 +2,39 @@ | @@ -2,29 +2,39 @@ | ||
2 | # Makefile pour generer la bibliotheque de fonctions de communication | 2 | # Makefile pour generer la bibliotheque de fonctions de communication |
3 | # | 3 | # |
4 | 4 | ||
5 | -all : sniffer sender | 5 | +CC=gcc |
6 | +CFLAGS=-W -Wall -Wextra | ||
7 | +CLIBS=ar -rcs | ||
8 | +LIB=libnet.a | ||
9 | +LDIR=../libs/ | ||
10 | +LIBS=$(LDIR)libnet.a $(LDIR)libthrd.a | ||
11 | +IDIR=../includes/ | ||
12 | +LDFLAGS=-lpthread -lpcap | ||
6 | 13 | ||
7 | -sniffer: sniffer.c | ||
8 | - gcc -o sniffer sniffer.c -lpcap | ||
9 | 14 | ||
10 | -sender: sender.c | ||
11 | - gcc -o sender sender.c | ||
12 | 15 | ||
13 | -#all: libnet.a | 16 | +all: $(LIB) |
14 | 17 | ||
15 | -# | ||
16 | -# La cible de nettoyage | ||
17 | -# | 18 | +$(LIB): sender.o sniffer.o tcpserver.o |
19 | + rm -f $@ | ||
20 | + $(CLIBS) $(LDIR)$@ $^ | ||
21 | + ranlib $(LDIR)$@ | ||
22 | + | ||
23 | + | ||
24 | +tcpserver.o: tcpserver.c | ||
25 | + $(CC) -o $@ -c $^ -I$(IDIR) $(CFLAGS) | ||
26 | + | ||
27 | +sniffer.o: sniffer.c | ||
28 | + $(CC) -o $@ -c $^ $(CFLAGS) | ||
29 | + | ||
30 | +sender.o: sender.c | ||
31 | + $(CC) -o $@ -c $^ $(CFLAGS) | ||
18 | 32 | ||
19 | -#clean: | ||
20 | -# rm -f core *.o libnet.a | ||
21 | 33 | ||
22 | # | 34 | # |
23 | -# Les cibles pour la bibliotheque | 35 | +# La cible de nettoyage |
24 | # | 36 | # |
25 | 37 | ||
26 | -#libnet.o: libnet.c libnet.h | 38 | +clean: |
39 | + rm -f *.o $(LDIR)$(LIB) ../bin/test | ||
27 | 40 | ||
28 | -#libcom.a: libnet.o | ||
29 | -# rm -f $@ | ||
30 | -# $(CLIB) $@ $+ |
Network/libpcap-1.9.0/ChmodBPF/StartupParameters.plist
100644 → 100755
Network/libpcap-1.9.0/Win32/Prj/wpcap.vcxproj.filters
100644 → 100755
Network/libpcap-1.9.0/cmake/Modules/FindDAG.cmake
100644 → 100755
Network/libpcap-1.9.0/cmake/Modules/FindFseeko.cmake
100644 → 100755
Network/libpcap-1.9.0/cmake/Modules/FindLFS.cmake
100644 → 100755
Network/libpcap-1.9.0/cmake/Modules/FindPacket.cmake
100644 → 100755
Network/libpcap-1.9.0/cmake/Modules/FindSNF.cmake
100644 → 100755
Network/libpcap-1.9.0/cmake/Modules/FindTC.cmake
100644 → 100755
Network/libpcap-1.9.0/cmake/have_siocglifconf.c
100644 → 100755
Network/libpcap-1.9.0/cmake_uninstall.cmake.in
100644 → 100755
Network/libpcap-1.9.0/doc/DLT_ALLOCATE_HOWTO.md
100644 → 100755
Network/libpcap-1.9.0/org.tcpdump.chmod_bpf.plist
100644 → 100755
Network/libpcap-1.9.0/pcap-linktype.manmisc.in
100644 → 100755
Network/libpcap-1.9.0/pcap-savefile.manfile.in
100644 → 100755
Network/libpcap-1.9.0/pcap_can_set_rfmon.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_datalink_name_to_val.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_datalink_val_to_name.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_get_required_select_timeout.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_get_selectable_fd.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_get_tstamp_precision.3pcap.in
100644 → 100755
Network/libpcap-1.9.0/pcap_list_datalinks.3pcap.in
100644 → 100755
Network/libpcap-1.9.0/pcap_list_tstamp_types.3pcap.in
100644 → 100755
Network/libpcap-1.9.0/pcap_major_version.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_offline_filter.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_open_offline.3pcap.in
100644 → 100755
Network/libpcap-1.9.0/pcap_set_buffer_size.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_set_immediate_mode.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_set_protocol_linux.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_set_tstamp_precision.3pcap.in
100644 → 100755
Network/libpcap-1.9.0/pcap_set_tstamp_type.3pcap.in
100644 → 100755
Network/libpcap-1.9.0/pcap_tstamp_type_name_to_val.3pcap
100644 → 100755
Network/libpcap-1.9.0/pcap_tstamp_type_val_to_name.3pcap
100644 → 100755
Network/libpcap-1.9.0/rpcapd/org.tcpdump.rpcapd.plist
100644 → 100755
Network/libpcap-1.9.0/rpcapd/rpcapd.inetd.conf
100644 → 100755
Network/libpcap-1.9.0/rpcapd/rpcapd.manadmin.in
100644 → 100755
Network/libpcap-1.9.0/rpcapd/rpcapd.xinetd.conf
100644 → 100755
Network/libpcap-1.9.0/testprogs/CMakeLists.txt
100644 → 100755
Network/libpcap-1.9.0/testprogs/can_set_rfmon_test.c
100644 → 100755
Network/libpcap-1.9.0/testprogs/findalldevstest.c
100644 → 100755
Network/libpcap-1.9.0/testprogs/reactivatetest.c
100644 → 100755
Network/libpcap-1.9.0/testprogs/threadsignaltest.c
100644 → 100755
Network/libpcap-1.9.0/testprogs/valgrindtest.c
100644 → 100755
No preview for this file type
Network/sender deleted
No preview for this file type
@@ -9,11 +9,9 @@ | @@ -9,11 +9,9 @@ | ||
9 | 9 | ||
10 | 10 | ||
11 | 11 | ||
12 | -int initialized=0; | ||
13 | -int sock_id; | ||
14 | - | ||
15 | int initializeSocketUDP(char* service) | 12 | int initializeSocketUDP(char* service) |
16 | { | 13 | { |
14 | + int sock_id; | ||
17 | struct addrinfo precisions, *resultat=NULL, *origine; // On stocke dans précisions nos besoins pour le socket, dans resultat l'adresse qui respectera les reqêtes | 15 | struct addrinfo precisions, *resultat=NULL, *origine; // On stocke dans précisions nos besoins pour le socket, dans resultat l'adresse qui respectera les reqêtes |
18 | 16 | ||
19 | memset(&precisions, 0, sizeof precisions); | 17 | memset(&precisions, 0, sizeof precisions); |
@@ -50,12 +48,10 @@ int initializeSocketUDP(char* service) | @@ -50,12 +48,10 @@ int initializeSocketUDP(char* service) | ||
50 | 48 | ||
51 | 49 | ||
52 | freeaddrinfo(origine); | 50 | freeaddrinfo(origine); |
53 | - | ||
54 | - initialized=1; | 51 | + return sock_id; |
55 | } | 52 | } |
56 | 53 | ||
57 | 54 | ||
58 | - | ||
59 | int sendUDPBroadcast(char* message, int port) | 55 | int sendUDPBroadcast(char* message, int port) |
60 | { | 56 | { |
61 | static struct sockaddr_in addrUDP; | 57 | static struct sockaddr_in addrUDP; |
@@ -65,17 +61,20 @@ int sendUDPBroadcast(char* message, int port) | @@ -65,17 +61,20 @@ int sendUDPBroadcast(char* message, int port) | ||
65 | struct in_addr tmpadd={0xffffffff}; | 61 | struct in_addr tmpadd={0xffffffff}; |
66 | addrUDP.sin_addr=tmpadd; | 62 | addrUDP.sin_addr=tmpadd; |
67 | 63 | ||
68 | - if(initialized!=1) | ||
69 | - { | ||
70 | - printf("Initialize via Broadcast\n"); | ||
71 | - char tmp_str[15]; | ||
72 | - sprintf(tmp_str, "%d", port); | ||
73 | - initializeSocketUDP( tmp_str ); | ||
74 | - } | 64 | + char tmp_str[15]; |
65 | + sprintf(tmp_str, "%d", port); | ||
66 | + int sock_id=initializeSocketUDP( tmp_str ); | ||
75 | 67 | ||
76 | - if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0) { fprintf(stderr, "Erreur sendto\n"); return(-1);} | 68 | + printf("Initialize via Broadcast %d\n", sock_id); |
69 | + | ||
70 | + if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0) { fprintf(stderr, "Erreur sendto\n"); return(-1);} | ||
71 | + | ||
72 | + close(sock_id); | ||
73 | + return 0; | ||
77 | } | 74 | } |
78 | 75 | ||
76 | + | ||
77 | + | ||
79 | int sendUDPUnicast(char* address, char* message, int port) | 78 | int sendUDPUnicast(char* address, char* message, int port) |
80 | { | 79 | { |
81 | static struct sockaddr_in addrUDP; | 80 | static struct sockaddr_in addrUDP; |
@@ -84,26 +83,25 @@ int sendUDPUnicast(char* address, char* message, int port) | @@ -84,26 +83,25 @@ int sendUDPUnicast(char* address, char* message, int port) | ||
84 | 83 | ||
85 | inet_aton(address, &(addrUDP.sin_addr)); // Converti l'écriture string de format a.b.c.d en format Internet | 84 | inet_aton(address, &(addrUDP.sin_addr)); // Converti l'écriture string de format a.b.c.d en format Internet |
86 | 85 | ||
87 | - | ||
88 | - | ||
89 | - if(initialized!=1) | ||
90 | - { | ||
91 | - printf("Initialize via Unicast\n"); | ||
92 | - char tmp_str[15]; | ||
93 | - sprintf(tmp_str, "%d", port); | ||
94 | - initializeSocketUDP( tmp_str ); | ||
95 | - } | 86 | + char tmp_str[15]; |
87 | + sprintf(tmp_str, "%d", port); | ||
88 | + int sock_id=initializeSocketUDP( tmp_str ); | ||
89 | + printf("Initialize via Unicast %d\n", sock_id); | ||
96 | 90 | ||
97 | if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto\n"); return(-1); } | 91 | if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto\n"); return(-1); } |
92 | + | ||
93 | + close(sock_id); | ||
94 | + return 0; | ||
98 | } | 95 | } |
99 | 96 | ||
100 | 97 | ||
101 | - | 98 | +/* |
102 | 99 | ||
103 | int main(void) | 100 | int main(void) |
104 | { | 101 | { |
105 | sendUDPBroadcast("Broadwesh", 2020); | 102 | sendUDPBroadcast("Broadwesh", 2020); |
106 | - sendUDPUnicast("255.255.255.255", "Uniwesh", 2020); | 103 | + sendUDPUnicast("192.168.43.174", "Uniwesh", 2020); |
107 | return(1); | 104 | return(1); |
108 | - close(sock_id); | ||
109 | } | 105 | } |
106 | + | ||
107 | +*/ |
No preview for this file type
Network/sniffer deleted
No preview for this file type
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | 7 | ||
8 | #define SZ_DEV 10 | 8 | #define SZ_DEV 10 |
9 | 9 | ||
10 | - | 10 | +/* |
11 | // Fonction lors de la detection d'un paquet | 11 | // Fonction lors de la detection d'un paquet |
12 | void arp_detect(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) | 12 | void arp_detect(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) |
13 | { | 13 | { |
@@ -18,8 +18,8 @@ void arp_detect(u_char *args, const struct pcap_pkthdr *header, const u_char *pa | @@ -18,8 +18,8 @@ void arp_detect(u_char *args, const struct pcap_pkthdr *header, const u_char *pa | ||
18 | if(num==10) { loop++; num=0; printf("10 paquets ARP ont été reçus !\n");} | 18 | if(num==10) { loop++; num=0; printf("10 paquets ARP ont été reçus !\n");} |
19 | } | 19 | } |
20 | 20 | ||
21 | - | ||
22 | - | 21 | +*/ |
22 | +/* | ||
23 | 23 | ||
24 | int main(int argc, char *argv[]) | 24 | int main(int argc, char *argv[]) |
25 | { | 25 | { |
@@ -55,10 +55,10 @@ int main(int argc, char *argv[]) | @@ -55,10 +55,10 @@ int main(int argc, char *argv[]) | ||
55 | printf("Device: %s\n", dev); | 55 | printf("Device: %s\n", dev); |
56 | 56 | ||
57 | 57 | ||
58 | - // Permet d'obtenir l'adresse ip de l'interface demandée | 58 | + // Permet d'obtenir l'adresse ip de l'interface demandée*/ |
59 | /* pcap permet de lister les interfaces et obtenir les adresses ip de ces dernières | 59 | /* pcap permet de lister les interfaces et obtenir les adresses ip de ces dernières |
60 | * On utilise la fonction pcap_findalldevs | 60 | * On utilise la fonction pcap_findalldevs |
61 | - */ | 61 | + *//* |
62 | 62 | ||
63 | pcap_if_t* interfaces; | 63 | pcap_if_t* interfaces; |
64 | if(pcap_findalldevs(&interfaces, buf_err)!=0) { printf("%s\n", buf_err); return(EXIT_FAILURE); } | 64 | if(pcap_findalldevs(&interfaces, buf_err)!=0) { printf("%s\n", buf_err); return(EXIT_FAILURE); } |
@@ -142,3 +142,5 @@ int main(int argc, char *argv[]) | @@ -142,3 +142,5 @@ int main(int argc, char *argv[]) | ||
142 | 142 | ||
143 | return(0); | 143 | return(0); |
144 | } | 144 | } |
145 | + | ||
146 | +*/ |
No preview for this file type
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
1 | +#include <sys/types.h> | ||
2 | +#include <sys/socket.h> | ||
3 | +#include <stdio.h> | ||
4 | +#include <stdlib.h> | ||
5 | +#include <unistd.h> | ||
6 | +#include <string.h> | ||
7 | +#include <netdb.h> | ||
8 | +#include <arpa/inet.h> | ||
9 | +#include "libthrd.h" | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | +int initialisationServeur(char* service) | ||
14 | +{ | ||
15 | + int sock_fd; | ||
16 | + | ||
17 | + struct addrinfo precisions, *resultat=NULL, *origine; // On stocke dans précisions nos besoins pour le socket, dans resultat l'adresse qui respectera les reqêtes | ||
18 | + | ||
19 | + memset(&precisions, 0, sizeof precisions); | ||
20 | + precisions.ai_family = AF_UNSPEC; | ||
21 | + precisions.ai_socktype = SOCK_STREAM; | ||
22 | + precisions.ai_flags = AI_PASSIVE; | ||
23 | + | ||
24 | + if(getaddrinfo(NULL, service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | ||
25 | + | ||
26 | + int n=0; | ||
27 | + | ||
28 | + for(struct addrinfo* i=origine; i!=NULL && resultat==NULL; i=i->ai_next) | ||
29 | + { | ||
30 | + printf("%d - ", n); | ||
31 | + if(i->ai_family==AF_INET) | ||
32 | + { | ||
33 | + resultat=i; | ||
34 | + printf("Test : %d", origine->ai_addrlen); | ||
35 | + } | ||
36 | + | ||
37 | + printf("\n"); | ||
38 | + n++; | ||
39 | + } | ||
40 | + | ||
41 | + struct sockaddr_in* test=(struct sockaddr_in*)(resultat->ai_addr); | ||
42 | + printf("Addr : %x\n", test->sin_addr.s_addr); | ||
43 | + if((sock_fd=socket(resultat->ai_family, resultat->ai_socktype, resultat->ai_protocol))<0) { fprintf(stderr, "Erreur socket\n"); return(-1); } | ||
44 | + | ||
45 | + int val=1; | ||
46 | + | ||
47 | + if(setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR|SO_BROADCAST, &val, sizeof(val))<0) { fprintf(stderr, "Erreur setsockopt\n"); return(-1); } | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + if(bind(sock_fd, resultat->ai_addr, resultat->ai_addrlen)) { fprintf(stderr, "Erreur bind\n"); return(-1); } | ||
52 | + | ||
53 | + if(listen(sock_fd, 20) < 0) { fprintf(stderr, "Error listen server socket\n"); return (-1); } | ||
54 | + | ||
55 | + freeaddrinfo(origine); | ||
56 | + | ||
57 | + return sock_fd; | ||
58 | +} | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | +int boucleServeur(int socket, void(* fctConnex)(int)) | ||
64 | +{ | ||
65 | + int sock_dial; | ||
66 | + | ||
67 | + printf("------- Début boucle serveur TCP -------\n\n"); | ||
68 | + | ||
69 | + while(1) | ||
70 | + { | ||
71 | + printf("-- boucle --\n"); | ||
72 | + if((sock_dial=accept(socket, NULL, NULL)) < 0){ fprintf(stderr, "Error accept dialogue\n"); return -1; } | ||
73 | + printf("Dialogue ACCEPTED\n"); | ||
74 | + | ||
75 | + lanceThread((void*)fctConnex, (void*)&sock_dial, sizeof(sock_dial)); | ||
76 | + } | ||
77 | +} | ||
78 | + |
No preview for this file type
Sioux/client
No preview for this file type
@@ -53,16 +53,25 @@ int connexionServeur(char* host, char* service) | @@ -53,16 +53,25 @@ int connexionServeur(char* host, char* service) | ||
53 | 53 | ||
54 | int main(void) | 54 | int main(void) |
55 | { | 55 | { |
56 | + | ||
57 | + char buffer[100]; | ||
56 | int sock_fd = connexionServeur("localhost", "2020"); | 58 | int sock_fd = connexionServeur("localhost", "2020"); |
57 | if(sock_fd<0) { fprintf(stderr, "Erreur connexionServeur\n"); return(-1); } | 59 | if(sock_fd<0) { fprintf(stderr, "Erreur connexionServeur\n"); return(-1); } |
58 | 60 | ||
59 | FILE* sockfd_stream = fdopen(sock_fd, "a+"); | 61 | FILE* sockfd_stream = fdopen(sock_fd, "a+"); |
60 | 62 | ||
61 | - while(1) | 63 | + printf("State sock : %p\n", sockfd_stream); |
64 | + | ||
65 | + for(int i=0; i<10; i++) | ||
62 | { | 66 | { |
63 | - fprintf(sockfd_stream, "YES !!! "); | ||
64 | - } | 67 | + fprintf(sockfd_stream, "YES !!!\n"); |
68 | + | ||
69 | + //fprintf(sockfd_stream, "EXIT\n"); | ||
65 | 70 | ||
71 | + fgets(buffer, 100, sockfd_stream); | ||
72 | + } | ||
73 | + fprintf(sockfd_stream, "EXIT\n"); | ||
74 | + fclose(sockfd_stream); | ||
66 | shutdown(sock_fd, SHUT_RDWR); | 75 | shutdown(sock_fd, SHUT_RDWR); |
67 | 76 | ||
68 | 77 |
Sioux/sioux
No preview for this file type
@@ -9,10 +9,7 @@ | @@ -9,10 +9,7 @@ | ||
9 | #include <arpa/inet.h> | 9 | #include <arpa/inet.h> |
10 | #include <pthread.h> | 10 | #include <pthread.h> |
11 | 11 | ||
12 | -#define BUFF_SIZE 100 | ||
13 | - | ||
14 | - | ||
15 | - | 12 | +#define BUFF_SIZE 1000 |
16 | 13 | ||
17 | 14 | ||
18 | int initialisationServeur(char* service) | 15 | int initialisationServeur(char* service) |
@@ -62,8 +59,10 @@ int initialisationServeur(char* service) | @@ -62,8 +59,10 @@ int initialisationServeur(char* service) | ||
62 | return sock_fd; | 59 | return sock_fd; |
63 | } | 60 | } |
64 | 61 | ||
62 | + | ||
65 | void* reponseConnexion(void* sock) | 63 | void* reponseConnexion(void* sock) |
66 | { | 64 | { |
65 | + | ||
67 | printf("Connected\n"); | 66 | printf("Connected\n"); |
68 | char buffer[BUFF_SIZE]; | 67 | char buffer[BUFF_SIZE]; |
69 | 68 | ||
@@ -81,10 +80,11 @@ void* reponseConnexion(void* sock) | @@ -81,10 +80,11 @@ void* reponseConnexion(void* sock) | ||
81 | fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); | 80 | fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); |
82 | 81 | ||
83 | } | 82 | } |
84 | - | 83 | + |
84 | + strcpy(buffer, "START"); | ||
85 | printf("Fin de la connexion\n"); | 85 | printf("Fin de la connexion\n"); |
86 | fclose(sockdial_stream); | 86 | fclose(sockdial_stream); |
87 | - | 87 | + pthread_exit(NULL); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
@@ -116,6 +116,7 @@ int boucleServeur(int socket, void(* fctConnex)(int)) | @@ -116,6 +116,7 @@ int boucleServeur(int socket, void(* fctConnex)(int)) | ||
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | + | ||
119 | void argPortParsing(int argc, char* argv[], char* port) | 120 | void argPortParsing(int argc, char* argv[], char* port) |
120 | { | 121 | { |
121 | struct option port_arg={"port", 1, NULL, 'p'}; | 122 | struct option port_arg={"port", 1, NULL, 'p'}; |
@@ -131,10 +132,11 @@ void argPortParsing(int argc, char* argv[], char* port) | @@ -131,10 +132,11 @@ void argPortParsing(int argc, char* argv[], char* port) | ||
131 | } | 132 | } |
132 | else | 133 | else |
133 | { | 134 | { |
134 | - printf("La syntaxe doit être ./sioux -p <port> ou ./sioux --port <port>"); | 135 | + printf("La syntaxe doit être de la forme ./sioux -p <port> ou ./sioux --port <port>\n\n"); |
135 | } | 136 | } |
136 | } | 137 | } |
137 | 138 | ||
139 | + | ||
138 | int main(int argc, char* argv[]) | 140 | int main(int argc, char* argv[]) |
139 | { | 141 | { |
140 | char port[10]="80"; | 142 | char port[10]="80"; |
@@ -147,6 +149,7 @@ int main(int argc, char* argv[]) | @@ -147,6 +149,7 @@ int main(int argc, char* argv[]) | ||
147 | 149 | ||
148 | 150 | ||
149 | boucleServeur(sock_fd, (void*)&reponseConnexion); | 151 | boucleServeur(sock_fd, (void*)&reponseConnexion); |
152 | + | ||
150 | return 0; | 153 | return 0; |
151 | } | 154 | } |
152 | 155 |
Sioux/sioux.o deleted
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +# | ||
2 | +# Makefile pour generer la bibliotheque de fonctions de communication | ||
3 | +# | ||
4 | + | ||
5 | +CC=gcc | ||
6 | +CFLAGS=-W -Wall -Wextra | ||
7 | +CLIBS=ar -rcs | ||
8 | +LIB=libthrd.a | ||
9 | +LDIR=../libs/ | ||
10 | +IDIR=../includes/ | ||
11 | +LDFLAGS=-lpthread | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | +all: $(LIB) | ||
16 | + | ||
17 | +$(LIB): threadSocket.o | ||
18 | + rm -f $@ | ||
19 | + $(CLIBS) $(LDIR)$@ $^ | ||
20 | + ranlib $(LDIR)$@ | ||
21 | + rm -f *.o | ||
22 | + | ||
23 | +threadSocket.o: threadSocket.c | ||
24 | + $(CC) -o $@ -c $^ $(CFLAGS) $(LDFLAGS) | ||
25 | + | ||
26 | + | ||
27 | +# | ||
28 | +# La cible de nettoyage | ||
29 | +# | ||
30 | + | ||
31 | +clean: | ||
32 | + rm -f *.o $(LDIR)$(LIB) | ||
33 | + | ||
34 | + |
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#include <stdlib.h> | ||
3 | +#include <pthread.h> | ||
4 | +#include <string.h> | ||
5 | +#include <unistd.h> | ||
6 | + | ||
7 | +#define BUFF_SIZE 1000 | ||
8 | + | ||
9 | +void* reponseConnexion(void* sock) | ||
10 | +{ | ||
11 | + | ||
12 | + printf("Connected\n"); | ||
13 | + char buffer[BUFF_SIZE]; | ||
14 | + | ||
15 | + FILE* sockdial_stream = fdopen(*((int*)(sock)), "a+"); | ||
16 | + | ||
17 | + printf("Sock : %d // Stream : %p \n", *((int*)(sock)), sockdial_stream); | ||
18 | + | ||
19 | + while(strcmp(buffer, "EXIT\n")!=0) | ||
20 | + { | ||
21 | + printf("WAIT\n"); | ||
22 | + fgets(buffer, BUFF_SIZE, sockdial_stream); | ||
23 | + | ||
24 | + printf("Le message reçu : %s", buffer); | ||
25 | + | ||
26 | + fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); | ||
27 | + | ||
28 | + } | ||
29 | + | ||
30 | + strcpy(buffer, "START"); | ||
31 | + printf("Fin de la connexion\n"); | ||
32 | + fclose(sockdial_stream); | ||
33 | + pthread_exit(NULL); | ||
34 | +} | ||
35 | + | ||
36 | + | ||
37 | +int lanceThread(void(* fonction) (void *), void* arg, int size) | ||
38 | +{ | ||
39 | + pthread_t thr_id; | ||
40 | + printf("%d \n",size); | ||
41 | + if(pthread_create(&thr_id, NULL, (void*)fonction, arg )!=0) { fprintf(stderr, "Le thread n'a pas pu être créé.\n"); return -1; } | ||
42 | + | ||
43 | + pthread_detach(thr_id); | ||
44 | + | ||
45 | + return 0; | ||
46 | +} | ||
47 | + | ||
48 | + | ||
49 | + |
Threads/threadsSocket.c deleted
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -#include <stdio.h> | ||
2 | -#include <stdlib.h> | ||
3 | -#include <pthread.h> | ||
4 | - | ||
5 | - | ||
6 | -int lanceThread(void(* fonction) (void *), void* arg, int size) | ||
7 | -{ | ||
8 | - pthread_t thr_id; | ||
9 | - | ||
10 | - if(pthread_create(&thr_id, NULL, fonction, arg)!=0) { fprintf(stderr, "Le thread n'a pas pu être créé.\n"); return -1; } | ||
11 | - | ||
12 | - pthread_detach(thr_id); | ||
13 | - | ||
14 | - | ||
15 | - | ||
16 | -} | ||
17 | - | ||
18 | -int main(void) | ||
19 | -{ | ||
20 | - | ||
21 | -} |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | + | ||
2 | +CC=gcc | ||
3 | +CFLAGS=-W -Wall -Wextra | ||
4 | +CLIBS=ar -rcs | ||
5 | +LIB=libnet.a | ||
6 | +LDIR=../libs/ | ||
7 | +LIBS=$(LDIR)libnet.a $(LDIR)libthrd.a | ||
8 | +IDIR=../includes/ | ||
9 | +LDFLAGS=-lpthread -lpcap | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | +all: test | ||
14 | + | ||
15 | +test: test.c | ||
16 | + cd ../Threads/ && make | ||
17 | + cd ../Network/ && make | ||
18 | + $(CC) -o $@ $< -I$(IDIR) $(LDIR)libnet.a $(LDIR)libthrd.a $(CFLAGS) $(LDFLAGS) | ||
19 | + rm -f *.o | ||
20 | + | ||
21 | +# | ||
22 | +# La cible de nettoyage | ||
23 | +# | ||
24 | + | ||
25 | +clean: | ||
26 | + cd ../Threads/ && make clean | ||
27 | + cd ../Network/ && make clean | ||
28 | + rm -f *.o test | ||
29 | + |
No preview for this file type
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
1 | +#include <stdlib.h> | ||
2 | +#include <stdio.h> | ||
3 | +#include <getopt.h> | ||
4 | +#include <string.h> | ||
5 | +#include "libnet.h" | ||
6 | + | ||
7 | + | ||
8 | +void argPortParsing(int argc, char* argv[], char* port) | ||
9 | +{ | ||
10 | + struct option port_arg={"port", 1, NULL, 'p'}; | ||
11 | + char opt; | ||
12 | + int longindex; | ||
13 | + | ||
14 | + while( (opt=getopt_long(argc, argv, "p:", &port_arg, &longindex)) !='p' && opt!=-1) {} | ||
15 | + | ||
16 | + if(opt=='p') | ||
17 | + { | ||
18 | + strcpy(port, optarg); | ||
19 | + printf("%s\n", optarg); | ||
20 | + } | ||
21 | + else | ||
22 | + { | ||
23 | + printf("La syntaxe doit être de la forme %s -p <port> ou %s --port <port>\n\n", argv[0], argv[0]); | ||
24 | + } | ||
25 | +} | ||
26 | + | ||
27 | + | ||
28 | +int main(int argc, char* argv[]) | ||
29 | +{ | ||
30 | + char port[10]="80"; | ||
31 | + argPortParsing(argc, argv, port); | ||
32 | + | ||
33 | + | ||
34 | + int sock_fd=initialisationServeur(port); | ||
35 | + | ||
36 | + if( sock_fd==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; } | ||
37 | + | ||
38 | + | ||
39 | + boucleServeur(sock_fd, (void*)&reponseConnexion); | ||
40 | + | ||
41 | + | ||
42 | + sendUDPBroadcast("BroadWesh", 2020); | ||
43 | + | ||
44 | + return 0; | ||
45 | +} | ||
46 | + |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +#ifndef __LIBNET_H__ | ||
2 | +#define __LIBNET_H__ | ||
3 | + | ||
4 | +int boucleServeur(int socket, void(* fctConnex)(int)); | ||
5 | +int lanceThread(void(* fonction) (void *), void* arg, int size); | ||
6 | +void* reponseConnexion(void* sock); | ||
7 | +int initialisationServeur(char* service); | ||
8 | +int initializeSocketUDP(char* service); | ||
9 | +int sendUDPBroadcast(char* message, int port); | ||
10 | +int sendUDPUnicast(char* address, char* message, int port); | ||
11 | + | ||
12 | + | ||
13 | +#endif |
No preview for this file type
No preview for this file type