Commit 32c9271a85f628239d9d70a22d7446de5d525b39
1 parent
685f1984
modif
Showing
302 changed files
with
272 additions
and
173 deletions
Show diff stats
Network/.sender.c.swp deleted
No preview for this file type
... | ... | @@ -2,29 +2,40 @@ |
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 | + ranlib $(LDIR)$@ | |
22 | + rm -f *.o | |
23 | + | |
24 | + | |
25 | +tcpserver.o: tcpserver.c | |
26 | + $(CC) -o $@ -c $^ -I$(IDIR) $(CFLAGS) | |
27 | + | |
28 | +sniffer.o: sniffer.c | |
29 | + $(CC) -o $@ -c $^ $(CFLAGS) | |
30 | + | |
31 | +sender.o: sender.c | |
32 | + $(CC) -o $@ -c $^ $(CFLAGS) | |
18 | 33 | |
19 | -#clean: | |
20 | -# rm -f core *.o libnet.a | |
21 | 34 | |
22 | 35 | # |
23 | -# Les cibles pour la bibliotheque | |
36 | +# La cible de nettoyage | |
24 | 37 | # |
25 | 38 | |
26 | -#libnet.o: libnet.c libnet.h | |
39 | +clean: | |
40 | + rm -f *.o $(LDIR)$(LIB) ../bin/test | |
27 | 41 | |
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,22 @@ |
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; | |
14 | - | |
15 | 12 | int initializeSocketUDP(char* service) |
16 | 13 | { |
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 | |
14 | + int sock_id; | |
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 | |
18 | 16 | |
19 | 17 | memset(&precisions, 0, sizeof precisions); |
20 | 18 | precisions.ai_family = AF_UNSPEC; |
21 | 19 | precisions.ai_socktype = SOCK_DGRAM; |
22 | 20 | //precisions.ai_flags = AI_PASSIVE; |
23 | - | |
24 | - if(getaddrinfo(NULL, service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | |
25 | - | |
21 | + | |
22 | + | |
23 | + if(getaddrinfo("192.168.0.14", service, &precisions, &origine)<0) { fprintf(stderr, "Erreur getaddrinfo\n"); return(-1); } | |
24 | + | |
26 | 25 | int n=0; |
27 | 26 | |
28 | 27 | for(struct addrinfo* i=origine; i!=NULL && resultat==NULL; i=i->ai_next) |
... | ... | @@ -38,6 +37,8 @@ int initializeSocketUDP(char* service) |
38 | 37 | n++; |
39 | 38 | } |
40 | 39 | |
40 | + printf("Value : %d\n", n); | |
41 | + | |
41 | 42 | struct sockaddr_in* test=(struct sockaddr_in*)(resultat->ai_addr); |
42 | 43 | printf("Addr : %x\n", test->sin_addr.s_addr); |
43 | 44 | if((sock_id=socket(resultat->ai_family, resultat->ai_socktype, resultat->ai_protocol))<0) { fprintf(stderr, "Erreur socket\n"); return(-1); } |
... | ... | @@ -50,12 +51,10 @@ int initializeSocketUDP(char* service) |
50 | 51 | |
51 | 52 | |
52 | 53 | freeaddrinfo(origine); |
53 | - | |
54 | - initialized=1; | |
54 | + return sock_id; | |
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | - | |
59 | 58 | int sendUDPBroadcast(char* message, int port) |
60 | 59 | { |
61 | 60 | static struct sockaddr_in addrUDP; |
... | ... | @@ -65,17 +64,21 @@ int sendUDPBroadcast(char* message, int port) |
65 | 64 | struct in_addr tmpadd={0xffffffff}; |
66 | 65 | addrUDP.sin_addr=tmpadd; |
67 | 66 | |
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 | - } | |
67 | + char tmp_str[15]; | |
68 | + sprintf(tmp_str, "%d", port); | |
69 | + int sock_id=initializeSocketUDP( tmp_str ); | |
75 | 70 | |
76 | - if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0) { fprintf(stderr, "Erreur sendto\n"); return(-1);} | |
71 | + printf("Initialize via Broadcast %d\n", sock_id); | |
72 | + | |
73 | + int status; | |
74 | + if((status=sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP))) < 0) { fprintf(stderr, "Erreur sendto %d\n", status); return(-1);} | |
75 | + | |
76 | + close(sock_id); | |
77 | + return 0; | |
77 | 78 | } |
78 | 79 | |
80 | + | |
81 | + | |
79 | 82 | int sendUDPUnicast(char* address, char* message, int port) |
80 | 83 | { |
81 | 84 | static struct sockaddr_in addrUDP; |
... | ... | @@ -84,26 +87,26 @@ int sendUDPUnicast(char* address, char* message, int port) |
84 | 87 | |
85 | 88 | inet_aton(address, &(addrUDP.sin_addr)); // Converti l'écriture string de format a.b.c.d en format Internet |
86 | 89 | |
87 | - | |
90 | + char tmp_str[15]; | |
91 | + sprintf(tmp_str, "%d", port); | |
92 | + int sock_id=initializeSocketUDP( tmp_str ); | |
93 | + printf("Initialize via Unicast %d\n", sock_id); | |
88 | 94 | |
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 | - } | |
95 | + if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto %d\n", errno); return(-1); } | |
96 | 96 | |
97 | - if(sendto(sock_id, message, sizeof(message), 0, (struct sockaddr*) &addrUDP, sizeof(addrUDP)) < 0 ) { fprintf(stderr, "Error sendto\n"); return(-1); } | |
98 | -} | |
99 | 97 | |
98 | + close(sock_id); | |
99 | + return 0; | |
100 | +} | |
100 | 101 | |
101 | 102 | |
103 | +/* | |
102 | 104 | |
103 | 105 | int main(void) |
104 | 106 | { |
105 | 107 | sendUDPBroadcast("Broadwesh", 2020); |
106 | - sendUDPUnicast("255.255.255.255", "Uniwesh", 2020); | |
108 | + sendUDPUnicast("192.168.43.174", "Uniwesh", 2020); | |
107 | 109 | return(1); |
108 | - close(sock_id); | |
109 | 110 | } |
111 | + | |
112 | +*/ | ... | ... |
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 | +*/ | ... | ... |
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 | - | ... | ... |
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 deleted
No preview for this file type
Sioux/sioux.o deleted
No preview for this file type
Sioux/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 | -} |
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,51 @@ |
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[]= "HTTP/1.1 200 OK\nServer: Serveur fait maison\nContent-Type: text/html; charset=UTF-8\nConnection: Keep-alive\n\n<h1>Hey !</h1>"; | |
14 | + | |
15 | + FILE* sockdial_stream = fdopen(*((int*)(sock)), "a+"); | |
16 | + | |
17 | + printf("Sock : %d // Stream : %p \n", *((int*)(sock)), sockdial_stream); | |
18 | + | |
19 | + fprintf(sockdial_stream, "%s", buffer); | |
20 | + | |
21 | + while(strcmp(buffer, "EXIT\n")!=0) | |
22 | + { | |
23 | + printf("WAIT\n"); | |
24 | + fgets(buffer, BUFF_SIZE, sockdial_stream); | |
25 | + | |
26 | + printf("Le message reçu : %s", buffer); | |
27 | + | |
28 | + fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); | |
29 | + | |
30 | + } | |
31 | + | |
32 | + strcpy(buffer, "START"); | |
33 | + printf("Fin de la connexion\n"); | |
34 | + fclose(sockdial_stream); | |
35 | + pthread_exit(NULL); | |
36 | +} | |
37 | + | |
38 | + | |
39 | +int lanceThread(void(* fonction) (void *), void* arg, int size) | |
40 | +{ | |
41 | + pthread_t thr_id; | |
42 | + printf("%d \n",size); | |
43 | + if(pthread_create(&thr_id, NULL, (void*)fonction, arg )!=0) { fprintf(stderr, "Le thread n'a pas pu être créé.\n"); return -1; } | |
44 | + | |
45 | + pthread_detach(thr_id); | |
46 | + | |
47 | + return 0; | |
48 | +} | |
49 | + | |
50 | + | |
51 | + | ... | ... |
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,45 @@ |
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; | |
35 | + | |
36 | + if( (sock_fd=initialisationServeur(port)) ==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; } | |
37 | + | |
38 | + boucleServeur(sock_fd, (void*)&reponseConnexion); | |
39 | + | |
40 | + | |
41 | + sendUDPBroadcast("BroadWesh", 2020); | |
42 | + sendUDPUnicast("192.168.0.37", "Coucou", 2020); | |
43 | + return 0; | |
44 | +} | |
45 | + | ... | ... |
... | ... | @@ -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