diff options
author | ume <ume@FreeBSD.org> | 2004-01-14 16:55:08 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2004-01-14 16:55:08 +0000 |
commit | ae8f515ebbe93c614c0b23bfca5f64abcff29955 (patch) | |
tree | 98bbb64ccebbb2f30bbd315dc6f05054c1fb1d5d | |
parent | cf600926e96281464ee5006d692c7c1cf9ec9aa4 (diff) | |
download | FreeBSD-src-ae8f515ebbe93c614c0b23bfca5f64abcff29955.zip FreeBSD-src-ae8f515ebbe93c614c0b23bfca5f64abcff29955.tar.gz |
use timeradd/sub/cmp.
Obtained from: KAME
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 65 |
1 files changed, 7 insertions, 58 deletions
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index be9d712..302200b 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -79,20 +79,6 @@ char *otherconf_script; */ #define PROBE_INTERVAL 60 -/* utility macros */ -/* a < b */ -#define TIMEVAL_LT(a, b) (((a).tv_sec < (b).tv_sec) ||\ - (((a).tv_sec == (b).tv_sec) && \ - ((a).tv_usec < (b).tv_usec))) - -/* a <= b */ -#define TIMEVAL_LEQ(a, b) (((a).tv_sec < (b).tv_sec) ||\ - (((a).tv_sec == (b).tv_sec) &&\ - ((a).tv_usec <= (b).tv_usec))) - -/* a == b */ -#define TIMEVAL_EQ(a, b) (((a).tv_sec==(b).tv_sec) && ((a).tv_usec==(b).tv_usec)) - int main __P((int, char **)); /* static variables and functions */ @@ -106,10 +92,6 @@ static int ifreconfig __P((char *)); #endif static int make_packet __P((struct ifinfo *)); static struct timeval *rtsol_check_timer __P((void)); -static void TIMEVAL_ADD __P((struct timeval *, struct timeval *, - struct timeval *)); -static void TIMEVAL_SUB __P((struct timeval *, struct timeval *, - struct timeval *)); static void rtsold_set_dump_file __P((int)); static void usage __P((char *)); @@ -557,7 +539,7 @@ rtsol_check_timer() rtsol_timer = tm_max; for (ifinfo = iflist; ifinfo; ifinfo = ifinfo->next) { - if (TIMEVAL_LEQ(ifinfo->expire, now)) { + if (timercmp(&ifinfo->expire, &now, <=)) { if (dflag > 1) warnmsg(LOG_DEBUG, __func__, "timer expiration on %s, " @@ -631,18 +613,18 @@ rtsol_check_timer() rtsol_timer_update(ifinfo); } - if (TIMEVAL_LT(ifinfo->expire, rtsol_timer)) + if (timercmp(&ifinfo->expire, &rtsol_timer, <)) rtsol_timer = ifinfo->expire; } - if (TIMEVAL_EQ(rtsol_timer, tm_max)) { + if (timercmp(&rtsol_timer, &tm_max, ==)) { warnmsg(LOG_DEBUG, __func__, "there is no timer"); return(NULL); - } else if (TIMEVAL_LT(rtsol_timer, now)) + } else if (timercmp(&rtsol_timer, &now, <)) /* this may occur when the interval is too small */ returnval.tv_sec = returnval.tv_usec = 0; else - TIMEVAL_SUB(&rtsol_timer, &now, &returnval); + timersub(&rtsol_timer, &now, &returnval); if (dflag > 1) warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld", @@ -709,13 +691,13 @@ rtsol_timer_update(struct ifinfo *ifinfo) } /* reset the timer */ - if (TIMEVAL_EQ(ifinfo->timer, tm_max)) { + if (timercmp(&ifinfo->timer, &tm_max, ==)) { ifinfo->expire = tm_max; warnmsg(LOG_DEBUG, __func__, "stop timer for %s", ifinfo->ifname); } else { gettimeofday(&now, NULL); - TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire); + timeradd(&now, &ifinfo->timer, &ifinfo->expire); if (dflag > 1) warnmsg(LOG_DEBUG, __func__, @@ -730,39 +712,6 @@ rtsol_timer_update(struct ifinfo *ifinfo) /* timer related utility functions */ #define MILLION 1000000 -/* result = a + b */ -static void -TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result) -{ - long l; - - if ((l = a->tv_usec + b->tv_usec) < MILLION) { - result->tv_usec = l; - result->tv_sec = a->tv_sec + b->tv_sec; - } else { - result->tv_usec = l - MILLION; - result->tv_sec = a->tv_sec + b->tv_sec + 1; - } -} - -/* - * result = a - b - * XXX: this function assumes that a >= b. - */ -void -TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result) -{ - long l; - - if ((l = a->tv_usec - b->tv_usec) >= 0) { - result->tv_usec = l; - result->tv_sec = a->tv_sec - b->tv_sec; - } else { - result->tv_usec = MILLION + l; - result->tv_sec = a->tv_sec - b->tv_sec - 1; - } -} - static void rtsold_set_dump_file(sig) int sig; |