From nobody Sat Dec 24 07:22:34 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NfFqv1F9Pz1HGwN; Sat, 24 Dec 2022 07:22:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NfFqv0RJhz3F65; Sat, 24 Dec 2022 07:22:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671866555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oEYZpLety47e/8533Z5Xp4q5AJmd1jhzQgU6ItM3kbs=; b=oeo1qErTrJ0l9JL2teU/TNmZzHgrXKslb1j69oQLXSO1lG8UUPAnyaMOWOeG2RRU7sy9HN 3FNzn7fdId45MCvdGgg1qstDSkF43nyLP48k3hhH0D5W3Kngq+EV4TmlE6XgqGDrMgD2o4 7Uh+YsJ4S5EuiMnR0ZEAPFoAa75lc5TLRoMmrAZmTWPgax3UpsVv/nCcbPxLV52v1SUcAl ix/rpDxVaMt4Xh+k+e78H6T9h119QueqIKt3DCuqD7OUQ1NrJHmKUxFcm8NDv0zY+lNdGo v27zuT2HPxYuxObIlVlx7wctKu5kvU6Gp9JEQkAAiLDoqAvC5ixjQsAqbkhwQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671866555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oEYZpLety47e/8533Z5Xp4q5AJmd1jhzQgU6ItM3kbs=; b=d3SHLw1FYOQ3EAF7jKSn0Oru670WzlKrEuAYGO+P3n38d/aJroa4DEeSQS2IA15ME3p9Wn Wek0j4TwVpIdH1uJeZ1cNG8RbigfzWj7M7D6pS1F5/Dpk5OQow4coAkN9obYVnic82gDbu 30TWjRHLJX4yTYpR9o19x5kSD1ynwh9MctdQP7kEzYdiPVVR2uh89m8P8JX8GkTR+fYPP/ e2KRXTOqyDLhm0RMKlo+ezImJx6pUUhJxl3mikuLk3Cm4VwHwyrkX2zXffIKCbEVdoJ3l6 98PlFckNL/bac1NXgxdgzgvJ0jbwfvoMHWGxqD3lfdb33DmaMW3VCeMUuHheYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671866555; a=rsa-sha256; cv=none; b=na+cFbvW3MG6sIltiCwFInS8HSXfxQn7veRKIqj6vM32LGtJjC6u08/5mqDehf8xfhJZ53 G70nWSxK3p+J/ES4vAqYQt1deQtz+jhT1QRtCZSqajDefwkaEwapizlucic/zL0R9f8b9C RQNBRKf9zcG5f70yZXSPdhG/P8//SQOcQhwH4aAIsIYJB9pbzWtQgySTXvxbIS3gHHpnnw lcUlvo4tmRiulizlV+DzTiy2Ob5LRmcCxGqhbpEE5aod8j++Ll6BCII3HjzotvHaVK+Qiv kflglSVe39e7oBOWJGjPb8max5CnHA4xl7MsKBbD8aBjrwbWDD++b8uhOkp5cQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NfFqt6Nqhz14XG; Sat, 24 Dec 2022 07:22:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BO7MYcA083168; Sat, 24 Dec 2022 07:22:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BO7MYUh083167; Sat, 24 Dec 2022 07:22:34 GMT (envelope-from git) Date: Sat, 24 Dec 2022 07:22:34 GMT Message-Id: <202212240722.2BO7MYUh083167@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 149466a516b2 - stable/13 - ping: split the visual part of -f into a new option -. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 149466a516b2561947f7b4e83807b9efa57e9915 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=149466a516b2561947f7b4e83807b9efa57e9915 commit 149466a516b2561947f7b4e83807b9efa57e9915 Author: Piotr Pawel Stefaniak AuthorDate: 2022-04-11 14:58:24 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2022-12-24 06:50:04 +0000 ping: split the visual part of -f into a new option -. Differential Revision: https://reviews.freebsd.org/D34882 (cherry picked from commit d399eb3ef7f8a8189b73d179e07119b30127efb9) --- sbin/ping/main.h | 4 ++-- sbin/ping/ping.8 | 29 ++++++++++++++++++++++++----- sbin/ping/ping.c | 23 +++++++++++++++++------ sbin/ping/ping6.c | 21 ++++++++++++++++----- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/sbin/ping/main.h b/sbin/ping/main.h index 0f987e9a20ae..51a368403bab 100644 --- 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 index 6048bbc6b749..fceff650fbc1 100644 --- a/sbin/ping/ping.8 +++ b/sbin/ping/ping.8 @@ -41,6 +41,7 @@ packets to network hosts .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 @@ packets to network hosts .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 @@ packets to network hosts .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 @@ as .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 @@ option on the socket being used. 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 index 00ac8eadddff..6956b9a68ad2 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -158,6 +158,7 @@ static int options; #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 int srecv; /* receive socket file descriptor */ 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 @@ ping(int argc, char *const *argv) 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 @@ ping(int argc, char *const *argv) err(EX_NOPERM, "-f flag"); } options |= F_FLOOD; + options |= F_DOT; setbuf(stdout, (char *)NULL); break; case 'G': /* Maximum packet size for ping sweep */ @@ -1117,8 +1128,8 @@ pinger(void) } 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); } /* @@ -1238,7 +1249,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) 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, @@ -1412,7 +1423,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) } 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; @@ -1447,7 +1458,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) (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 index b17d5805eed5..74d36f0357f8 100644 --- a/sbin/ping/ping6.c +++ b/sbin/ping/ping6.c @@ -201,6 +201,7 @@ struct tv32 { #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 int srecv; /* receive socket file descriptor */ 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 @@ ping6(int argc, char *argv[]) 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 @@ ping6(int argc, char *argv[]) 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 @@ pinger(void) (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 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr) 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_pack(u_char *buf, int cc, struct msghdr *mhdr) pr_icmph(icp, end); } - if (!(options & F_FLOOD)) { + if (!(options & F_DOT)) { (void)putchar('\n'); if (options & F_VERBOSE) pr_exthdrs(mhdr);