Warn if pcap_dispatch looks like it's blocking.
authorEmil Mikulic <emikulic@gmail.com>
Wed, 12 Aug 2009 12:45:34 +0000 (22:45 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sat, 28 May 2011 10:10:52 +0000 (20:10 +1000)
cap.c

diff --git a/cap.c b/cap.c
index f224561..57deb17 100644 (file)
--- a/cap.c
+++ b/cap.c
@@ -303,6 +303,10 @@ cap_poll(fd_set *read_set
 
    total = 0;
    for (;;) {
+#ifndef NDEBUG
+      struct timeval t1;
+      gettimeofday(&t1, NULL);
+#endif
       ret = pcap_dispatch(
             pcap,
             -1,               /* count, -1 = entire buffer */
@@ -314,6 +318,19 @@ cap_poll(fd_set *read_set
          return;
       }
 
+#ifndef NDEBUG
+      {
+         struct timeval t2;
+         int td;
+
+         gettimeofday(&t2, NULL);
+         td = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec;
+         if (td > CAP_TIMEOUT*1000)
+            warnx("pcap_dispatch blocked for %d usec! (expected <= %d usec)\n",
+               td, CAP_TIMEOUT*1000);
+      }
+#endif
+
       /* Despite count = -1, Linux will only dispatch one packet at a time. */
       total += ret;