]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1542 in SNORT/snort3 from ~MASHASAN/snort3:cloud_lookup_retry...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 13 Mar 2019 13:30:22 +0000 (09:30 -0400)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 13 Mar 2019 13:30:22 +0000 (09:30 -0400)
Squashed commit of the following:

commit 3b07962e785332f7426f06d65bbb8a780ad3aeeb
Author: Masud Hasan <mashasan@cisco.com>
Date:   Mon Mar 11 14:52:05 2019 -0400

    time: Adding timersub_ms function to return timersub in milliseconds

src/time/packet_time.cc
src/time/packet_time.h

index 0dfdedc527279e5827cbc912432d4a1bd5069818..512d15bac0c1a8d3da50c3680e12320541af658b 100644 (file)
@@ -34,6 +34,7 @@
 #endif
 
 #include "main/thread.h"
+#include "time/timersub.h"
 
 #include "packet_time.h"
 
@@ -46,6 +47,19 @@ time_t packet_time()
 {
     return s_recent_packet.tv_sec;
 }
+
+int64_t timersub_ms(const struct timeval* end, const struct timeval* start)
+{
+    if (!end)
+        end = &s_recent_packet; // use recent packet time instead when end is null
+
+    if (!start or !start->tv_sec or !end->tv_sec)
+        return 0;               // can't really compare when values are not set
+
+    struct timeval difftime;
+    TIMERSUB(end, start, &difftime);
+    return difftime.tv_sec*1000 + difftime.tv_usec/1000;
+}
 }
 
 void packet_time_update(const struct timeval* cur_tv)
index a720c54ace65d8b9a0c5ed0fc03c1c28afd1e354..c9eb377883987b0acf2d6503e8fc1dc4401560db 100644 (file)
@@ -27,6 +27,7 @@
 namespace snort
 {
 SO_PUBLIC time_t packet_time();
+SO_PUBLIC int64_t timersub_ms(const struct timeval* end, const struct timeval* start);
 }
 
 void packet_time_update(const struct timeval* cur_tv);