This one computes difference in milliseconds between
two structs timeval.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/iptraf-ng-compat.h | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/iptraf-ng-compat.h b/src/iptraf-ng-compat.h
index b2cc0ac..ac10127 100644
--- a/src/iptraf-ng-compat.h
+++ b/src/iptraf-ng-compat.h
@@ -112,4 +112,31 @@ static inline char *skip_whitespace(char *str)
return str;
}
+static inline unsigned long __timeval_diff_msec(const struct timeval *end,
+ const struct timeval *start)
+{
+ signed long secs = end->tv_sec - start->tv_sec;
+ signed long usecs = end->tv_usec - start->tv_usec;
+
+ if(usecs < 0) {
+ usecs = 1000000 - usecs;
+ secs -= 1;
+ }
+ if(secs >= 0)
+ return secs * 1000UL + usecs / 1000UL;
+ else
+ return 0UL;
+}
+
+static inline unsigned long timeval_diff_msec(const struct timeval *end,
+ const struct timeval *start)
+{
+ if(!start)
+ return 0UL;
+ if(!end)
+ return 0UL;
+
+ return __timeval_diff_msec(end, start);
+}
+
#endif /* IPTRAF_NG_COMPAT_H */
--
1.7.8.4