From 1af95559cf04f6d05e732a600b1e8a313d7a1430 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 18 Jul 2018 13:55:39 +0000 Subject: [PATCH] When running flood ping with count packets (-c) set an alarm after sending all packets otherwise ping will wait forever to see all answers - which might not arrive on lossy links. Problem pointed out by, input & OK claudio --- sbin/ping/ping.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 54846f6c9eb..520f3226910 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.225 2018/04/11 16:03:58 zhuk Exp $ */ +/* $OpenBSD: ping.c,v 1.226 2018/07/18 13:55:39 florian Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -817,8 +817,25 @@ main(int argc, char *argv[]) } if (options & F_FLOOD) { - (void)pinger(s); - timeout = 10; + if (pinger(s) != 0) { + (void)signal(SIGALRM, onsignal); + timeout = INFTIM; + if (nreceived) { + itimer.it_value.tv_sec = 2 * tmax / + 1000; + if (itimer.it_value.tv_sec == 0) + itimer.it_value.tv_sec = 1; + } else + itimer.it_value.tv_sec = maxwait; + itimer.it_interval.tv_sec = 0; + itimer.it_interval.tv_usec = 0; + itimer.it_value.tv_usec = 0; + (void)setitimer(ITIMER_REAL, &itimer, NULL); + + /* When the alarm goes off we are done. */ + seenint = 1; + } else + timeout = 10; } else timeout = INFTIM; -- 2.20.1