diff options
-rw-r--r-- | sbin/ping/ping.8 | 18 | ||||
-rw-r--r-- | sbin/ping/ping.c | 27 | ||||
-rw-r--r-- | sbin/ping6/ping6.8 | 30 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 29 |
4 files changed, 78 insertions, 26 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); diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8 index 25cc4fa7795..17049b1d379 100644 --- a/sbin/ping6/ping6.8 +++ b/sbin/ping6/ping6.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ping6.8,v 1.39 2007/06/23 16:15:18 itojun Exp $ +.\" $OpenBSD: ping6.8,v 1.40 2009/05/31 17:33:39 ckuethe Exp $ .\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: June 23 2007 $ +.Dd $Mdocdate: May 31 2009 $ .Dt PING6 8 .Os .Sh NAME @@ -36,10 +36,7 @@ .Nd send ICMPv6 ECHO_REQUEST packets to network hosts .Sh SYNOPSIS .Nm ping6 -.\" without ipsec, or new ipsec -.Op Fl dfHmNnqtvWw -.\" old ipsec -.\" .Op Fl AdEfnNqRtvwW +.Op Fl dEefHmNnqtvWw .Op Fl a Ar addrtype .Op Fl b Ar bufsiz .Op Fl c Ar count @@ -49,8 +46,6 @@ .Op Fl i Ar wait .Op Fl l Ar preload .Op Fl p Ar pattern -.\" new ipsec -.\".Op Fl P Ar policy .Op Fl S Ar sourceaddr .Op Fl s Ar packetsize .Op Ar hops ... @@ -71,10 +66,6 @@ ICMPv6 header formatted as documented in RFC 2463. The options are as follows: .Bl -tag -width Ds -.\" old ipsec -.\" .It Fl A -.\" Enables transport-mode IPsec authentication header -.\" .Pq experimental . .It Fl a Ar addrtype Generate an ICMPv6 Node Information Node Addresses query, rather than an echo-request. @@ -115,9 +106,18 @@ packets. Set the .Dv SO_DEBUG option on the socket being used. -.\" .It Fl E -.\" Enables transport-mode IPsec encapsulated security payload -.\" .Pq experimental . +.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/ping6/ping6.c b/sbin/ping6/ping6.c index 179c294b255..376c2e0bf53 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.73 2008/03/24 16:11:08 deraadt Exp $ */ +/* $OpenBSD: ping6.c,v 1.74 2009/05/31 17:33:39 ckuethe Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -162,6 +162,8 @@ struct tv32 { #define F_NIGROUP 0x40000 #define F_SUPTYPES 0x80000 #define F_NOMINMTU 0x100000 +#define F_AUD_RECV 0x200000 +#define F_AUD_MISS 0x400000 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) u_int options; @@ -199,6 +201,7 @@ long npackets; /* max packets to transmit */ long nreceived; /* # of packets we got back */ long nrepeats; /* number of duplicates */ long ntransmitted; /* sequence # for outbound packets = #sent */ +unsigned long nmissedmax = 1; /* max value of ntransmitted - nreceived - 1 */ struct timeval interval = {1, 0}; /* interval between packets */ /* timing */ @@ -285,7 +288,7 @@ main(int argc, char *argv[]) preload = 0; datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; while ((ch = getopt(argc, argv, - "a:b:c:dfHg:h:I:i:l:mnNp:qRS:s:tvwW")) != -1) { + "a:b:c:dEefHg:h:I:i:l:mnNp:qRS:s:tvwW")) != -1) { switch (ch) { case 'a': { @@ -353,6 +356,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()) { errno = EPERM; @@ -589,6 +598,10 @@ main(int argc, char *argv[]) if ((options & F_FLOOD) && (options & F_INTERVAL)) errx(1, "-f and -i incompatible options"); + if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS))) + warnx("No audible output for flood pings"); + + if ((options & F_NOUSERDATA) == 0) { if (datalen >= sizeof(struct tv32)) { /* we can time transfer */ @@ -954,6 +967,12 @@ main(int argc, char *argv[]) } if (npackets && nreceived >= npackets) break; + if (ntransmitted - nreceived - 1 > nmissedmax) { + nmissedmax = ntransmitted - nreceived - 1; + if (!(options & F_FLOOD) && (options & F_AUD_MISS)) + (void)fputc('\a', stderr); + } + } summary(0); exit(nreceived == 0); @@ -1342,6 +1361,8 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr) (void)printf(" time=%g ms", triptime); if (dupflag) (void)printf("(DUP!)"); + if (options & F_AUD_RECV) + (void)fputc('\a', stderr); /* check the data */ cp = buf + off + ICMP6ECHOLEN + ICMP6ECHOTMLEN; dp = outpack + ICMP6ECHOLEN + ICMP6ECHOTMLEN; @@ -2433,14 +2454,14 @@ void usage(void) { (void)fprintf(stderr, - "usage: ping6 [-dfH" + "usage: ping6 [-dEefH" "m" "NnqtvWw" #ifdef IPV6_REACHCONF "R" #endif "] [-a addrtype] [-b bufsiz] [-c count] [-g gateway]\n\t" - "[-h hoplimit] [-I interface] [-i wait] [-l preload] [-p pattern]" + "[-h hoplimit] [-I interface] [-i wait] [-l preload] [-p pattern]" "\n\t[-S sourceaddr] [-s packetsize] [hops ...] host\n"); exit(1); } |