diff --git a/TODO b/TODO index c3ef990..d962d9b 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index ff9d111..b81b2fc 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -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. diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 021eed8..412e451 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -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) ; diff --git a/owlps-listener/Makefile b/owlps-listener/Makefile index 304507e..d36d77b 100644 --- a/owlps-listener/Makefile +++ b/owlps-listener/Makefile @@ -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) diff --git a/owlps-listener/owlps-listener.h b/owlps-listener/owlps-listener.h index fd8c1f9..48ad4a4 100644 --- a/owlps-listener/owlps-listener.h +++ b/owlps-listener/owlps-listener.h @@ -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, diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index dd9f4e4..a08182e 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -22,6 +22,7 @@ #ifdef USE_PTHREAD # include +# include #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