From owner-cvs-src@FreeBSD.ORG  Sun Nov 12 17:41:02 2006
Return-Path: <owner-cvs-src@FreeBSD.ORG>
X-Original-To: cvs-src@freebsd.org
Delivered-To: cvs-src@freebsd.org
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id A116E16A40F;
	Sun, 12 Nov 2006 17:41:02 +0000 (UTC)
	(envelope-from keramida@freebsd.org)
Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 583C143D97;
	Sun, 12 Nov 2006 17:40:53 +0000 (GMT)
	(envelope-from keramida@freebsd.org)
Received: from kobe.laptop (host155-42.pool8174.interbusiness.it
	[81.74.42.155] (may be forged)) (authenticated bits=128)
	by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id kACHeCfe011154
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT);
	Sun, 12 Nov 2006 19:40:21 +0200
Received: from kobe.laptop (kobe.laptop [127.0.0.1])
	by kobe.laptop (8.13.8/8.13.8) with ESMTP id kACHe58U004405;
	Sun, 12 Nov 2006 18:40:06 +0100 (CET)
	(envelope-from keramida@freebsd.org)
Received: (from keramida@localhost)
	by kobe.laptop (8.13.8/8.13.8/Submit) id kACHe5IX004404;
	Sun, 12 Nov 2006 18:40:05 +0100 (CET)
	(envelope-from keramida@freebsd.org)
Date: Sun, 12 Nov 2006 18:40:05 +0100
From: Giorgos Keramidas <keramida@freebsd.org>
To: src-committers@freebsd.org, cvs-src@freebsd.org, cvs-all@freebsd.org
Message-ID: <20061112174004.GB4237@kobe.laptop>
References: <200611112211.kABMBsHp073602@repoman.freebsd.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <200611112211.kABMBsHp073602@repoman.freebsd.org>
X-Hellug-MailScanner: Found to be clean
X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.463,
	required 5, autolearn=not spam, BAYES_00 -2.60,
	FORGED_RCVD_HELO 0.14, UNPARSEABLE_RELAY 0.00)
X-Hellug-MailScanner-From: keramida@freebsd.org
X-Spam-Status: No
Cc: 
Subject: Re: cvs commit: src/usr.bin/sockstat sockstat.1 sockstat.c
X-BeenThere: cvs-src@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: CVS commit messages for the src tree <cvs-src.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/cvs-src>,
	<mailto:cvs-src-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/cvs-src>
List-Post: <mailto:cvs-src@freebsd.org>
List-Help: <mailto:cvs-src-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/cvs-src>,
	<mailto:cvs-src-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 12 Nov 2006 17:41:02 -0000

On 2006-11-11 22:11, Giorgos Keramidas <keramida@freebsd.org> wrote:
> keramida    2006-11-11 22:11:54 UTC
> 
>   FreeBSD src repository (doc committer)
> 
>   Modified files:
>     usr.bin/sockstat     sockstat.1 sockstat.c 
>   Log:
>   Add support for filtering sockets by protocol type.  The default
>   behavior of sockstat(1) will still be to show "udp", "tcp" and
>   "divert" protocols, but we can now provide a (comma-separated)
>   list of protocols, as in:
>   
>       % sockstat -P tcp
>   
>   to list only TCP sockets, or we can filter more than one protocol
>   by separating the protocol names with a comma:
>   
>       % sockstat -P tcp,udp
>   
>   Protocol names are parsed with getprotobyname(3), so any protocol
>   whose name is listed in `/etc/protocols' should work fine.
>   
>   Submitted by:   Josh Carroll <josh.carroll@psualum.com>
>   Approved by:    des
>   
>   Revision  Changes    Path
>   1.21      +12 -2     src/usr.bin/sockstat/sockstat.1
>   1.14      +115 -12   src/usr.bin/sockstat/sockstat.c

This commit breaks sockstat when only *one* of -4 or -6 is used.
My apologies for not testing the changes more thoroughly, everyone :(

I've already emailed a followup patch to des@ for review, which you can
also find attached below.  When I get his approval, I'll commit it to
CVS too:

%%%
diff -r b717d3e25bc0 -r a894939b8792 usr.bin/sockstat/sockstat.c
--- a/usr.bin/sockstat/sockstat.c	Sun Nov 12 16:33:09 2006 +0100
+++ b/usr.bin/sockstat/sockstat.c	Sun Nov 12 18:34:29 2006 +0100
@@ -714,12 +714,17 @@ main(int argc, char *argv[])
 		usage();
 
 	/*
-	 * If protos_defined remains -1, no -P was provided, so we have to
-	 * set up the default protocol list in protos[] first.
+	 * If no -4, -6, -u or -P option was specified, use the default list
+	 * of protocols *and* UNIX domain sockets.  Otherwise, if only one
+	 * of -4 and -6 was specified and we don't have a protocol list yet
+	 * (i.e. because no -P option was present), still use the default
+	 * protocol list (to list sockets of the respective address family).
 	 */
 	if (!opt_4 && !opt_6 && !opt_u && protos_defined == -1) {
 		opt_u = 1;
 		protos_defined = set_default_protos();
+	} else if ((opt_4 || opt_6) && protos_defined == -1) {
+		protos_defined = set_default_protos();
 	}
 
 	if (!opt_4 && !opt_6)
%%%