Thread monitor dans apd
A code/loc-mobile/TODO M code/loc-bts/ap/apd.c : Thread permettant de passer en mode Monitor lorsque l'interface Wi-Fi n'y est pas. M code/librtaputil/librtaputil.c : Vérification du mode avant le passage en Monitor dans iface_mode_monitor(). git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@22 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
parent
2f245fc09a
commit
fbe2cdec78
|
@ -186,19 +186,29 @@ int create_udp_listening_socket(int port)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Bascule l'interface Wi-Fi "iface" en mode Monitor */
|
/* Bascule l'interface Wi-Fi "iface" en mode Monitor si elle n'y est pas déjà */
|
||||||
int iface_mode_monitor(char *iface)
|
int iface_mode_monitor(char *iface)
|
||||||
{
|
{
|
||||||
struct iwreq wrq ;
|
struct iwreq wrq ;
|
||||||
int sockfd = iw_sockets_open() ;
|
int sockfd = iw_sockets_open() ;
|
||||||
|
|
||||||
strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ;
|
|
||||||
wrq.u.mode = IW_MODE_MONITOR ;
|
|
||||||
|
|
||||||
if (ioctl(sockfd, SIOCSIWMODE, &wrq) == -1)
|
strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ;
|
||||||
|
|
||||||
|
if (ioctl(sockfd, SIOCGIWMODE, &wrq) == -1) // Récupération du mode actuel
|
||||||
{
|
{
|
||||||
perror("Erreur lors du passage en mode Monitor ") ;
|
perror("Erreur lors de la lecture du mode ") ;
|
||||||
return ERR_SETTING_MONITOR_MODE ;
|
return ERR_READING_MODE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wrq.u.mode != IW_MODE_MONITOR) // Si on n'est pas déjà en mode Monitor
|
||||||
|
{
|
||||||
|
wrq.u.mode = IW_MODE_MONITOR ;
|
||||||
|
if (ioctl(sockfd, SIOCSIWMODE, &wrq) == -1) // on y passe.
|
||||||
|
{
|
||||||
|
perror("Erreur lors du passage en mode Monitor ") ;
|
||||||
|
return ERR_SETTING_MONITOR_MODE ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -153,7 +155,8 @@ BOOL run ;
|
||||||
#define ERR_SETTING_MONITOR_MODE 101
|
#define ERR_SETTING_MONITOR_MODE 101
|
||||||
#define ERR_SETTING_CHANNEL 102
|
#define ERR_SETTING_CHANNEL 102
|
||||||
#define ERR_READING_CHANNEL 103
|
#define ERR_READING_CHANNEL 103
|
||||||
#define ERR_BAD_SIGNAL 104
|
#define ERR_READING_MODE 104
|
||||||
|
#define ERR_BAD_SIGNAL 111
|
||||||
|
|
||||||
/* En-têtes de fonctions */
|
/* En-têtes de fonctions */
|
||||||
// Fonctions utilitaires
|
// Fonctions utilitaires
|
||||||
|
|
|
@ -21,7 +21,7 @@ CFLAGS=-O2 -W -Wall -Wstrict-prototypes -O -I.
|
||||||
DEPFLAGS=-MMD
|
DEPFLAGS=-MMD
|
||||||
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
|
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
|
||||||
PICFLAG=-fPIC
|
PICFLAG=-fPIC
|
||||||
LIBS=-lm -lpcap ../../librtaputil/librtaputil.so.1.0
|
LIBS=-lm -lpcap -lpthread ../../librtaputil/librtaputil.so.1.0
|
||||||
|
|
||||||
|
|
||||||
## Cibles de compilation standard ##
|
## Cibles de compilation standard ##
|
||||||
|
|
|
@ -27,6 +27,7 @@ enum {ARGV_AGGREG_IP=1, ARGV_RTAP_IFACE, ARGV_WIFI_IFACE} ;
|
||||||
|
|
||||||
|
|
||||||
/* En-têtes des fonctions */
|
/* En-têtes des fonctions */
|
||||||
|
void* keep_mode_monitor(char *iface) ;
|
||||||
int capture(char *capture_iface, char *aggregated_ip, BOOL print_values) ;
|
int capture(char *capture_iface, char *aggregated_ip, BOOL print_values) ;
|
||||||
void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet, int sockfd, struct sockaddr_in *server, BOOL print_values) ;
|
void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet, int sockfd, struct sockaddr_in *server, BOOL print_values) ;
|
||||||
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
|
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
|
||||||
|
|
|
@ -15,6 +15,7 @@ int main(int argc, char *argv[])
|
||||||
struct sigaction action ; // Structure de mise en place des gestionnaires de signaux
|
struct sigaction action ; // Structure de mise en place des gestionnaires de signaux
|
||||||
char *mac_string ; // MAC de l'AP sous forme de chaîne
|
char *mac_string ; // MAC de l'AP sous forme de chaîne
|
||||||
int ret ; // Code de retour du programme
|
int ret ; // Code de retour du programme
|
||||||
|
pthread_t thread ; // Thread pour le repassage en mode monitor
|
||||||
|
|
||||||
if (argc != ARGC)
|
if (argc != ARGC)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +32,9 @@ int main(int argc, char *argv[])
|
||||||
action.sa_handler = sigterm_handler ;
|
action.sa_handler = sigterm_handler ;
|
||||||
sigaction(SIGTERM, &action, NULL) ;
|
sigaction(SIGTERM, &action, NULL) ;
|
||||||
|
|
||||||
|
/* Création du thread */
|
||||||
|
pthread_create(&thread, NULL, (void *) &keep_mode_monitor, argv[ARGV_WIFI_IFACE]) ;
|
||||||
|
|
||||||
get_mac_addr(argv[ARGV_WIFI_IFACE], mac) ;
|
get_mac_addr(argv[ARGV_WIFI_IFACE], mac) ;
|
||||||
mac_string = mac_bytes_to_string(mac) ;
|
mac_string = mac_bytes_to_string(mac) ;
|
||||||
printf("Ma mac est : %s\n", mac_string) ;
|
printf("Ma mac est : %s\n", mac_string) ;
|
||||||
|
@ -44,6 +48,20 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Fonction du thread, qui surveille la liste et envoie les infos au serveur de localisation au bout du timeout */
|
||||||
|
void* keep_mode_monitor(char *iface)
|
||||||
|
{
|
||||||
|
while (run)
|
||||||
|
{
|
||||||
|
iface_mode_monitor(iface) ; // Passage de l'interface en mode Monitor.
|
||||||
|
sleep(5) ; // Pause de 5 secondes.
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Capture des paquets en utilisant l'interface "capture_iface".
|
/* Capture des paquets en utilisant l'interface "capture_iface".
|
||||||
* Les données capturées sont envoyées au serveur d'aggrégation dont l'IP est "aggregated_ip".
|
* Les données capturées sont envoyées au serveur d'aggrégation dont l'IP est "aggregated_ip".
|
||||||
|
@ -285,7 +303,7 @@ void get_mac_addr(char *eth, unsigned char mac_bytes[6])
|
||||||
|
|
||||||
sockfd = socket(AF_INET, SOCK_DGRAM, 0) ;
|
sockfd = socket(AF_INET, SOCK_DGRAM, 0) ;
|
||||||
if(sockfd < 0)
|
if(sockfd < 0)
|
||||||
printf("Can't open socket\n") ;
|
perror("Impossible d'ouvrir la socket pour récupérer l'adresse MAC ") ;
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, eth, IFNAMSIZ) ;
|
strncpy(ifr.ifr_name, eth, IFNAMSIZ) ;
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "../../librtaputil/rtaputil.h"
|
#include "../../librtaputil/rtaputil.h"
|
||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define AGGREGATE_TIMEOUT 500 // Timeout d'agrégation (en mili-secondes)
|
#define AGGREGATE_TIMEOUT 500 // Timeout d'agrégation (en mili-secondes)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
* Mettre l'interface Wi-Fi en paramètre du programme mobile.
|
Loading…
Reference in New Issue