File: timer.c

package info (click to toggle)
radvd 1%3A1.8.5-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 908 kB
  • sloc: sh: 4,134; ansic: 3,562; yacc: 825; lex: 139; makefile: 109
file content (58 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (2)
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
58
/*
 *
 *   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 <pekkas@netcore.fi>.
 *
 */

#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;
}