Support for ping -a: beep when packet received.

Slightly tweaked from version submitted by andrew@untraceable.net in PR7815
This commit is contained in:
sommerfeld 1999-06-19 19:15:22 +00:00
parent 36da665f8c
commit 6c3d02c865
2 changed files with 24 additions and 5 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ping.8,v 1.29 1999/06/12 17:17:16 tron Exp $ .\" $NetBSD: ping.8,v 1.30 1999/06/19 19:15:22 sommerfeld Exp $
.\" .\"
.\" Copyright (c) 1985, 1991, 1993 .\" Copyright (c) 1985, 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -44,7 +44,7 @@ packets to network hosts
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm "" .Nm ""
.Bk -words .Bk -words
.Op Fl dfnoqrvDPQRL .Op Fl adfnoqrvDPQRL
.Ek .Ek
.Bk -words .Bk -words
.Op Fl c Ar count .Op Fl c Ar count
@ -96,6 +96,11 @@ and then an arbitrary number of ``pad'' bytes used to fill out the
packet. packet.
The options are as follows: The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl a
Emit an audible beep (by sending an ascii BEL character to the
standard error output) after each non-duplicate response is received.
This is disabled for flood pings as it would probably cause temporary
insanity.
.It Fl c Ar count .It Fl c Ar count
Stop after sending (and waiting the specified delay to receive) Stop after sending (and waiting the specified delay to receive)
.Ar count .Ar count

View File

@ -1,4 +1,4 @@
/* $NetBSD: ping.c,v 1.48 1999/04/17 01:17:15 mjl Exp $ */ /* $NetBSD: ping.c,v 1.49 1999/06/19 19:15:22 sommerfeld Exp $ */
/* /*
* Copyright (c) 1989, 1993 * Copyright (c) 1989, 1993
@ -62,7 +62,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: ping.c,v 1.48 1999/04/17 01:17:15 mjl Exp $"); __RCSID("$NetBSD: ping.c,v 1.49 1999/06/19 19:15:22 sommerfeld Exp $");
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -121,6 +121,7 @@ __RCSID("$NetBSD: ping.c,v 1.48 1999/04/17 01:17:15 mjl Exp $");
#define F_ONCE 0x1000 /* exit(0) after receiving 1 reply */ #define F_ONCE 0x1000 /* exit(0) after receiving 1 reply */
#define F_MCAST 0x2000 /* multicast target */ #define F_MCAST 0x2000 /* multicast target */
#define F_MCAST_NOLOOP 0x4000 /* no multicast loopback */ #define F_MCAST_NOLOOP 0x4000 /* no multicast loopback */
#define F_AUDIBLE 0x8000 /* audible output */
/* MAX_DUP_CHK is the number of bits in received table, the /* MAX_DUP_CHK is the number of bits in received table, the
@ -245,8 +246,11 @@ main(int argc, char *argv[])
__progname = argv[0]; __progname = argv[0];
#endif #endif
while ((c = getopt(argc, argv, while ((c = getopt(argc, argv,
"c:dDfg:h:i:I:l:Lnop:PqQrRs:t:T:vw:")) != -1) { "ac:dDfg:h:i:I:l:Lnop:PqQrRs:t:T:vw:")) != -1) {
switch (c) { switch (c) {
case 'a':
pingflags |= F_AUDIBLE;
break;
case 'c': case 'c':
npackets = strtol(optarg, &p, 0); npackets = strtol(optarg, &p, 0);
if (*p != '\0' || npackets <= 0) if (*p != '\0' || npackets <= 0)
@ -359,6 +363,9 @@ main(int argc, char *argv[])
#endif #endif
sec_to_timeval(interval, &interval_tv); sec_to_timeval(interval, &interval_tv);
if ((pingflags & (F_AUDIBLE|F_FLOOD)) == (F_AUDIBLE|F_FLOOD))
warnx("Sorry, no audible output for flood pings");
if (npackets != 0) { if (npackets != 0) {
npackets += preload; npackets += preload;
} else { } else {
@ -790,6 +797,13 @@ pr_pack_sub(int cc,
(void)printf(" ttl=%d", ttl); (void)printf(" ttl=%d", ttl);
if (pingflags & F_TIMING) if (pingflags & F_TIMING)
(void)printf(" time=%.3f ms", triptime*1000.0); (void)printf(" time=%.3f ms", triptime*1000.0);
/*
* Send beep to stderr, since that's more likely than stdout
* to go to a terminal..
*/
if (pingflags & F_AUDIBLE && !dupflag)
(void)fprintf(stderr,"\a");
} }