summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorStuart Henderson <sthen@cvs.openbsd.org>2021-02-21 10:38:43 +0000
committerStuart Henderson <sthen@cvs.openbsd.org>2021-02-21 10:38:43 +0000
commitf85deff41e2f1b07e5edb89168814eb0f9a24a60 (patch)
tree1b3457d08dbbbd6272e205a54e10e6c7cc39bbbe /sbin
parentc0e7527311e586cd04895a5a7c39c49a90eb9a5a (diff)
Add ping -g, a concise display format similar to that used by other
network devices that shows one character per echo request (! for normal response, . for timed out, D for duplicate, T for truncated) making it easier to identify patterns of loss over periods of time. ok remi@ kn@, feedback from deraadt@ chris@ !!!!!...!!!!!!!!!!!!!!!!!!!!!!!!!!!...!!!!!!!!!!!!!!!!!!!!!!!!!!!.........!!!!!!!!!!!!!!!!!!!!!...!!!!!!!!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!.........!!!!!!!!!!!!!!!!!!!!!...!!!!!!!!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!.........!!!!!!!!!!!!!!!!!!!!!...!!!!!!!!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!..........!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!..........!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!..........!!!!!!!!!!!!!!!!!!!!....!!!!!!!!!!!!!!!!!!!!!!!!!!.....!!!!!!!!!!!!!!
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ping/ping.822
-rw-r--r--sbin/ping/ping.c37
2 files changed, 45 insertions, 14 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index 259a6f363d1..964bbaeeabb 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ping.8,v 1.63 2020/02/11 18:41:39 deraadt Exp $
+.\" $OpenBSD: ping.8,v 1.64 2021/02/21 10:38:42 sthen Exp $
.\" $NetBSD: ping.8,v 1.10 1995/12/31 04:55:35 ghudson Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -57,7 +57,7 @@
.\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\"
-.Dd $Mdocdate: February 11 2020 $
+.Dd $Mdocdate: February 21 2021 $
.Dt PING 8
.Os
.Sh NAME
@@ -66,7 +66,7 @@
.Nd send ICMP ECHO_REQUEST packets to network hosts
.Sh SYNOPSIS
.Nm ping
-.Op Fl DdEefHLnqRv
+.Op Fl DdEefgHLnqRv
.Op Fl c Ar count
.Op Fl I Ar sourceaddr
.Op Fl i Ar interval
@@ -79,7 +79,7 @@
.Op Fl w Ar maxwait
.Ar host
.Nm ping6
-.Op Fl DdEefHLmnqv
+.Op Fl DdEefgHLmnqv
.Op Fl c Ar count
.Op Fl h Ar hoplimit
.Op Fl I Ar sourceaddr
@@ -151,6 +151,20 @@ Only the superuser may use this option.
.Bf -emphasis
This can be very hard on a network and should be used with caution.
.Ef
+.It Fl g
+Provides a visual display of packets received and lost.
+For every
+.Dv ECHO_REPLY
+received, an exclamation mark
+.Sq !
+is printed, while for every missed packet a period
+.Sq \&.
+is printed.
+Duplicate and truncated replies are indicated with
+.Sq D
+and
+.Sq T
+respectively.
.It Fl H
Try reverse lookups for addresses.
.It Fl h Ar hoplimit
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 068c262da4a..f7c3c101b25 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping.c,v 1.243 2020/12/29 16:40:47 florian Exp $ */
+/* $OpenBSD: ping.c,v 1.244 2021/02/21 10:38:42 sthen Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -145,7 +145,7 @@ int options;
#define F_QUIET 0x0010
#define F_RROUTE 0x0020
#define F_SO_DEBUG 0x0040
-/* 0x0080 */
+#define F_SHOWCHAR 0x0080
#define F_VERBOSE 0x0100
/* 0x0200 */
#define F_HDRINCL 0x0400
@@ -297,8 +297,8 @@ main(int argc, char *argv[])
preload = 0;
datap = &outpack[ECHOLEN + ECHOTMLEN];
while ((ch = getopt(argc, argv, v6flag ?
- "c:DdEefHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
- "DEI:LRS:c:defHi:l:np:qs:T:t:V:vw:")) != -1) {
+ "c:DdEefgHh:I:i:Ll:mNnp:qS:s:T:V:vw:" :
+ "DEI:LRS:c:defgHi:l:np:qs:T:t:V:vw:")) != -1) {
switch(ch) {
case 'c':
npackets = strtonum(optarg, 0, INT64_MAX, &errstr);
@@ -326,6 +326,9 @@ main(int argc, char *argv[])
options |= F_FLOOD;
setvbuf(stdout, NULL, _IONBF, 0);
break;
+ case 'g':
+ options |= F_SHOWCHAR;
+ break;
case 'H':
options |= F_HOSTNAME;
break;
@@ -879,6 +882,11 @@ main(int argc, char *argv[])
if (!(options & F_FLOOD) &&
(options & F_AUD_MISS))
fputc('\a', stderr);
+ if ((options & F_SHOWCHAR) &&
+ !(options & F_FLOOD)) {
+ putchar('.');
+ fflush(stdout);
+ }
}
continue;
}
@@ -1329,7 +1337,14 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr)
if (options & F_FLOOD)
write(STDOUT_FILENO, &BSPACE, 1);
- else {
+ else if (options & F_SHOWCHAR) {
+ if (dupflag)
+ putchar('D');
+ else if (cc - ECHOLEN < datalen)
+ putchar('T');
+ else
+ putchar('!');
+ } else {
printf("%d bytes from %s: icmp_seq=%u", cc,
pr_addr(from, fromlen), ntohs(seq));
if (v6flag)
@@ -1386,9 +1401,11 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr)
pr_ipopt(hlen, buf);
if (!(options & F_FLOOD)) {
- putchar('\n');
- if (v6flag && (options & F_VERBOSE))
- pr_exthdrs(mhdr);
+ if (!(options & F_SHOWCHAR)) {
+ putchar('\n');
+ if (v6flag && (options & F_VERBOSE))
+ pr_exthdrs(mhdr);
+ }
fflush(stdout);
if (options & F_AUD_RECV)
fputc('\a', stderr);
@@ -2236,13 +2253,13 @@ usage(void)
{
if (v6flag) {
fprintf(stderr,
- "usage: ping6 [-DdEefHLmnqv] [-c count] [-h hoplimit] "
+ "usage: ping6 [-DdEefgHLmnqv] [-c count] [-h hoplimit] "
"[-I sourceaddr]\n\t[-i interval] [-l preload] "
"[-p pattern] [-s packetsize] [-T toskeyword]\n"
"\t[-V rtable] [-w maxwait] host\n");
} else {
fprintf(stderr,
- "usage: ping [-DdEefHLnqRv] [-c count] [-I sourceaddr] "
+ "usage: ping [-DdEefgHLnqRv] [-c count] [-I sourceaddr] "
"[-i interval]\n\t[-l preload] [-p pattern] [-s packetsize]"
#ifndef SMALL
" [-T toskeyword]"