[Listener] Fix the "don't want to quit" bug

In capture(), the pcap_loop() call was blocking, so the program did not
quit if no packet came on rtap_iface. This is now fixed by a call to
pcap_breakloop() in the signal handlers.
This commit is contained in:
Matteo Cypriani 2011-03-24 14:57:33 +01:00
parent ccb963cea8
commit 5f9de6e1dc
3 changed files with 28 additions and 13 deletions

5
TODO
View File

@ -35,11 +35,6 @@
- read_packet(): use ieee80211_header_size for all implicit packets
Currently the size is corrected only for data packets.
- Fix the "don't want to quit" bug
Sometimes owlps-listener refuses to quit on SIGTERM. This is
because of the blocking call of pcap_loop() in capture(): something
has to be read on rtap_iface before to quit. Maybe we should thread
capture(), to be able to pthread_cancel() it.
- Fix segfault when rtap_iface is not in monitor mode (?) on Foneras.
- Merge Makefile and Makefile_atheros?
Use autohell?

View File

@ -97,6 +97,9 @@ void send_autocalibration_request(void) ;
uint_fast16_t make_packet(uint8_t **packet) ;
#endif // USE_PTHREAD
void sigint_handler(int num) ;
void sigterm_handler(int num) ;
void print_usage(void) ;
void print_version(void) ;

View File

@ -11,6 +11,7 @@ char *program_name = NULL ;
uint8_t my_mac_bytes[6] ; // AP MAC address
char my_ip[INET_ADDRSTRLEN] ; // AP IP address
pcap_t *capture_handler = NULL ; // Packet capture descriptor
int aggregation_sockfd ;
struct sockaddr_in aggregation_server ;
int autocalibration_send_sockfd ;
@ -89,9 +90,9 @@ int main(int argc, char *argv[])
/* Set up signal handlers */
sigemptyset(&action.sa_mask) ;
action.sa_handler = owl_sigint_handler ;
action.sa_handler = sigint_handler ;
sigaction(SIGINT, &action, NULL) ;
action.sa_handler = owl_sigterm_handler ;
action.sa_handler = sigterm_handler ;
sigaction(SIGTERM, &action, NULL) ;
get_mac_addr(GET_WIFI_IFACE(), my_mac_bytes) ;
@ -585,12 +586,12 @@ void* keep_mode_monitor(void *iface)
*/
int capture()
{
pcap_t *handle ; // Packet capture descriptor
char errbuf[PCAP_ERRBUF_SIZE] ; // Error message
// Start capture:
handle = pcap_open_live(GET_RTAP_IFACE(), BUFSIZ, 1, 1000, errbuf) ;
if (handle == NULL) // Capture starting failed
capture_handler =
pcap_open_live(GET_RTAP_IFACE(), BUFSIZ, 1, 1000, errbuf) ;
if (capture_handler == NULL) // Capture starting failed
{
fprintf(stderr, "Cannot open capture interface %s\n", errbuf) ;
return ERR_OPENING_IFACE ;
@ -602,11 +603,11 @@ int capture()
GET_AGGREGATION_PORT(),
&aggregation_server, NULL) ;
while(run)
while (run)
// Capture one packet at time, and call read_packet() on it:
pcap_loop(handle, 1, read_packet, NULL) ;
pcap_loop(capture_handler, 1, read_packet, NULL) ;
pcap_close(handle) ; // Stop capture
pcap_close(capture_handler) ; // Stop capture
close(aggregation_sockfd) ; // Close socket
return 0 ;
@ -1176,6 +1177,22 @@ uint_fast16_t make_packet(uint8_t **packet)
void sigint_handler(int num)
{
owl_sigint_handler(num) ;
pcap_breakloop(capture_handler) ;
}
void sigterm_handler(int num)
{
owl_sigterm_handler(num) ;
pcap_breakloop(capture_handler) ;
}
void print_usage()
{
printf("Usage :\n"