From nobody Mon Apr 18 17:13:53 2022 X-Original-To: dev-commits-src-main@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 AB10F11DE0EA; Mon, 18 Apr 2022 17:13:53 +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 4KhtnY4Qt0z3KY3; Mon, 18 Apr 2022 17:13:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650302033; 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=CAPTL4GExpUHE8w2sxnkBWlMonT6wPTaMdBmEYTqv7E=; b=LzsUOrSkpUufXH1YeoEbu4aqCK/5s2a+FG5ucV/jgMuRaoTzN9iLqbG/IRyacB+WDC3bV6 sMKwmHsUT4a95stX1FuqQfd7Vqbbq0/XISUZ9wJBFDVFjWExzuBsNNNghGEh0/aREce8/a 5ut9uTxMg3E4CgwZDPfHeuuIZ8fo+cos3q5rWqHY92pjFdLDIdY7uimknHD+wIjHIdf+Vc +6Frr/9vYKvv0XdlwU22QzIgHSZKLdIWzb5O0p7HKGK0jEX5Uwh/vNFk/aYUaL3e2KwRq9 +3mrmNqQhpszPtQMxx7rQX2LLMzyZ1hIONvAvwpii9yEovOFFqBMX/qO53SJdA== 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 77B7916BBB; Mon, 18 Apr 2022 17:13:53 +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 23IHDrKL039735; Mon, 18 Apr 2022 17:13:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23IHDrjB039734; Mon, 18 Apr 2022 17:13:53 GMT (envelope-from git) Date: Mon, 18 Apr 2022 17:13:53 GMT Message-Id: <202204181713.23IHDrjB039734@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: d399eb3ef7f8 - main - ping: split the visual part of -f into a new option -. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: d399eb3ef7f8a8189b73d179e07119b30127efb9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650302033; 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=CAPTL4GExpUHE8w2sxnkBWlMonT6wPTaMdBmEYTqv7E=; b=iUjlA1iLv2lEBFX93ffnetlhadTfLfGTZN+m7SUgr4KjicDB+USgFcJ+ljRlv3EPH0Kzhr gKpchvMRJ8IfxpqohWIDhgcJxKXMfFa9VtM4xcVtBrdMQeWY80XF87NfoPBDrlHbmx+ubA 1gFI8JfcbriOFSh1RDAToDMhD3gaGBuPGVKXf4uX79NknHYsTZOuk5sAtoxLfIEqw9peMx NwKf3pTUiGrOJU+TPMEy9ZaUGyj3jd4VRZcg6BonU2h/ur2M/CtlxYeoTHbzoRH684pTJ8 2wIfE5lBXlkrc3NcEGfErDqwLC3Qvvb7bd5MZsDQh6Lb8Die6V57ekLogCsriQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650302033; a=rsa-sha256; cv=none; b=aTqAfrq/Ft7n6Us8OfSEoP66+swoYf7fPrFxQxsQWVw3hTRCvTE2dmBjY3qdV/X3pot6Mt T4YeO7jI/POIS4w8NA6hS1peczh5b+WTrIK6UyXEM0oOqichkEcwY3/gboA6ZVtvMNSv8d Y2fl1lmApi1pW0MfNGGERilmbqN6HWuQO8VzX4Dx7yPxueQC3AkmlJPl8++mIPyUpd1YDd j8GlFvQWKtn5S7T7ImlMAMFMcJv/k9V3W1rFePH5HvkS4KKqvEPLzHCrDD+ex/1Q7TlpR9 Vr20d81exBzlFI3GtRC6/DTdPDnen4QCz+CJUTwwEaQpZh6YVRanDY8yzA7nfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=d399eb3ef7f8a8189b73d179e07119b30127efb9 commit d399eb3ef7f8a8189b73d179e07119b30127efb9 Author: Piotr Pawel Stefaniak AuthorDate: 2022-04-11 14:58:24 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2022-04-18 16:10:50 +0000 ping: split the visual part of -f into a new option -. After this, we'll be able to ping a host and not spam the terminal, and no flooding will have to be involved. I've been doing this under Linux as ping -fi1 host. Reviewed by: rpokala, Pau Amma Differential Revision: https://reviews.freebsd.org/D34882 --- 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 b868122a7b71..cd9c020382da 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 be535f72146a..cfef81f76099 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 */ @@ -1114,8 +1125,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); } /* @@ -1220,7 +1231,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, @@ -1361,7 +1372,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; @@ -1396,7 +1407,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 76a96f0631ff..e780129c928d 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);