2008-02-14 08:54:51 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the rtap localisation project.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 16:04:49 +01:00
|
|
|
#ifndef _AP_H
|
|
|
|
#define _AP_H
|
|
|
|
|
2009-07-02 09:42:15 +02:00
|
|
|
// Compilation-time options (comment-out to unactivate)
|
|
|
|
#define USE_CONFIG_FILE // Use libconfuse to read a config file
|
|
|
|
#define USE_PTHREAD // POSIX threads available?
|
2009-07-02 11:10:22 +02:00
|
|
|
//#define PLATFORM_ATHEROS // Will we compile to an Atheros platform?
|
2009-07-02 09:42:15 +02:00
|
|
|
|
2009-09-03 11:09:48 +02:00
|
|
|
#define DEBUG
|
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
|
2008-10-06 17:27:33 +02:00
|
|
|
#include "../../libowlps/owlps.h"
|
2008-02-14 08:54:51 +01:00
|
|
|
#include <pcap.h>
|
2009-07-02 09:42:15 +02:00
|
|
|
|
|
|
|
#ifdef USE_CONFIG_FILE
|
2009-04-15 14:15:49 +02:00
|
|
|
#include <confuse.h>
|
2009-07-02 09:42:15 +02:00
|
|
|
#endif // USE_CONFIG_FILE
|
|
|
|
|
|
|
|
#ifdef USE_PTHREAD
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif // USE_PTHREAD
|
2008-02-14 08:54:51 +01:00
|
|
|
|
|
|
|
// Pour la fonction get_mac_addr() :
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* Codes d'erreurs */
|
|
|
|
#define ERR_CREATING_SOCKET 1 // Erreur lors de la création de la socket d'envoi
|
|
|
|
#define ERR_OPENING_IFACE 2 // Erreur lors de l'ouverture de l'interface de capture
|
|
|
|
#define ERR_BAD_USAGE 3 // Mauvais appel au programme
|
2009-04-15 14:15:49 +02:00
|
|
|
#define ERR_PARSING_CONFIG_FILE 4 // Erreur lors de la lecture du fichier de configuration
|
2008-02-14 08:54:51 +01:00
|
|
|
|
2009-07-02 09:42:15 +02:00
|
|
|
|
2009-04-15 14:15:49 +02:00
|
|
|
/* Arguments & configuration du programme */
|
2009-09-03 11:09:48 +02:00
|
|
|
#define OPTIONS "d:f:kl:m:p:qr:vw:" // Chaîne pour getopt
|
2009-04-15 14:15:49 +02:00
|
|
|
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf"
|
2009-08-04 12:02:52 +02:00
|
|
|
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
|
2009-07-02 09:42:15 +02:00
|
|
|
|
2009-09-03 11:09:48 +02:00
|
|
|
|
2008-02-14 08:54:51 +01:00
|
|
|
/* En-têtes des fonctions */
|
2009-07-02 09:42:15 +02:00
|
|
|
#ifdef USE_PTHREAD
|
2008-02-27 17:37:08 +01:00
|
|
|
void* keep_mode_monitor(char *iface) ;
|
2009-07-02 09:42:15 +02:00
|
|
|
#endif // USE_PTHREAD
|
2009-08-04 12:02:52 +02:00
|
|
|
int capture(void) ;
|
|
|
|
void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet, int sockfd, struct sockaddr_in *server) ;
|
2008-02-14 08:54:51 +01:00
|
|
|
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
|
|
|
|
void print_usage(char *prog) ;
|
2008-02-22 16:04:49 +01:00
|
|
|
|
|
|
|
|
2009-07-02 09:42:15 +02:00
|
|
|
/* Macros permettant de jongler entre la gestion des options via la
|
|
|
|
* structure offerte par libconfuse, et une structure maison si cette
|
|
|
|
* dernière est désactivée.
|
|
|
|
*/
|
|
|
|
/* Macros utilisant libconfuse : */
|
|
|
|
#ifdef USE_CONFIG_FILE
|
2009-08-04 12:02:52 +02:00
|
|
|
#define SET_MODE(MODE) (cfg_setint(cfg, "mode", (MODE)))
|
|
|
|
#define GET_MODE() (cfg_getint(cfg, "mode"))
|
2009-07-02 09:42:15 +02:00
|
|
|
#define SET_AGGREGATION_IP(IP) (cfg_setstr(cfg, "aggregation_ip", (IP)))
|
|
|
|
#define GET_AGGREGATION_IP() (cfg_getstr(cfg, "aggregation_ip"))
|
|
|
|
#ifdef USE_PTHREAD
|
|
|
|
#define SET_KEEP_MONITOR() (cfg_setbool(cfg, "keep_monitor", cfg_true))
|
|
|
|
#define GET_KEEP_MONITOR() (cfg_getbool(cfg, "keep_monitor"))
|
|
|
|
#endif // USE_PTHREAD
|
|
|
|
#define SET_AGGREGATION_PORT(PORT) (cfg_setint(cfg, "aggregation_port", (PORT)))
|
|
|
|
#define GET_AGGREGATION_PORT() (cfg_getint(cfg, "aggregation_port"))
|
2009-07-02 13:12:51 +02:00
|
|
|
#define SET_LISTENING_PORT(PORT) (cfg_setint(cfg, "listening_port", (PORT)))
|
|
|
|
#define GET_LISTENING_PORT() (cfg_getint(cfg, "listening_port"))
|
2009-07-02 09:42:15 +02:00
|
|
|
#define SET_RTAP_IFACE(IFACE) (cfg_setstr(cfg, "rtap_iface", (IFACE)))
|
|
|
|
#define GET_RTAP_IFACE() (cfg_getstr(cfg, "rtap_iface"))
|
|
|
|
#define SET_WIFI_IFACE(IFACE) (cfg_setstr(cfg, "wifi_iface", (IFACE)))
|
|
|
|
#define GET_WIFI_IFACE() (cfg_getstr(cfg, "wifi_iface"))
|
2009-08-04 12:02:52 +02:00
|
|
|
#define SET_VERBOSE() (cfg_setbool(cfg, "verbose", cfg_true))
|
|
|
|
#define UNSET_VERBOSE() (cfg_setbool(cfg, "verbose", cfg_false))
|
|
|
|
#define GET_VERBOSE() (cfg_getbool(cfg, "verbose"))
|
2009-07-02 09:42:15 +02:00
|
|
|
|
|
|
|
/* Macros utilisant la structure maison : */
|
|
|
|
#else // USE_CONFIG_FILE
|
2009-08-04 12:02:52 +02:00
|
|
|
#define SET_MODE(MODE) (options.mode = (MODE))
|
|
|
|
#define GET_MODE() (options.mode)
|
2009-07-02 09:42:15 +02:00
|
|
|
#define SET_AGGREGATION_IP(IP) (strncpy(options.aggregation_ip, (IP), 16))
|
|
|
|
#define GET_AGGREGATION_IP() (options.aggregation_ip)
|
|
|
|
#ifdef USE_PTHREAD
|
|
|
|
#define SET_KEEP_MONITOR() (options.keep_monitor = TRUE)
|
|
|
|
#define GET_KEEP_MONITOR() (options.keep_monitor)
|
|
|
|
#endif // USE_PTHREAD
|
|
|
|
#define SET_AGGREGATION_PORT(PORT) (options.aggregation_port = (PORT))
|
|
|
|
#define GET_AGGREGATION_PORT() (options.aggregation_port)
|
2009-07-02 13:12:51 +02:00
|
|
|
#define SET_LISTENING_PORT(PORT) (options.listening_port = (PORT))
|
|
|
|
#define GET_LISTENING_PORT() (options.listening_port)
|
2009-07-02 09:42:15 +02:00
|
|
|
#define SET_RTAP_IFACE(IFACE) (strncpy(options.rtap_iface, (IFACE), IFNAMSIZ+1))
|
|
|
|
#define GET_RTAP_IFACE() (options.rtap_iface)
|
|
|
|
#define SET_WIFI_IFACE(IFACE) (strncpy(options.wifi_iface, (IFACE), IFNAMSIZ+1))
|
|
|
|
#define GET_WIFI_IFACE() (options.wifi_iface)
|
2009-08-04 12:02:52 +02:00
|
|
|
#define SET_VERBOSE() (options.verbose = TRUE)
|
|
|
|
#define UNSET_VERBOSE() (options.verbose = FALSE)
|
|
|
|
#define GET_VERBOSE() (options.verbose)
|
2009-07-02 09:42:15 +02:00
|
|
|
#endif // USE_CONFIG_FILE
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _AP_H
|