From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 15 12:28:26 2007 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1EF5016A41B for ; Thu, 15 Nov 2007 12:28:26 +0000 (UTC) (envelope-from dd@freebsd.org) Received: from mail.trit.net (mail.trit.net [208.75.88.227]) by mx1.freebsd.org (Postfix) with ESMTP id 0616D13C44B for ; Thu, 15 Nov 2007 12:28:25 +0000 (UTC) (envelope-from dd@freebsd.org) Received: from maverick.qvzn.org (cpe-76-81-49-74.socal.res.rr.com [76.81.49.74]) by mail.trit.net (Postfix) with ESMTP id DAA9936641 for ; Thu, 15 Nov 2007 12:01:13 +0000 (UTC) Received: from maverick.qvzn.org (localhost [127.0.0.1]) by maverick.qvzn.org (8.14.1/8.13.6) with ESMTP id lAFC1DPg012212 for ; Thu, 15 Nov 2007 12:01:13 GMT (envelope-from dd@freebsd.org) Received: (from dima@localhost) by maverick.qvzn.org (8.14.1/8.13.6/Submit) id lAFC1DDt012211 for hackers@freebsd.org; Thu, 15 Nov 2007 12:01:13 GMT (envelope-from dd@freebsd.org) X-Authentication-Warning: maverick.qvzn.org: dima set sender to dd@freebsd.org using -f Date: Thu, 15 Nov 2007 12:01:13 +0000 From: Dima Dorfman To: hackers@freebsd.org Message-ID: <20071115120112.GG1288@beaver.trit.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="h31gzZEtNLTqOjlF" Content-Disposition: inline X-PGP-Key: 69FAE582 (https://www.trit.org/~dima/dima.asc) X-PGP-Fingerprint: B340 8338 7DA3 4D61 7632 098E 0730 055B 69FA E582 User-Agent: mutt-ng/devel-r804 (FreeBSD) Cc: Subject: Patch for ping6 -o X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2007 12:28:26 -0000 --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The ping(8) utility has an -o switch that tells it to exit after receiving the first reply. This is useful, but ping6(8) doesn't have it. Simple patch attached. Comments/reviews/whatnots? I'll commit to HEAD in a few days if I don't hear any objections. -- Dima Dorfman --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ping6.diff" Index: ping6.8 =================================================================== RCS file: /home/ncvs/src/sbin/ping6/ping6.8,v retrieving revision 1.23 diff -u -r1.23 ping6.8 --- ping6.8 10 Feb 2005 09:19:32 -0000 1.23 +++ ping6.8 15 Nov 2007 11:44:31 -0000 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD: src/sbin/ping6/ping6.8,v 1.23 2005/02/10 09:19:32 ru Exp $ .\" -.Dd May 17, 1998 +.Dd November 15, 2007 .Dt PING6 8 .Os .Sh NAME @@ -40,7 +40,7 @@ .Sh SYNOPSIS .Nm .\" without ipsec, or new ipsec -.Op Fl dfHmnNqtvwW +.Op Fl dfHmnNoqtvwW .\" old ipsec .\" .Op Fl AdEfmnNqRtvwW .Bk -words @@ -225,6 +225,8 @@ outgoing interface needs to be specified by .Fl I option. +.It Fl o +Exit successfully after receiving one reply packet. .It Fl p Ar pattern You may specify up to 16 .Dq pad Index: ping6.c =================================================================== RCS file: /home/ncvs/src/sbin/ping6/ping6.c,v retrieving revision 1.31 diff -u -r1.31 ping6.c --- ping6.c 1 Jul 2007 12:08:06 -0000 1.31 +++ ping6.c 15 Nov 2007 11:45:12 -0000 @@ -188,6 +188,7 @@ #define F_NIGROUP 0x40000 #define F_SUPTYPES 0x80000 #define F_NOMINMTU 0x100000 +#define F_ONCE 0x200000 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) u_int options; @@ -344,7 +345,7 @@ #endif /*IPSEC_POLICY_IPSEC*/ #endif while ((ch = getopt(argc, argv, - "a:b:c:dfHg:h:I:i:l:mnNp:qS:s:tvwW" ADDOPTS)) != -1) { + "a:b:c:dfHg:h:I:i:l:mnNop:qS:s:tvwW" ADDOPTS)) != -1) { #undef ADDOPTS switch (ch) { case 'a': @@ -485,6 +486,9 @@ case 'N': options |= F_NIGROUP; break; + case 'o': + options |= F_ONCE; + break; case 'p': /* fill buffer with user pattern */ options |= F_PINGFILLED; fill((char *)datap, optarg); @@ -1164,7 +1168,8 @@ */ pr_pack(packet, cc, &m); } - if (npackets && nreceived >= npackets) + if (( (options & F_ONCE) != 0 && nreceived > 0) || + (npackets > 0 && nreceived >= npackets)) break; } summary(); --h31gzZEtNLTqOjlF--