Updated timeval_diff() to calculate a full difference.
[icmpmonitor] / icmpmonitor.c
index 6dede30..6bc2006 100644 (file)
  * See LICENSE file for copyright and license details.
  */
 
  * See LICENSE file for copyright and license details.
  */
 
+/* Wishlist */
+/* TODO: Add IPv6 support. */
+/* TODO: Turn the global '-r' functionality into per-host config file option. */
+/* TODO: Add 'auto' keyword to 'start_condition', testing host on startup. */
+/* TODO: Double-check the network code when interrupted while receiving a packet. */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -94,12 +100,16 @@ checksum(const uint16_t * data)
 }
 
 /*
 }
 
 /*
- * Calculate difference between two timeval structs to within one second.
+ * Calculate difference (a-b) between two timeval structs.
  */
 void
 timeval_diff(struct timeval * a, const struct timeval * b)
 {
  */
 void
 timeval_diff(struct timeval * a, const struct timeval * b)
 {
-    assert(a->tv_sec >= b->tv_sec);
+    if (a->tv_usec < b->tv_usec) {
+        a->tv_sec--;
+        a->tv_usec += 1000000;
+    }
+    a->tv_usec -= b->tv_usec;
     a->tv_sec -= b->tv_sec;
 }
 
     a->tv_sec -= b->tv_sec;
 }