bin/123752: [patch] teach /sbin/ping6 about -a
Edwin Groothuis
edwin at mavetju.org
Sat May 17 08:40:04 UTC 2008
>Number: 123752
>Category: bin
>Synopsis: [patch] teach /sbin/ping6 about -a
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat May 17 08:40:03 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Edwin Groothuis
>Release: FreeBSD 6.3-RELEASE-p2 i386
>Organization:
-
>Environment:
System: FreeBSD k7.mavetju 6.3-RELEASE-p2 FreeBSD 6.3-RELEASE-p2 #0: Mon May 12 11:35:35 EST 2008 edwin at k7.mavetju:/usr/src/sys/i386/compile/k7 i386
>Description:
Teach /sbin/ping6 about the -a which is known from /sbin/ping
>How-To-Repeat:
>Fix:
diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8
index 7fd4c33..b693c34 100644
--- a/sbin/ping6/ping6.8
+++ b/sbin/ping6/ping6.8
@@ -40,7 +40,7 @@ packets to network hosts
.Sh SYNOPSIS
.Nm
.\" without ipsec, or new ipsec
-.Op Fl dfHmnNoqtvwW
+.Op Fl adfHmnNoqtvwW
.\" old ipsec
.\" .Op Fl AdEfmnNqRtvwW
.Bk -words
@@ -107,6 +107,9 @@ The options are as follows:
.\" .It Fl A
.\" Enables transport-mode IPsec authentication header
.\" (experimental).
+.It Fl a
+Audible. Include a bell (ASCII 0x07) character in the output when
+an ICMP6_ECHO_REPLY is received.
.It Fl a Ar addrtype
Generate ICMPv6 Node Information Node Addresses query, rather than echo-request.
.Ar addrtype
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 6fe487c..c87ec34 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -236,6 +236,11 @@ double tmax = 0.0; /* maximum round trip time */
double tsum = 0.0; /* sum of all times, for doing average */
double tsumsq = 0.0; /* sum of all times squared, for std. dev. */
+/* audio */
+int aflag = 0; /* Give a beep or not */
+#define AFLAG_BEEPONREPLY 1
+#define AFLAG_BEEPONFAILURE 2
+
/* for node addresses */
u_short naflags;
@@ -344,53 +349,11 @@ main(argc, argv)
#define ADDOPTS "AE"
#endif /*IPSEC_POLICY_IPSEC*/
#endif
+ opterr = 0; /* To prevent warnings about the -a construction */
while ((ch = getopt(argc, argv,
- "a:b:c:dfHg:h:I:i:l:mnNop:qS:s:tvwW" ADDOPTS)) != -1) {
+ "Ab:c:dfHg:h:I:i:l:mnNop:qS:s:tvwW" ADDOPTS)) != -1) {
#undef ADDOPTS
switch (ch) {
- case 'a':
- {
- char *cp;
-
- options &= ~F_NOUSERDATA;
- options |= F_NODEADDR;
- for (cp = optarg; *cp != '\0'; cp++) {
- switch (*cp) {
- case 'a':
- naflags |= NI_NODEADDR_FLAG_ALL;
- break;
- case 'c':
- case 'C':
- naflags |= NI_NODEADDR_FLAG_COMPAT;
- break;
- case 'l':
- case 'L':
- naflags |= NI_NODEADDR_FLAG_LINKLOCAL;
- break;
- case 's':
- case 'S':
- naflags |= NI_NODEADDR_FLAG_SITELOCAL;
- break;
- case 'g':
- case 'G':
- naflags |= NI_NODEADDR_FLAG_GLOBAL;
- break;
- case 'A': /* experimental. not in the spec */
-#ifdef NI_NODEADDR_FLAG_ANYCAST
- naflags |= NI_NODEADDR_FLAG_ANYCAST;
- break;
-#else
- errx(1,
-"-a A is not supported on the platform");
- /*NOTREACHED*/
-#endif
- default:
- usage();
- /*NOTREACHED*/
- }
- }
- break;
- }
case 'b':
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
errno = 0;
@@ -565,6 +528,78 @@ main(argc, argv)
#endif /*IPSEC_POLICY_IPSEC*/
#endif /*IPSEC*/
default:
+ /*
+ * This is to differentiate between -a (audible bell)
+ * and the -a addrtype (Node Information Node
+ * Addresses query). The rules are:
+ * If there is no next argv, then throw an error.
+ * If the following argument starts with a -, it is -a.
+ * If the following argument is the last argument,
+ * then it is -a.
+ * Otherwise it's a -a addrtype.
+ */
+ if (optopt == 'a') {
+ char *cp;
+
+ if (optind == argc) {
+ usage();
+ /*NOTREACHED*/
+ }
+ if (argv[optind][0] == '-') {
+ aflag = AFLAG_BEEPONREPLY;
+ break;
+ }
+ if (optind == argc - 1) {
+ aflag = AFLAG_BEEPONREPLY;
+ break;
+ }
+
+ options &= ~F_NOUSERDATA;
+ options |= F_NODEADDR;
+ for (cp = argv[optind]; *cp != '\0'; cp++) {
+ switch (*cp) {
+ case 'a':
+ naflags |=
+ NI_NODEADDR_FLAG_ALL;
+ break;
+ case 'c':
+ case 'C':
+ naflags |=
+ NI_NODEADDR_FLAG_COMPAT;
+ break;
+ case 'l':
+ case 'L':
+ naflags |=
+ NI_NODEADDR_FLAG_LINKLOCAL;
+ break;
+ case 's':
+ case 'S':
+ naflags |=
+ NI_NODEADDR_FLAG_SITELOCAL;
+ break;
+ case 'g':
+ case 'G':
+ naflags |=
+ NI_NODEADDR_FLAG_GLOBAL;
+ break;
+ case 'A': /* experimental. not in the spec */
+#ifdef NI_NODEADDR_FLAG_ANYCAST
+ naflags |=
+ NI_NODEADDR_FLAG_ANYCAST;
+ break;
+#else
+ errx(1,
+"-a A is not supported on the platform");
+ /*NOTREACHED*/
+#endif
+ default:
+ usage();
+ /*NOTREACHED*/
+ }
+ }
+ break;
+ } /* Check for -a usage */
+
usage();
/*NOTREACHED*/
}
@@ -1552,6 +1587,8 @@ pr_pack(buf, cc, mhdr)
if (options & F_FLOOD)
(void)write(STDOUT_FILENO, &BSPACE, 1);
else {
+ if (aflag == AFLAG_BEEPONREPLY)
+ (void)printf("%c", 7);
(void)printf("%d bytes from %s, icmp_seq=%u", cc,
pr_addr(from, fromlen), seq);
(void)printf(" hlim=%d", hoplim);
@@ -2760,7 +2797,7 @@ usage()
"A"
#endif
"usage: ping6 [-"
- "d"
+ "ad"
#if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC)
"E"
#endif
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list