diff --git a/sbin/ping/main.h b/sbin/ping/main.h --- a/sbin/ping/main.h +++ b/sbin/ping/main.h @@ -40,7 +40,7 @@ #else #define PING4ADDOPTS #endif -#define PING4OPTS "4AaC:c:DdfG:g:Hh:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" PING4ADDOPTS +#define PING4OPTS ".::4AaC:c:DdfG:g:Hh:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" PING4ADDOPTS #if defined(INET6) && defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) #define PING6ADDOPTS "P:" @@ -49,7 +49,7 @@ #else #define PING6ADDOPTS #endif -#define PING6OPTS "6Aab:C:c:Dde:fHI:i:k:l:m:nNoOp:qS:s:t:uvyYW:z:" PING6ADDOPTS +#define PING6OPTS ".::6Aab:C:c:Dde:fHI:i:k:l:m:nNoOp:qS:s:t:uvyYW:z:" PING6ADDOPTS void usage(void) __dead2; diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8 --- a/sbin/ping/ping.8 +++ b/sbin/ping/ping.8 @@ -41,6 +41,7 @@ .Sh SYNOPSIS .Nm .Op Fl 4AaDdfHnoQqRrv +.Op Fl .\& Ns Ar chars .Op Fl C Ar pcp .Op Fl c Ar count .Op Fl G Ar sweepmaxsize @@ -60,6 +61,7 @@ .Ar IPv4-host .Nm .Op Fl 4AaDdfHLnoQqRrv +.Op Fl .\& Ns Ar chars .Op Fl C Ar pcp .Op Fl c Ar count .Op Fl I Ar iface @@ -78,6 +80,7 @@ .Ar IPv4-mcast-group .Nm .Op Fl 6AaDdEfHNnOoquvYyZ +.Op Fl .\& Ns Ar chars .Op Fl b Ar bufsiz .Op Fl c Ar count .Op Fl e Ar gateway @@ -145,6 +148,22 @@ .Nm ping6 . .Ss Options common to both IPv4 and IPv6 targets .Bl -tag -width indent +.It Fl .\& Ns Ar chars +By default, for every +.Tn ECHO_REQUEST +sent, a period +.Dq .\& +is printed, while for every +.Tn ECHO_REPLY +received, a backspace is printed. +This option takes an optional string argument listing characters +that will be printed one by one in the provided order +instead of the default period. +.Pp +Example usage: +.Bd -literal -offset indent +ping -.0123456789 freebsd.org +.Ed .It Fl A Audible. Output a bell @@ -188,13 +207,13 @@ Flood ping. Outputs packets as fast as they come back or one hundred times per second, whichever is more. -For every +Implies +.Fl .\& +to print a period for every .Tn ECHO_REQUEST -sent a period -.Dq .\& -is printed, while for every +sent and a backspace for every .Tn ECHO_REPLY -received a backspace is printed. +received. This provides a rapid display of how many packets are being dropped. Only the super-user may use this option. .Bf -emphasis diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -158,6 +158,7 @@ #define F_SWEEP 0x200000 #define F_WAITTIME 0x400000 #define F_IP_VLAN_PCP 0x800000 +#define F_DOT 0x1000000 /* * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum @@ -176,7 +177,9 @@ static u_char outpackhdr[IP_MAXPACKET], *outpack; static char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */ static char BSPACE = '\b'; /* characters written for flood */ -static char DOT = '.'; +static const char *DOT = "."; +static size_t DOTlen = 1; +static size_t DOTidx = 0; static char *hostname; static char *shostname; static int ident; /* process id to identify our packets */ @@ -303,6 +306,13 @@ outpack = outpackhdr + sizeof(struct ip); while ((ch = getopt(argc, argv, PING4OPTS)) != -1) { switch(ch) { + case '.': + options |= F_DOT; + if (optarg != NULL) { + DOT = optarg; + DOTlen = strlen(optarg); + } + break; case '4': /* This option is processed in main(). */ break; @@ -340,6 +350,7 @@ err(EX_NOPERM, "-f flag"); } options |= F_FLOOD; + options |= F_DOT; setbuf(stdout, (char *)NULL); break; case 'G': /* Maximum packet size for ping sweep */ @@ -1114,8 +1125,8 @@ } ntransmitted++; sntransmitted++; - if (!(options & F_QUIET) && options & F_FLOOD) - (void)write(STDOUT_FILENO, &DOT, 1); + if (!(options & F_QUIET) && options & F_DOT) + (void)write(STDOUT_FILENO, &DOT[DOTidx++ % DOTlen], 1); } /* @@ -1220,7 +1231,7 @@ return; } - if (options & F_FLOOD) + if (options & F_DOT) (void)write(STDOUT_FILENO, &BSPACE, 1); else { (void)printf("%zd bytes from %s: icmp_seq=%u", cc, @@ -1361,7 +1372,7 @@ } if (i == old_rrlen && !bcmp((char *)cp, old_rr, i) - && !(options & F_FLOOD)) { + && !(options & F_DOT)) { (void)printf("\t(same route)"); hlen -= i; cp += i; @@ -1396,7 +1407,7 @@ (void)printf("\nunknown option %x", *cp); break; } - if (!(options & F_FLOOD)) { + if (!(options & F_DOT)) { (void)putchar('\n'); (void)fflush(stdout); } diff --git a/sbin/ping/ping6.c b/sbin/ping/ping6.c --- a/sbin/ping/ping6.c +++ b/sbin/ping/ping6.c @@ -201,6 +201,7 @@ #define F_DONTFRAG 0x1000000 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) #define F_WAITTIME 0x2000000 +#define F_DOT 0x4000000 static u_int options; #define IN6LEN sizeof(struct in6_addr) @@ -227,7 +228,9 @@ static u_char outpack[MAXPACKETLEN]; static char BSPACE = '\b'; /* characters written for flood */ static char BBELL = '\a'; /* characters written for AUDIBLE */ -static char DOT = '.'; +static const char *DOT = "."; +static size_t DOTlen = 1; +static size_t DOTidx = 0; static char *hostname; static int ident; /* process id to identify our packets */ static u_int8_t nonce[8]; /* nonce field for node information */ @@ -352,6 +355,13 @@ while ((ch = getopt(argc, argv, PING6OPTS)) != -1) { switch (ch) { + case '.': + options |= F_DOT; + if (optarg != NULL) { + DOT = optarg; + DOTlen = strlen(optarg); + } + break; case '6': /* This option is processed in main(). */ break; @@ -437,6 +447,7 @@ errx(1, "Must be superuser to flood ping"); } options |= F_FLOOD; + options |= F_DOT; setbuf(stdout, (char *)NULL); break; case 'e': @@ -1463,8 +1474,8 @@ (void)printf("ping6: wrote %s %d chars, ret=%d\n", hostname, cc, i); } - if (!(options & F_QUIET) && options & F_FLOOD) - (void)write(STDOUT_FILENO, &DOT, 1); + if (!(options & F_QUIET) && options & F_DOT) + (void)write(STDOUT_FILENO, &DOT[DOTidx++ % DOTlen], 1); return(0); } @@ -1661,7 +1672,7 @@ return; } - if (options & F_FLOOD) + if (options & F_DOT) (void)write(STDOUT_FILENO, &BSPACE, 1); else { if (options & F_AUDIBLE) @@ -1853,7 +1864,7 @@ pr_icmph(icp, end); } - if (!(options & F_FLOOD)) { + if (!(options & F_DOT)) { (void)putchar('\n'); if (options & F_VERBOSE) pr_exthdrs(mhdr);