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
.\" The Regents of the University of California. All rights reserved.
@ -44,7 +44,7 @@ packets to network hosts
.Sh SYNOPSIS
.Nm ""
.Bk -words
.Op Fl dfnoqrvDPQRL
.Op Fl adfnoqrvDPQRL
.Ek
.Bk -words
.Op Fl c Ar count
@ -96,6 +96,11 @@ and then an arbitrary number of ``pad'' bytes used to fill out the
packet.
The options are as follows:
.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
Stop after sending (and waiting the specified delay to receive)
.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
@ -62,7 +62,7 @@
#include <sys/cdefs.h>
#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
#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_MCAST 0x2000 /* multicast target */
#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
@ -245,8 +246,11 @@ main(int argc, char *argv[])
__progname = argv[0];
#endif
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) {
case 'a':
pingflags |= F_AUDIBLE;
break;
case 'c':
npackets = strtol(optarg, &p, 0);
if (*p != '\0' || npackets <= 0)
@ -359,6 +363,9 @@ main(int argc, char *argv[])
#endif
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) {
npackets += preload;
} else {
@ -790,6 +797,13 @@ pr_pack_sub(int cc,
(void)printf(" ttl=%d", ttl);
if (pingflags & F_TIMING)
(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");
}