diff options
author | Chris Kuethe <ckuethe@cvs.openbsd.org> | 2009-05-31 17:33:40 +0000 |
---|---|---|
committer | Chris Kuethe <ckuethe@cvs.openbsd.org> | 2009-05-31 17:33:40 +0000 |
commit | 8ab81686e9da47bf574ca4315fb6c8a32314db3b (patch) | |
tree | 28a90b679b2ef4d11ab13343aa9fde45c1daa8aa /sbin/ping | |
parent | 27c775ee9dc631b95ec2a1f83dad749c8ee5d8bb (diff) |
add audible output to ping and ping6: -e beeps when pings are replied, -E beeps when
pings are dropped.
suggestion to make ping and ping6 use the same flag from deraadt & sthen.
reminder to not forget about ping6 from todd and naddy.
ok deraadt, sthen
"well, i don't object..." from a few others.
Diffstat (limited to 'sbin/ping')
-rw-r--r-- | sbin/ping/ping.8 | 18 | ||||
-rw-r--r-- | sbin/ping/ping.c | 27 |
2 files changed, 38 insertions, 7 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8 index 062eccb26f8..df480aee7cb 100644 --- a/sbin/ping/ping.8 +++ b/sbin/ping/ping.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ping.8,v 1.36 2008/05/07 11:57:20 claudio Exp $ +.\" $OpenBSD: ping.8,v 1.37 2009/05/31 17:33:39 ckuethe Exp $ .\" $NetBSD: ping.8,v 1.10 1995/12/31 04:55:35 ghudson Exp $ .\" .\" Copyright (c) 1985, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)ping.8 8.2 (Berkeley) 12/11/93 .\" -.Dd $Mdocdate: May 7 2008 $ +.Dd $Mdocdate: May 31 2009 $ .Dt PING 8 .Os .Sh NAME @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm ping .Bk -words -.Op Fl DdfLnqRrv +.Op Fl DdEefLnqRrv .Op Fl c Ar count .Op Fl I Ar ifaddr .Op Fl i Ar wait @@ -82,6 +82,18 @@ bit. Set the .Dv SO_DEBUG option on the socket being used. +.It Fl E +Emit an audible beep (by sending an ascii BEL character to the +standard error output) when no packet is received before the next +packet is transmitted. +To cater for round-trip times that are longer than the interval between +transmissions, further missing packets cause a bell only if the maximum +number of unreceived packets has increased. +This is disabled for flood pings. +.It Fl e +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. .It Fl f Flood ping. Outputs packets as fast as they come back or one hundred times per second, diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index cd1b4afa868..d8e8149da97 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.79 2009/04/23 23:18:35 sthen Exp $ */ +/* $OpenBSD: ping.c,v 1.80 2009/05/31 17:33:39 ckuethe Exp $ */ /* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */ /* @@ -43,7 +43,7 @@ static const char copyright[] = #if 0 static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; #else -static const char rcsid[] = "$OpenBSD: ping.c,v 1.79 2009/04/23 23:18:35 sthen Exp $"; +static const char rcsid[] = "$OpenBSD: ping.c,v 1.80 2009/05/31 17:33:39 ckuethe Exp $"; #endif #endif /* not lint */ @@ -120,6 +120,8 @@ int options; #define F_HDRINCL 0x0400 #define F_TTL 0x0800 #define F_SO_JUMBO 0x1000 +#define F_AUD_RECV 0x2000 +#define F_AUD_MISS 0x4000 /* multicast options */ int moptions; @@ -152,6 +154,7 @@ unsigned long npackets; /* max packets to transmit */ unsigned long nreceived; /* # of packets we got back */ unsigned long nrepeats; /* number of duplicates */ unsigned long ntransmitted; /* sequence # for outbound packets = #sent */ +unsigned long nmissedmax = 1; /* max value of ntransmitted - nreceived - 1 */ double interval = 1; /* interval between packets */ struct itimerval interstr; /* interval structure for use with setitimer */ @@ -211,7 +214,7 @@ main(int argc, char *argv[]) preload = 0; datap = &outpack[8 + sizeof(struct tvi)]; while ((ch = getopt(argc, argv, - "DI:LRS:c:dfi:jl:np:qrs:T:t:vw:")) != -1) + "DEI:LRS:c:defi:jl:np:qrs:T:t:vw:")) != -1) switch(ch) { case 'c': npackets = (unsigned long)strtonum(optarg, 1, INT_MAX, &errstr); @@ -227,6 +230,12 @@ main(int argc, char *argv[]) case 'd': options |= F_SO_DEBUG; break; + case 'E': + options |= F_AUD_MISS; + break; + case 'e': + options |= F_AUD_RECV; + break; case 'f': if (getuid()) errx(1, "%s", strerror(EPERM)); @@ -353,6 +362,9 @@ main(int argc, char *argv[]) if (options & F_FLOOD && options & F_INTERVAL) errx(1, "-f and -i options are incompatible"); + if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS))) + warnx("No audible output for flood pings"); + if (datalen >= sizeof(struct tvi)) /* can we time transfer */ timing = 1; packlen = datalen + MAXIPLEN + MAXICMPLEN; @@ -567,6 +579,11 @@ catcher(int signo) (void)signal(SIGALRM, finish); (void)alarm(waittime); } + if (ntransmitted - nreceived - 1 > nmissedmax) { + nmissedmax = ntransmitted - nreceived - 1; + if (!(options & F_FLOOD) && (options & F_AUD_MISS)) + (void)fputc('\a', stderr); + } errno = save_errno; } @@ -866,6 +883,8 @@ pr_pack(char *buf, int cc, struct sockaddr_in *from) if (!(options & F_FLOOD)) { (void)putchar('\n'); (void)fflush(stdout); + if (options & F_AUD_RECV) + (void)fputc('\a', stderr); } } @@ -1341,7 +1360,7 @@ void usage(void) { (void)fprintf(stderr, - "usage: ping [-DdfLnqRrv] [-c count] [-I ifaddr] [-i wait]\n" + "usage: ping [-AaDdfLnqRrv] [-c count] [-I ifaddr] [-i wait]\n" "\t[-l preload] [-p pattern] [-s packetsize] [-T tos] [-t ttl]\n" "\t[-w maxwait] host\n"); exit(1); |