owlps/infrastructure-centred/owlps-listener/owlps-listener.h

132 lines
4.5 KiB
C
Raw Normal View History

/*
* This file is part of the rtap localisation project.
*/
#ifndef _OWLPS_LISTENER_H_
#define _OWLPS_LISTENER_H_
/* Compilation-time options: to activate, uncomment or compile with -D
* option.
*/
//#define USE_CONFIG_FILE // Use libconfuse to read a config file
//#define USE_PTHREAD // POSIX threads available?
#define DEBUG
#include "../../libowlps/owlps.h"
#include "../libowlps-client/owlps-client.h"
#include <pcap.h>
#ifdef USE_CONFIG_FILE
# include <confuse.h>
#endif // USE_CONFIG_FILE
#ifdef USE_PTHREAD
# include <pthread.h>
#endif // USE_PTHREAD
#include <endian.h>
/* <endian.h> defines le32toh only in glibc >= 2.9. If we use an older
* version of glibc, or another libc (e.g. uClibc), we must define it
* manually.
*/
#ifndef le32toh
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define le32toh(x) (x)
# else // __BYTE_ORDER == __LITTLE_ENDIAN
# include <byteswap.h>
# define le32toh(x) bswap_32(x)
# endif // __BYTE_ORDER == __LITTLE_ENDIAN
#endif // le32toh
// Used by get_mac_addr():
#include <netinet/if_ether.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
/* Arguments & program configuration */
2010-07-13 14:42:33 +02:00
#define OPTIONS "d:f:hkl:m:p:qr:vw:" // getopt string
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf"
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
/* Error codes */
#define ERR_OPENING_IFACE 2 // Error when opening capture interface
#define ERR_BAD_USAGE 3 // Bad program call
#define ERR_PARSING_CONFIG_FILE 4 // Error reading the configuration file
/* Function headers */
2010-07-13 15:09:07 +02:00
void initialise_configuration(int argc, char **argv) ;
void parse_config_file(int argc, char **argv) ;
void parse_command_line(int argc, char **argv) ;
void check_configuration(void) ;
#ifdef DEBUG
void print_configuration(void) ;
#endif // DEBUG
#ifdef USE_PTHREAD
void* keep_mode_monitor(char *iface) ;
#endif // USE_PTHREAD
int capture(void) ;
void read_packet(u_char *args, const struct pcap_pkthdr *header,
const u_char *packet) ;
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
2010-07-13 15:09:07 +02:00
void print_usage(void) ;
/* Macros to allow switching option handling with the libconfuse
* structure and a home-made structure (if program is not compiled
* with libconfuse support).
*/
/* libconfuse macros */
#ifdef USE_CONFIG_FILE
#define SET_MODE(MODE) (cfg_setint(cfg, "mode", (MODE)))
#define GET_MODE() (cfg_getint(cfg, "mode"))
#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"))
#define SET_LISTENING_PORT(PORT) (cfg_setint(cfg, "listening_port", (PORT)))
#define GET_LISTENING_PORT() (cfg_getint(cfg, "listening_port"))
#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"))
#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"))
/* Home-made structure macros */
#else // USE_CONFIG_FILE
#define SET_MODE(MODE) (options.mode = (MODE))
#define GET_MODE() (options.mode)
#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)
#define SET_LISTENING_PORT(PORT) (options.listening_port = (PORT))
#define GET_LISTENING_PORT() (options.listening_port)
#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)
#define SET_VERBOSE() (options.verbose = TRUE)
#define UNSET_VERBOSE() (options.verbose = FALSE)
#define GET_VERBOSE() (options.verbose)
#endif // USE_CONFIG_FILE
#endif // _OWLPS_LISTENER_H_