From edwin@mavetju.org  Sat May 17 08:37:04 2008
Return-Path: <edwin@mavetju.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id D165C1065675
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 May 2008 08:37:04 +0000 (UTC)
	(envelope-from edwin@mavetju.org)
Received: from mail5out.barnet.com.au (mail5.barnet.com.au [202.83.178.78])
	by mx1.freebsd.org (Postfix) with ESMTP id 7CB938FC18
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 May 2008 08:37:04 +0000 (UTC)
	(envelope-from edwin@mavetju.org)
Received: by mail5out.barnet.com.au (Postfix, from userid 1001)
	id 76FD62218A77; Sat, 17 May 2008 18:37:03 +1000 (EST)
Received: from mail5auth.barnet.com.au (mail5.barnet.com.au [202.83.178.78])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail5auth.barnet.com.au", Issuer "*.barnet.com.au" (verified OK))
	by mail5.barnet.com.au (Postfix) with ESMTP id 36D7521B2D9A
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 May 2008 18:37:03 +1000 (EST)
Received: from k7.mavetju (k7.mavetju.org [10.251.1.18])
	by mail5auth.barnet.com.au (Postfix) with ESMTP id A98E722189E1
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 May 2008 18:37:02 +1000 (EST)
Received: by k7.mavetju (Postfix, from userid 1001)
	id 6E00D7DA; Sat, 17 May 2008 18:37:02 +1000 (EST)
Message-Id: <20080517083702.6E00D7DA@k7.mavetju>
Date: Sat, 17 May 2008 18:37:02 +1000 (EST)
From: Edwin Groothuis <edwin@mavetju.org>
Reply-To: Edwin Groothuis <edwin@mavetju.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] teach /sbin/ping6 about -a
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         123752
>Category:       bin
>Synopsis:       [patch] teach ping6(8) about -a
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    matteo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 17 08:40:03 UTC 2008
>Closed-Date:    Sun Aug 31 18:09:52 UTC 2008
>Last-Modified:  Sun Aug 31 18:10:15 UTC 2008
>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@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,10 @@ 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) {
+	    "b: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:
State-Changed-From-To: open->patched 
State-Changed-By: matteo 
State-Changed-When: Mar 26 Ago 2008 14:35:22 UTC 
State-Changed-Why:  
I chose a simpler approach and just assigned -e to the new option. 
MFC coming in two days. 


Responsible-Changed-From-To: freebsd-bugs->matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Mar 26 Ago 2008 14:35:22 UTC 
Responsible-Changed-Why:  
I chose a simpler approach and just assigned -e to the new option. 
MFC coming in two days. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123752 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/123752: commit references a PR
Date: Tue, 26 Aug 2008 14:34:39 +0000 (UTC)

 matteo      2008-08-26 14:34:09 UTC
 
   FreeBSD src repository
 
   Modified files:
     sbin/ping6           ping6.8 ping6.c 
   Log:
   SVN rev 182195 on 2008-08-26 14:34:09Z by matteo
   
   Implement audible support similar to ping(8) -a option. Since -a was already taken, I chose -e (no real argument for this) but I'm willing to change to a different character if needed/desired.
   
   PR:     bin/123752 (inspired by)
   MFC after:      2 days
   
   Revision  Changes    Path
   1.26      +8 -2      src/sbin/ping6/ping6.8
   1.35      +8 -1      src/sbin/ping6/ping6.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: matteo 
State-Changed-When: Dom 31 Ago 2008 18:09:21 UTC 
State-Changed-Why:  
committed to RELENG_7 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123752 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/123752: commit references a PR
Date: Sun, 31 Aug 2008 18:07:42 +0000 (UTC)

 matteo      2008-08-31 18:07:15 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sbin/ping6           ping6.8 ping6.c 
   Log:
   SVN rev 182554 on 2008-08-31 18:07:15Z by matteo
   
   MFC r182195, r182269, r182276
   
   Implement -R support, similar to ping(8)'s -A and -r support, similar
   to ping(8)'s -a.
   
   PR:             bin/123752 (inspired by)
   
   Revision   Changes    Path
   1.23.10.2  +18 -2     src/sbin/ping6/ping6.8
   1.31.2.2   +19 -2     src/sbin/ping6/ping6.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
