From owner-freebsd-bugs@FreeBSD.ORG Sat May 17 08:40:04 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3DB781065673 for ; Sat, 17 May 2008 08:40:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 1368B8FC1B for ; Sat, 17 May 2008 08:40:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m4H8e36r077783 for ; Sat, 17 May 2008 08:40:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m4H8e3bp077781; Sat, 17 May 2008 08:40:03 GMT (envelope-from gnats) Resent-Date: Sat, 17 May 2008 08:40:03 GMT Resent-Message-Id: <200805170840.m4H8e3bp077781@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Edwin Groothuis Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D165C1065675 for ; 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 ; 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 ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/123752: [patch] teach /sbin/ping6 about -a X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Edwin Groothuis List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 May 2008 08:40:04 -0000 >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@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: