From bdc2cdc5fe5688742992ebe51b6bc6fc7dd5d2e6 Mon Sep 17 00:00:00 2001 From: Alexander Langer Date: Thu, 8 Oct 1998 00:32:08 +0000 Subject: [PATCH] Check the timeval passed to BIOCSRTIMEOUT with itimerfix. Use tvtohz() to convert the timeval into a tick count. Suggested by: bde Reviewed by: bde Handle hz > 1000 in BIOCGRTIMEOUT. Pointed out by: bde Reviewed by: bde Obtained from: OpenBSD --- sys/net/bpf.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 78bd721b1aa1..f9a217b5e334 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -37,7 +37,7 @@ * * @(#)bpf.c 8.2 (Berkeley) 3/28/94 * - * $Id: bpf.c,v 1.42 1998/10/04 17:20:22 alex Exp $ + * $Id: bpf.c,v 1.43 1998/10/04 23:04:48 alex Exp $ */ #include "bpfilter.h" @@ -778,9 +778,12 @@ bpfioctl(dev, cmd, addr, flags, p) { struct timeval *tv = (struct timeval *)addr; - d->bd_rtout = tv->tv_sec * hz + tv->tv_usec / tick; - if (d->bd_rtout == 0 && tv->tv_usec != 0) - d->bd_rtout = 1; + /* + * Subtract 1 tick from tvtohz() since this isn't + * a one-shot timer. + */ + if ((error = itimerfix(tv)) == 0) + d->bd_rtout = tvtohz(tv) - 1; break; } @@ -790,11 +793,9 @@ bpfioctl(dev, cmd, addr, flags, p) case BIOCGRTIMEOUT: { struct timeval *tv = (struct timeval *)addr; - u_long msec = d->bd_rtout; - msec *= tick / 1000; - tv->tv_sec = msec / 1000; - tv->tv_usec = msec % 1000; + tv->tv_sec = d->bd_rtout / hz; + tv->tv_usec = (d->bd_rtout % hz) * tick; break; }