From ae8f515ebbe93c614c0b23bfca5f64abcff29955 Mon Sep 17 00:00:00 2001 From: ume Date: Wed, 14 Jan 2004 16:55:08 +0000 Subject: use timeradd/sub/cmp. Obtained from: KAME --- usr.sbin/rtsold/rtsold.c | 65 ++++++------------------------------------------ 1 file 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; -- cgit v1.1