131 lines
4.2 KiB
C
131 lines
4.2 KiB
C
/*
|
|
* This is the rtapanalyser library, Wi-Fi packet sniffer and analyser,
|
|
* thanks to the radiotap header of each packet.
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <pcap.h>
|
|
#include <sys/timeb.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <math.h>
|
|
|
|
|
|
/* Type booléen */
|
|
typedef enum {FALSE, TRUE} BOOL ;
|
|
|
|
|
|
/* Liste chaînée des valeurs des champs rtap */
|
|
typedef struct _ss_list
|
|
{
|
|
unsigned char header_revision ;
|
|
unsigned char header_pad ;
|
|
unsigned short header_length ;
|
|
unsigned short fhss;
|
|
unsigned long present_flags ;
|
|
unsigned long long mac_timestamp ;
|
|
unsigned char flags;
|
|
unsigned char data_rate ;
|
|
unsigned short channel ;
|
|
unsigned short channel_type ;
|
|
unsigned char antenna_signal_dbm ;
|
|
unsigned char antenna_noise_dbm ;
|
|
unsigned char antenna ;
|
|
unsigned short lock_quality ;
|
|
unsigned short tx_attenuation ;
|
|
unsigned short tx_attenuation_db ;
|
|
unsigned char tx_attenuation_dbm ;
|
|
unsigned char antenna_signal_db ;
|
|
unsigned char antenna_noise_db ;
|
|
unsigned long fcs ;
|
|
BOOL check[15] ; // Champs présents
|
|
struct _ss_list *next ;
|
|
} ss_list ;
|
|
|
|
|
|
/* Liste chaînée des adresses MAC en provenances desquelles on a capturé des paquets */
|
|
typedef struct _mac_list
|
|
{
|
|
unsigned short int nb_samples ; // Nombre d'occurrences de l'adresse MAC
|
|
unsigned char mac_addr_bytes[6] ; // Adresse MAC en octets
|
|
ss_list *samples_list ; // Liste des valeurs capturées pour cette adresse
|
|
struct _mac_list *next ; // Élément suivant de la liste
|
|
} mac_list ;
|
|
|
|
|
|
/* Position des champs fixes de l'en-tête rtap (octets) */
|
|
#define RTAP_P_HREVISION 0 // Header revision
|
|
#define RTAP_P_HPAD 1 // Header pad
|
|
#define RTAP_P_HLENGTH 2 // Header length
|
|
#define RTAP_P_PRESENTFLAGS 4 // Present flags
|
|
|
|
|
|
/* Longueur des champs de l'en-tête rtap (octets) */
|
|
#define RTAP_L_HREVISION 1 // Header revision
|
|
#define RTAP_L_HPAD 1 // Header pad
|
|
#define RTAP_L_HLENGTH 2 // Header length
|
|
#define RTAP_L_PRESENTFLAGS 4 // Present flags
|
|
#define RTAP_L_MACTS 8 // MAC timestamp
|
|
#define RTAP_L_FLAGS 1 // autre champ de flags
|
|
#define RTAP_L_RATE 1 // Data rate
|
|
#define RTAP_L_CHANNEL 2 // Channel
|
|
#define RTAP_L_CHANNELTYPE 2 // Channel type
|
|
#define RTAP_L_ANTENNASIGNALDBM 1 // SSI signal dBm
|
|
#define RTAP_L_ANTENNANOISEDBM 1 // SSI noise dBm
|
|
#define RTAP_L_ANTENNA 1 // Antenna
|
|
#define RTAP_L_FHSS 2
|
|
#define RTAP_L_LOCKQUALITY 2
|
|
#define RTAP_L_TXATTENUATION 2
|
|
#define RTAP_L_TXATTENUATIONDB 2
|
|
#define RTAP_L_TXATTENUATIONDBM 1
|
|
#define RTAP_L_ANTENNASIGNALDB 1 // en dB
|
|
#define RTAP_L_ANTENNANOISEDB 1 // en dB
|
|
#define RTAP_L_FCS 4
|
|
#define RTAP_L_EXT // Non implémenté
|
|
|
|
|
|
/* Positions pour affichage (tableau check de ss_list) */
|
|
#define RTAP_MACTS 0
|
|
#define RTAP_FLAGS 1
|
|
#define RTAP_RATE 2
|
|
#define RTAP_CHANNEL 3 // ainsi que RTAP_CHANNELTYPE
|
|
#define RTAP_FHSS 4
|
|
#define RTAP_ANTENNASIGNALDBM 5
|
|
#define RTAP_ANTENNANOISEDBM 6
|
|
#define RTAP_LOCKQUALITY 7
|
|
#define RTAP_TXATTENUATION 8
|
|
#define RTAP_TXATTENUATIONDB 9
|
|
#define RTAP_TXATTENUATIONDBM 10
|
|
#define RTAP_ANTENNA 11
|
|
#define RTAP_ANTENNASIGNALDB 12
|
|
#define RTAP_ANTENNANOISEDB 13
|
|
#define RTAP_FCS 14
|
|
|
|
|
|
/* Codes d'erreurs */
|
|
#define ERR_FILENAME 1 // Erreur dans le nom du fichier d'entrée ou de sortie
|
|
#define ERR_OPENING_FILE 2 // Erreur lors de l'ouverture du fichier d'entrée ou de sortie
|
|
#define ERR_OPENING_IFACE 3 // Erreur lors de l'ouverture de l'interface de capture
|
|
#define ERR_CAPTURE_TIME_FORMAT 4 // Format du temps de capture incorrect
|
|
|
|
|
|
/* En-têtes des fonctions */
|
|
int capture(char *capture_iface, unsigned long capture_time, mac_list **results, BOOL print_values) ;
|
|
void print_mac_list(mac_list *results, BOOL verbose) ;
|
|
void print_ss_list(ss_list *ss) ;
|
|
void free_mac_list(mac_list **results) ;
|
|
int write_mac_list_to_file(char *file, mac_list *results) ;
|
|
int read_mac_list_from_file(char *file, mac_list **results) ;
|
|
|
|
void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet, mac_list **results, BOOL print_values) ;
|
|
char* mac_bytes_to_string(unsigned char *mac_binary) ;
|
|
char frequency_to_channel(unsigned short channel) ;
|
|
unsigned int sub_date(struct timeb sup, struct timeb inf) ;
|
|
BOOL mac_cmp(unsigned char *mac1, unsigned char *mac2) ;
|