Vitezslav Samel <vitezslav(a)samel.cz> writes:
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;
}
I don't see any point to have two functions. See
+static inline unsigned long __timeval_diff_msec(const struct timeval
*end,
+ const struct timeval *start)
+{
if (!start || !end)
return 0UL;
+ 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;
+}
and now you don't have to use __timeval... naming