Commit 0007fb16cd2bb0fdb3a67ec5640b8802fd854478
Merge branch 'master' of https://archives.plil.fr/amoreau/skam_projet
Showing
306 changed files
with
369 additions
and
148 deletions
Show diff stats
Network/.sender.c.swp deleted
No preview for this file type
... | ... | @@ -2,29 +2,44 @@ |
2 | 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 | +<<<<<<< HEAD | |
22 | + ranlib $(LDIR)$@ | |
23 | + rm -f *.o | |
24 | +======= | |
25 | + ranlib $(LDIR)$@ | |
26 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
27 | + | |
28 | + | |
29 | +tcpserver.o: tcpserver.c | |
30 | + $(CC) -o $@ -c $^ -I$(IDIR) $(CFLAGS) | |
31 | + | |
32 | +sniffer.o: sniffer.c | |
33 | + $(CC) -o $@ -c $^ $(CFLAGS) | |
34 | + | |
35 | +sender.o: sender.c | |
36 | + $(CC) -o $@ -c $^ $(CFLAGS) | |
18 | 37 | |
19 | -#clean: | |
20 | -# rm -f core *.o libnet.a | |
21 | 38 | |
22 | 39 | # |
23 | -# Les cibles pour la bibliotheque | |
40 | +# La cible de nettoyage | |
24 | 41 | # |
25 | 42 | |
26 | -#libnet.o: libnet.c libnet.h | |
43 | +clean: | |
44 | + rm -f *.o $(LDIR)$(LIB) ../bin/test | |
27 | 45 | |
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
... | ... | @@ -6,23 +6,30 @@ |
6 | 6 | #include <string.h> |
7 | 7 | #include <netdb.h> |
8 | 8 | #include <arpa/inet.h> |
9 | +#include <errno.h> | |
9 | 10 | |
10 | 11 | |
11 | - | |
12 | -int initialized=0; | |
13 | -int sock_id; | |
12 | +<<<<<<< HEAD | |
13 | +int initializeSocketUDP(char* service) | |
14 | +{ | |
15 | + int sock_id; | |
16 | + 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 | |
17 | +======= | |
14 | 18 | |
15 | 19 | int initializeSocketUDP(char* service) |
16 | 20 | { |
21 | + int sock_id; | |
17 | 22 | 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 |
23 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
18 | 24 | |
19 | 25 | memset(&precisions, 0, sizeof precisions); |
20 | 26 | precisions.ai_family = AF_UNSPEC; |
21 | 27 | precisions.ai_socktype = SOCK_DGRAM; |
22 | 28 | //precisions.ai_flags = AI_PASSIVE; |
23 | - | |
24 | - if(getaddrinfo(NULL, service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | |
25 | - | |
29 | + | |
30 | + | |
31 | + if(getaddrinfo("192.168.0.14", service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | |
32 | + | |
26 | 33 | int n=0; |
27 | 34 | |
28 | 35 | for(struct addrinfo* i=origine; i!=NULL && resultat==NULL; i=i->ai_next) |
... | ... | @@ -38,6 +45,8 @@ int initializeSocketUDP(char* service) |
38 | 45 | n++; |
39 | 46 | } |
40 | 47 | |
48 | + printf("Value : %d\n", n); | |
49 | + | |
41 | 50 | struct sockaddr_in* test=(struct sockaddr_in*)(resultat->ai_addr); |
42 | 51 | printf("Addr : %x\n", test->sin_addr.s_addr); |
43 | 52 | if((sock_id=socket(resultat->ai_family, resultat->ai_socktype, resultat->ai_protocol))<0) { fprintf(stderr, "Erreur socket\n"); return(-1); } |
... | ... | @@ -50,12 +59,10 @@ int initializeSocketUDP(char* service) |
50 | 59 | |
51 | 60 | |
52 | 61 | freeaddrinfo(origine); |
53 | - | |
54 | - initialized=1; | |
62 | + return sock_id; | |
55 | 63 | } |
56 | 64 | |
57 | 65 | |
58 | - | |
59 | 66 | int sendUDPBroadcast(char* message, int port) |
60 | 67 | { |
61 | 68 | static struct sockaddr_in addrUDP; |
... | ... | @@ -65,17 +72,27 @@ int sendUDPBroadcast(char* message, int port) |
65 | 72 | struct in_addr tmpadd={0xffffffff}; |
66 | 73 | addrUDP.sin_addr=tmpadd; |
67 | 74 | |
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 | - } | |
75 | + char tmp_str[15]; | |
76 | + sprintf(tmp_str, "%d", port); | |
77 | + int sock_id=initializeSocketUDP( tmp_str ); | |
78 | + | |
79 | + printf("Initialize via Broadcast %d\n", sock_id); | |
80 | +<<<<<<< HEAD | |
81 | + | |
82 | + int status; | |
83 | + if((status=sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP))) < 0) { fprintf(stderr, "Erreur sendto %d\n", status); return(-1);} | |
84 | + | |
85 | +======= | |
75 | 86 | |
76 | - if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0) { fprintf(stderr, "Erreur sendto\n"); return(-1);} | |
87 | + if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0) { fprintf(stderr, "Erreur sendto\n"); return(-1);} | |
88 | + | |
89 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
90 | + close(sock_id); | |
91 | + return 0; | |
77 | 92 | } |
78 | 93 | |
94 | + | |
95 | + | |
79 | 96 | int sendUDPUnicast(char* address, char* message, int port) |
80 | 97 | { |
81 | 98 | static struct sockaddr_in addrUDP; |
... | ... | @@ -84,26 +101,38 @@ int sendUDPUnicast(char* address, char* message, int port) |
84 | 101 | |
85 | 102 | inet_aton(address, &(addrUDP.sin_addr)); // Converti l'écriture string de format a.b.c.d en format Internet |
86 | 103 | |
87 | - | |
104 | + char tmp_str[15]; | |
105 | + sprintf(tmp_str, "%d", port); | |
106 | + int sock_id=initializeSocketUDP( tmp_str ); | |
107 | + printf("Initialize via Unicast %d\n", sock_id); | |
108 | +<<<<<<< HEAD | |
88 | 109 | |
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 | - } | |
110 | + if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto %d\n", errno); return(-1); } | |
111 | + | |
112 | +======= | |
96 | 113 | |
97 | 114 | if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto\n"); return(-1); } |
115 | + | |
116 | + close(sock_id); | |
117 | + return 0; | |
98 | 118 | } |
119 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
99 | 120 | |
121 | + close(sock_id); | |
122 | + return 0; | |
123 | +} | |
100 | 124 | |
125 | +<<<<<<< HEAD | |
101 | 126 | |
127 | +======= | |
128 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
129 | +/* | |
102 | 130 | |
103 | 131 | int main(void) |
104 | 132 | { |
105 | 133 | sendUDPBroadcast("Broadwesh", 2020); |
106 | - sendUDPUnicast("255.255.255.255", "Uniwesh", 2020); | |
134 | + sendUDPUnicast("192.168.43.174", "Uniwesh", 2020); | |
107 | 135 | return(1); |
108 | - close(sock_id); | |
109 | 136 | } |
137 | + | |
138 | +*/ | ... | ... |
No preview for this file type
Network/sniffer deleted
No preview for this file type
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | |
8 | 8 | #define SZ_DEV 10 |
9 | 9 | |
10 | - | |
10 | +/* | |
11 | 11 | // Fonction lors de la detection d'un paquet |
12 | 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 | 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 | 24 | int main(int argc, char *argv[]) |
25 | 25 | { |
... | ... | @@ -55,10 +55,10 @@ int main(int argc, char *argv[]) |
55 | 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 | 59 | /* pcap permet de lister les interfaces et obtenir les adresses ip de ces dernières |
60 | 60 | * On utilise la fonction pcap_findalldevs |
61 | - */ | |
61 | + *//* | |
62 | 62 | |
63 | 63 | pcap_if_t* interfaces; |
64 | 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 | 142 | |
143 | 143 | return(0); |
144 | 144 | } |
145 | + | |
146 | +*/ | ... | ... |
No preview for this file type
Sioux/sioux.c renamed to Network/tcpserver.c
... | ... | @@ -3,15 +3,10 @@ |
3 | 3 | #include <stdio.h> |
4 | 4 | #include <stdlib.h> |
5 | 5 | #include <unistd.h> |
6 | -#include <getopt.h> | |
7 | 6 | #include <string.h> |
8 | 7 | #include <netdb.h> |
9 | 8 | #include <arpa/inet.h> |
10 | -#include <pthread.h> | |
11 | - | |
12 | -#define BUFF_SIZE 100 | |
13 | - | |
14 | - | |
9 | +#include "libthrd.h" | |
15 | 10 | |
16 | 11 | |
17 | 12 | |
... | ... | @@ -62,42 +57,7 @@ int initialisationServeur(char* service) |
62 | 57 | return sock_fd; |
63 | 58 | } |
64 | 59 | |
65 | -void* reponseConnexion(void* sock) | |
66 | -{ | |
67 | - printf("Connected\n"); | |
68 | - char buffer[BUFF_SIZE]; | |
69 | - | |
70 | - FILE* sockdial_stream = fdopen(*((int*)(sock)), "a+"); | |
71 | - | |
72 | - printf("Sock : %d // Stream : %p \n", *((int*)(sock)), sockdial_stream); | |
73 | - | |
74 | - while(strcmp(buffer, "EXIT\n")!=0) | |
75 | - { | |
76 | - printf("WAIT\n"); | |
77 | - fgets(buffer, BUFF_SIZE, sockdial_stream); | |
78 | - | |
79 | - printf("Le message reçu : %s", buffer); | |
80 | - | |
81 | - fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); | |
82 | - | |
83 | - } | |
84 | - | |
85 | - printf("Fin de la connexion\n"); | |
86 | - fclose(sockdial_stream); | |
87 | - | |
88 | -} | |
89 | - | |
90 | 60 | |
91 | -int lanceThread(void(* fonction) (void *), void* arg, int size) | |
92 | -{ | |
93 | - pthread_t thr_id; | |
94 | - | |
95 | - if(pthread_create(&thr_id, NULL, (void*)fonction, arg )!=0) { fprintf(stderr, "Le thread n'a pas pu être créé.\n"); return -1; } | |
96 | - | |
97 | - pthread_detach(thr_id); | |
98 | - | |
99 | - return 0; | |
100 | -} | |
101 | 61 | |
102 | 62 | |
103 | 63 | int boucleServeur(int socket, void(* fctConnex)(int)) |
... | ... | @@ -116,38 +76,3 @@ int boucleServeur(int socket, void(* fctConnex)(int)) |
116 | 76 | } |
117 | 77 | } |
118 | 78 | |
119 | -void argPortParsing(int argc, char* argv[], char* port) | |
120 | -{ | |
121 | - struct option port_arg={"port", 1, NULL, 'p'}; | |
122 | - char opt; | |
123 | - int longindex; | |
124 | - | |
125 | - while( (opt=getopt_long(argc, argv, "p:", &port_arg, &longindex)) !='p' && opt!=-1) {} | |
126 | - | |
127 | - if(opt=='p') | |
128 | - { | |
129 | - strcpy(port, optarg); | |
130 | - printf("%s\n", optarg); | |
131 | - } | |
132 | - else | |
133 | - { | |
134 | - printf("La syntaxe doit être ./sioux -p <port> ou ./sioux --port <port>"); | |
135 | - } | |
136 | -} | |
137 | - | |
138 | -int main(int argc, char* argv[]) | |
139 | -{ | |
140 | - char port[10]="80"; | |
141 | - argPortParsing(argc, argv, port); | |
142 | - | |
143 | - | |
144 | - int sock_fd=initialisationServeur(port); | |
145 | - | |
146 | - if( sock_fd==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; } | |
147 | - | |
148 | - | |
149 | - boucleServeur(sock_fd, (void*)&reponseConnexion); | |
150 | - return 0; | |
151 | -} | |
152 | - | |
153 | - | ... | ... |
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 | 53 | |
54 | 54 | int main(void) |
55 | 55 | { |
56 | + | |
57 | + char buffer[100]; | |
56 | 58 | int sock_fd = connexionServeur("localhost", "2020"); |
57 | 59 | if(sock_fd<0) { fprintf(stderr, "Erreur connexionServeur\n"); return(-1); } |
58 | 60 | |
59 | 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 | 75 | shutdown(sock_fd, SHUT_RDWR); |
67 | 76 | |
68 | 77 | ... | ... |
Sioux/sioux
No preview for this file type
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 @@ |
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,73 @@ |
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 | +<<<<<<< HEAD | |
14 | + char buff_rec[BUFF_SIZE]; | |
15 | + char buffer[]="HTTP/1.1 200 OK\r\nServer: Serveur fait maison\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: Keep-alive\r\n\r\nPOST /Page.html HTTP/1.1\r\n\r\n"; | |
16 | + | |
17 | + | |
18 | + FILE* sockdial_stream = fdopen(*((int*)(sock)), "a+"); | |
19 | + | |
20 | + printf("Sock : %d // Stream : %p \n", *((int*)(sock)), sockdial_stream); | |
21 | + | |
22 | + fgets(buff_rec, BUFF_SIZE, sockdial_stream); | |
23 | + fprintf(sockdial_stream, "%s", buffer); | |
24 | + | |
25 | + //while(strcmp(buffer, "EXIT\n")!=0) | |
26 | + //{ | |
27 | + printf("WAIT\n"); | |
28 | + // fgets(buff_rec, BUFF_SIZE, sockdial_stream); | |
29 | + | |
30 | + printf("Le message reçu : %s", buff_rec); | |
31 | + | |
32 | + fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); | |
33 | + | |
34 | + //} | |
35 | +======= | |
36 | + char buffer[BUFF_SIZE]; | |
37 | + | |
38 | + FILE* sockdial_stream = fdopen(*((int*)(sock)), "a+"); | |
39 | + | |
40 | + printf("Sock : %d // Stream : %p \n", *((int*)(sock)), sockdial_stream); | |
41 | + | |
42 | + while(strcmp(buffer, "EXIT\n")!=0) | |
43 | + { | |
44 | + printf("WAIT\n"); | |
45 | + fgets(buffer, BUFF_SIZE, sockdial_stream); | |
46 | + | |
47 | + printf("Le message reçu : %s", buffer); | |
48 | + | |
49 | + fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); | |
50 | + | |
51 | + } | |
52 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
53 | + | |
54 | + strcpy(buffer, "START"); | |
55 | + printf("Fin de la connexion\n"); | |
56 | + fclose(sockdial_stream); | |
57 | + pthread_exit(NULL); | |
58 | +} | |
59 | + | |
60 | + | |
61 | +int lanceThread(void(* fonction) (void *), void* arg, int size) | |
62 | +{ | |
63 | + pthread_t thr_id; | |
64 | + printf("%d \n",size); | |
65 | + if(pthread_create(&thr_id, NULL, (void*)fonction, arg )!=0) { fprintf(stderr, "Le thread n'a pas pu être créé.\n"); return -1; } | |
66 | + | |
67 | + pthread_detach(thr_id); | |
68 | + | |
69 | + return 0; | |
70 | +} | |
71 | + | |
72 | + | |
73 | + | ... | ... |
Threads/threadsSocket.c deleted
... | ... | @@ -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 @@ |
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,84 @@ |
1 | +#include <stdlib.h> | |
2 | +#include <stdio.h> | |
3 | +<<<<<<< HEAD | |
4 | +#include <unistd.h> | |
5 | +#include <getopt.h> | |
6 | +#include <string.h> | |
7 | +#include <signal.h> | |
8 | +#include "libnet.h" | |
9 | + | |
10 | + | |
11 | +int sock_fd; | |
12 | + | |
13 | +struct sigaction action; | |
14 | + | |
15 | +void handler(int sig) | |
16 | +{ | |
17 | + if(sig==SIGINT) | |
18 | + { | |
19 | + printf("\nINTERRUPTION SOCKET : %d\n\n", sock_fd); | |
20 | + close(sock_fd); | |
21 | + exit(1); | |
22 | + } | |
23 | +} | |
24 | + | |
25 | + | |
26 | +======= | |
27 | +#include <getopt.h> | |
28 | +#include <string.h> | |
29 | +#include "libnet.h" | |
30 | + | |
31 | + | |
32 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
33 | +void argPortParsing(int argc, char* argv[], char* port) | |
34 | +{ | |
35 | + struct option port_arg={"port", 1, NULL, 'p'}; | |
36 | + char opt; | |
37 | + int longindex; | |
38 | + | |
39 | + while( (opt=getopt_long(argc, argv, "p:", &port_arg, &longindex)) !='p' && opt!=-1) {} | |
40 | + | |
41 | + if(opt=='p') | |
42 | + { | |
43 | + strcpy(port, optarg); | |
44 | + printf("%s\n", optarg); | |
45 | + } | |
46 | + else | |
47 | + { | |
48 | + printf("La syntaxe doit être de la forme %s -p <port> ou %s --port <port>\n\n", argv[0], argv[0]); | |
49 | + } | |
50 | +} | |
51 | + | |
52 | + | |
53 | +int main(int argc, char* argv[]) | |
54 | +{ | |
55 | + char port[10]="80"; | |
56 | + argPortParsing(argc, argv, port); | |
57 | + | |
58 | +<<<<<<< HEAD | |
59 | + action.sa_handler=&handler; | |
60 | + sigaction(SIGINT, &action, NULL); | |
61 | + | |
62 | + if( (sock_fd=initialisationServeur(port)) ==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; } | |
63 | + | |
64 | + boucleServeur(sock_fd, (void*)&reponseConnexion); | |
65 | + | |
66 | + | |
67 | + sendUDPBroadcast("BroadWesh", 2020); | |
68 | + sendUDPUnicast("192.168.0.37", "Coucou", 2020); | |
69 | +======= | |
70 | + | |
71 | + int sock_fd=initialisationServeur(port); | |
72 | + | |
73 | + if( sock_fd==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; } | |
74 | + | |
75 | + | |
76 | + boucleServeur(sock_fd, (void*)&reponseConnexion); | |
77 | + | |
78 | + | |
79 | + sendUDPBroadcast("BroadWesh", 2020); | |
80 | + | |
81 | +>>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d | |
82 | + return 0; | |
83 | +} | |
84 | + | ... | ... |
... | ... | @@ -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