forked from radvd-project/radvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.c
58 lines (51 loc) · 1.2 KB
/
timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
*
* Authors:
* Pedro Roque <roque@di.fc.ul.pt>
* Lars Fenneberg <lf@elemental.net>
*
* This software is Copyright 1996-2000 by the above mentioned author(s),
* All Rights Reserved.
*
* The license which is distributed with this software in the file COPYRIGHT
* applies to this software. If your distribution is missing this file, you
* may request it from <reubenhwk@gmail.com>.
*
*/
#include "radvd.h"
struct timeval
next_timeval(double next)
{
struct timeval tv;
gettimeofday(&tv, NULL);
tv.tv_sec += (int)next;
tv.tv_usec += 1000000 * (next - (int)next);
return tv;
}
int
timevaldiff(struct timeval const *a, struct timeval const *b)
{
int msec;
msec = (a->tv_sec - b->tv_sec) * 1000;
msec += (a->tv_usec - b->tv_usec) / 1000;
return msec;
}
/* Returns when the next time should expire in milliseconds. */
int
next_time_msec(struct Interface const * iface)
{
struct timeval tv;
int retval;
gettimeofday(&tv, NULL);
retval = timevaldiff(&iface->next_multicast, &tv);
return retval >= 1 ? retval : 1;
}
int
expired(struct Interface const * iface)
{
struct timeval tv;
gettimeofday(&tv, NULL);
if(timevaldiff(&iface->next_multicast, &tv) > 0)
return 0;
return 1;
}