Skip to content

Commit 45abaed

Browse files
blairstevencarlatat
authored andcommitted
Use monotonic clock for time keeping
1 parent 4a173e2 commit 45abaed

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ginetflow.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ static gboolean flow_parse_ipv6(GInetTuple * f, const guint8 * data, guint32 len
223223

224224
static inline guint64 get_time_us(void)
225225
{
226-
struct timeval tv;
227-
gettimeofday(&tv, NULL);
228-
return (tv.tv_sec * (guint64) TIMESTAMP_RESOLUTION_US + tv.tv_usec);
226+
struct timespec now;
227+
228+
if (clock_gettime(CLOCK_MONOTONIC, &now) == 0)
229+
return (now.tv_sec * (guint64)TIMESTAMP_RESOLUTION_US + (now.tv_nsec / 1000));
230+
else
231+
return 0;
229232
}
230233

231234
static guint32 get_hdr_len(guint8 hdr_ext_len)

0 commit comments

Comments
 (0)