[lib] Move owl_iface_mode_monitor() in Listener

Only owlps-listener uses owl_iface_mode_monitor(), so we don't need to
keep it in libowlps.
This commit is contained in:
Matteo Cypriani 2011-06-23 13:30:57 +02:00
parent 7dade1c36b
commit 00d89efd40
6 changed files with 38 additions and 37 deletions

1
TODO
View File

@ -24,7 +24,6 @@
° owl_timestamp_is_null()
° owl_iface_channel_hop()
° owl_iface_set_channel() (except by owl_iface_channel_hop())
- Move owl_iface_mode_monitor() in owlps-listenerd.c.
* Aggregator

View File

@ -376,39 +376,6 @@ int owl_create_udp_listening_socket(const uint_fast16_t port)
}
/*
* Switches the IEEE 802.11 interface 'iface' to Monitor mode.
*/
int owl_iface_mode_monitor(const char *const iface)
{
struct iwreq wrq ;
int sockfd = iw_sockets_open() ;
strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ;
if (ioctl(sockfd, SIOCGIWMODE, &wrq) == -1) // Get current mode
{
perror("Error reading interface mode") ;
return ERR_READING_MODE ;
}
// If interface is not yet in Monitor mode
if (wrq.u.mode != IW_MODE_MONITOR)
{
wrq.u.mode = IW_MODE_MONITOR ;
if (ioctl(sockfd, SIOCSIWMODE, &wrq) == -1) // Set up Monitor mode
{
perror("Error setting up Monitor mode") ;
return ERR_SETTING_MODE ;
}
}
close(sockfd) ;
return 0 ;
}
/*
* Sets the IEEE 802.11 channel of the interface 'iface'.
* 'channel' must be an integer between 1 and 14.

View File

@ -290,7 +290,6 @@ int owl_create_udp_trx_socket(const char *const server_address,
struct sockaddr_in *const server_description,
struct sockaddr_in *const client_description) ;
int owl_create_udp_listening_socket(const uint_fast16_t port) ;
int owl_iface_mode_monitor(const char *const iface) ;
int owl_iface_set_channel(const char *const iface,
const uint_fast8_t channel) ;
int owl_iface_channel_hop(const char *const iface) ;

View File

@ -36,7 +36,7 @@ OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" \
-D USE_CONFIG_FILE -lconfuse -D USE_PTHREAD -pthread
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client \
-lpcap
-lpcap -liw
LDFLAGS = $(LIBS) $(OWLPSFLAGS)

View File

@ -74,6 +74,7 @@ void print_configuration(void) ;
#ifdef USE_PTHREAD
void* keep_mode_monitor(void *iface) ;
int iface_mode_monitor(const char *const iface) ;
#endif // USE_PTHREAD
int capture(void) ;
void read_packet(u_char *args, const struct pcap_pkthdr *header,

View File

@ -22,6 +22,7 @@
#ifdef USE_PTHREAD
# include <pthread.h>
# include <iwlib.h>
#endif // USE_PTHREAD
// Used by get_mac_addr():
@ -668,12 +669,46 @@ void* keep_mode_monitor(void *iface)
while (owl_run)
{
// Switch the interface to monitor mode:
owl_iface_mode_monitor((char*) iface) ;
iface_mode_monitor((char*) iface) ;
sleep(1) ; // Wait for 1 second
}
pthread_exit(NULL) ;
}
/*
* Switches the IEEE 802.11 interface 'iface' to Monitor mode.
*/
int iface_mode_monitor(const char *const iface)
{
struct iwreq wrq ;
int sockfd = iw_sockets_open() ;
strncpy((&wrq)->ifr_name, iface, IFNAMSIZ) ;
if (ioctl(sockfd, SIOCGIWMODE, &wrq) == -1) // Get current mode
{
perror("Error reading interface mode") ;
return ERR_READING_MODE ;
}
// If interface is not yet in Monitor mode
if (wrq.u.mode != IW_MODE_MONITOR)
{
wrq.u.mode = IW_MODE_MONITOR ;
if (ioctl(sockfd, SIOCSIWMODE, &wrq) == -1) // Set up Monitor mode
{
perror("Error setting up Monitor mode") ;
return ERR_SETTING_MODE ;
}
}
close(sockfd) ;
return 0 ;
}
#endif // USE_PTHREAD