Merge branch 'tomato-ND-USBmod' into tomato-RT
[tomato.git] / release / src / router / radvd / timer.c
blob30d29628c1759e8b8850518a50494276021af41d
1 /*
2 * $Id: timer.c,v 1.12 2011/02/22 00:20:40 reubenhwk Exp $
4 * Authors:
5 * Pedro Roque <roque@di.fc.ul.pt>
6 * Lars Fenneberg <lf@elemental.net>
8 * This software is Copyright 1996-2000 by the above mentioned author(s),
9 * All Rights Reserved.
11 * The license which is distributed with this software in the file COPYRIGHT
12 * applies to this software. If your distribution is missing this file, you
13 * may request it from <pekkas@netcore.fi>.
17 #include "radvd.h"
19 struct timeval
20 next_timeval(double next)
22 struct timeval tv;
23 gettimeofday(&tv, NULL);
24 tv.tv_sec += (int)next;
25 tv.tv_usec += 1000000 * (next - (int)next);
26 return tv;
29 int
30 timevaldiff(struct timeval const *a, struct timeval const *b)
32 int msec;
33 msec = (a->tv_sec - b->tv_sec) * 1000;
34 msec += (a->tv_usec - b->tv_usec) / 1000;
35 return msec;
39 /* Returns when the next time should expire in milliseconds. */
40 int
41 next_time_msec(struct Interface const * iface)
43 struct timeval tv;
44 int retval;
45 gettimeofday(&tv, NULL);
46 retval = timevaldiff(&iface->next_multicast, &tv);
47 return retval >= 1 ? retval : 1;
50 int
51 expired(struct Interface const * iface)
53 struct timeval tv;
54 gettimeofday(&tv, NULL);
55 if(timevaldiff(&iface->next_multicast, &tv) > 0)
56 return 0;
57 return 1;