From: Mike Stepanek (mstepane) Date: Wed, 13 Mar 2019 13:30:22 +0000 (-0400) Subject: Merge pull request #1542 in SNORT/snort3 from ~MASHASAN/snort3:cloud_lookup_retry... X-Git-Tag: 3.0.0-251~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13026a88f82f2b5701a39a1d0e53a8d67c0d2204;p=thirdparty%2Fsnort3.git Merge pull request #1542 in SNORT/snort3 from ~MASHASAN/snort3:cloud_lookup_retry to master Squashed commit of the following: commit 3b07962e785332f7426f06d65bbb8a780ad3aeeb Author: Masud Hasan Date: Mon Mar 11 14:52:05 2019 -0400 time: Adding timersub_ms function to return timersub in milliseconds --- diff --git a/src/time/packet_time.cc b/src/time/packet_time.cc index 0dfdedc52..512d15bac 100644 --- a/src/time/packet_time.cc +++ b/src/time/packet_time.cc @@ -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) diff --git a/src/time/packet_time.h b/src/time/packet_time.h index a720c54ac..c9eb37788 100644 --- a/src/time/packet_time.h +++ b/src/time/packet_time.h @@ -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);