--- arpon-3.0-ng+dfsg1/src/intf.c 2020-05-05 10:30:53.111114269 +0200 +++ arpon-3.0-ng+dfsg1/src/intf.c 2020-05-05 10:34:02.050975653 +0200 @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include @@ -119,16 +119,6 @@ #define INTF_ARPFILTER "arp" /* - * No seconds. - */ -#define INTF_SECS 0 - -/* - * Milliseconds to microseconds. - */ -#define INTF_MILLI2MICRO(x) x * 1000 - -/* * Live capture counter. */ #define INTF_LOOPCOUNT -1 /* All ARP packets received. */ @@ -669,8 +659,9 @@ void * intf_capture(void *callback) { - struct timeval timeout; - int fd; + struct epoll_event ev; + memset(&ev, 0, sizeof(ev)); + int fdread = epoll_create1(0); /* Initialize the thread. */ thd_init(); @@ -678,46 +669,28 @@ MSG_DEBUG("Capture on %s..", opt_getinterface()); /* Get the pcap capture handle file descriptor. */ - if ((fd = pcap_get_selectable_fd(cfg->pcap)) < 0) { + if ((ev.data.fd = pcap_get_selectable_fd(cfg->pcap)) < 0) { MSG_ERROR("No selectable file descriptor from pcap"); exit(EXIT_FAILURE); } - /* Set the read capture timeout to 1 millisecond. */ - timeout.tv_sec = INTF_SECS; /* No seconds. */ - timeout.tv_usec = INTF_MILLI2MICRO(INTF_READTIMEOUT); + /* Available for read operations */ + ev.events = EPOLLIN; + + /* Setup the pcap capture handle file descriptor for epoll */ + if (epoll_ctl(fdread, EPOLL_CTL_ADD, ev.data.fd, &ev) < 0) { + MSG_ERROR("%s", strerror(errno)); + exit(EXIT_FAILURE); + } /* * Loop until the network traffic of the interface is up. - * This loop uses select + pcap in order to process the + * This loop uses epoll + pcap in order to process the * I/O asynchronous ARP packets read from the buffer. */ while (1) { - fd_set fdread; - - /* Clear the set. */ - FD_ZERO(&fdread); - - /* Add the pcap capture handle file descriptor to set. */ - FD_SET(fd, &fdread); - - /* - * Monitor the pcap capture handle file descriptor - * until it becomes ready for the reading. - */ - if (select(fd + 1, &fdread, NULL, NULL, &timeout) < 0) { - /* Interrupt signal? */ - if (errno == EINTR) { - /* Loop again with the time remaining calculated by select. */ - continue; - } - - MSG_ERROR("%s", strerror(errno)); - exit(EXIT_FAILURE); - } - /* Pcap capture handle file descriptor is ready to reading? */ - if (FD_ISSET(fd, &fdread) != 0) { + if (epoll_wait(fdread, &ev, 1, -1) > 0) { /* * Process the live capture from the network traffic (read from * the buffer) and run the live capture decoder callback routine. @@ -746,10 +719,6 @@ } } } - - /* Re-set the read capture timeout to 1 millisecond. */ - timeout.tv_sec = INTF_SECS; /* No seconds. */ - timeout.tv_usec = INTF_MILLI2MICRO(INTF_READTIMEOUT); } /* Never reaches here. */