From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 3 02:18:25 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 61B4216A415 for ; Fri, 3 Nov 2006 02:18:25 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9A05943D45 for ; Fri, 3 Nov 2006 02:18:23 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id kA32ICsA006340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 3 Nov 2006 04:18:19 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.13.8/8.13.8) with ESMTP id kA32I4GL016247; Fri, 3 Nov 2006 04:18:05 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.13.8/8.13.8/Submit) id kA32I3ts016246; Fri, 3 Nov 2006 04:18:03 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Fri, 3 Nov 2006 04:18:03 +0200 From: Giorgos Keramidas To: josh.carroll@psualum.com Message-ID: <20061103021803.GC8508@kobe.laptop> References: <8cb6106e0610311058s7144d38bp2b1dafd114e2b433@mail.gmail.com> <20061102094748.G75543@mignon.ki.iif.hu> <8cb6106e0611021507n6315b629kad8cbbf901343c2@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8cb6106e0611021507n6315b629kad8cbbf901343c2@mail.gmail.com> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.537, required 5, AWL -0.14, BAYES_00 -2.60, DNS_FROM_RFC_ABUSE 0.20, UNPARSEABLE_RELAY 0.00) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-hackers@freebsd.org Subject: Re: sockstat tcp/udp switches 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: Fri, 03 Nov 2006 02:18:25 -0000 On 2006-11-02 15:07, Josh Carroll wrote: > > I haven't tested yet, but I think in the options structure you > >should use : > > > >+ {"ipv6", 0, NULL, '6'}, > > > >instead of: > >+ {"ipv6", 0, NULL, 0}, > > Oops, thanks for catching that. Fixed that in the new patch below. > > >also for portability you should use: > >no_argument or required_argument as a second field.... > > Thank you for the feedback, I've modified that and the new patch is below. Can we have something that doesn't need one option letter for each protocol, protocol family or socket type, please? :) I've tested this patch, and it seems to work ok -- at least much better than having to type: $ sockstat -4 | { read head; echo "$head" ; grep -i tcp; } But I don't particularly like the fact that it grabs two option letters for tcp and udp. Maybe we can add an option like: -P proto Display only sockets of _protocol_ type. Then we can use just two options, similar to the ones netstat(1) uses, to designate a protocol family and a specific protocol within that family :) > --- sockstat.c.orig Thu Nov 2 15:01:16 2006 > +++ sockstat.c Thu Nov 2 15:02:32 2006 > @@ -58,6 +58,7 @@ > #include > #include > #include > +#include > > static int opt_4; /* Show IPv4 sockets */ > static int opt_6; /* Show IPv6 sockets */ > @@ -65,6 +66,8 @@ > static int opt_l; /* Show listening sockets */ > static int opt_u; /* Show Unix domain sockets */ > static int opt_v; /* Verbose mode */ > +static int opt_tcp; /* show tcp */ > +static int opt_udp; /* show udp */ > > static int *ports; > > @@ -584,8 +587,20 @@ > main(int argc, char *argv[]) > { > int o; > + static struct option options[] = { > + {"ipv4", no_argument, NULL, '4'}, > + {"ipv6", no_argument, NULL, '6'}, > + {"connected", no_argument, NULL, 'c'}, > + {"listening", no_argument, NULL, 'l'}, > + {"unix", no_argument, NULL, 'u'}, > + {"verbose", no_argument, NULL, 'v'}, > + {"port", required_argument, NULL, 'p'}, > + {"tcp", no_argument, NULL, 't'}, > + {"udp", no_argument, NULL, 'd'}, > + {NULL, 0, NULL, 0} > + }; > > - while ((o = getopt(argc, argv, "46clp:uv")) != -1) > + while ((o = getopt_long_only(argc, argv, "46clp:uvtd", options, > NULL)) != -1) > switch (o) { > case '4': > opt_4 = 1; > @@ -608,6 +623,12 @@ > case 'v': > ++opt_v; > break; > + case 't': > + opt_tcp = 1; > + break; > + case 'd': > + opt_udp = 1; > + break; > default: > usage(); > } > @@ -618,20 +639,35 @@ > if (argc > 0) > usage(); > > - if (!opt_4 && !opt_6 && !opt_u) > - opt_4 = opt_6 = opt_u = 1; > + if (!opt_4 && !opt_6) { > + opt_4 = opt_6 = 1; > + > + if(!opt_u) { > + if(opt_tcp || opt_udp) > + opt_u = 0; > + } else { > + opt_4 = opt_6 = opt_u = 1; > + } > + } > + > if (!opt_c && !opt_l) > opt_c = opt_l = 1; > > + if(!opt_tcp && !opt_udp) > + opt_tcp = opt_udp = 1; > + > if (opt_4 || opt_6) { > - gather_inet(IPPROTO_TCP); > - gather_inet(IPPROTO_UDP); > + if(opt_tcp) > + gather_inet(IPPROTO_TCP); > + if(opt_udp) > + gather_inet(IPPROTO_UDP); > gather_inet(IPPROTO_DIVERT); > } > if (opt_u) { > gather_unix(SOCK_STREAM); > gather_unix(SOCK_DGRAM); > } > + > getfiles(); > display(); > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"