From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 2 08:53:46 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 7D33016A403 for ; Thu, 2 Nov 2006 08:53:46 +0000 (UTC) (envelope-from mohacsi@niif.hu) Received: from mail.ki.iif.hu (ki.iif.hu [193.6.222.240]) by mx1.FreeBSD.org (Postfix) with ESMTP id 05E6543D53 for ; Thu, 2 Nov 2006 08:53:45 +0000 (GMT) (envelope-from mohacsi@niif.hu) Received: by mail.ki.iif.hu (Postfix, from userid 1003) id 4C61D55D8; Thu, 2 Nov 2006 09:53:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.ki.iif.hu (Postfix) with ESMTP id 4A8EA55CD; Thu, 2 Nov 2006 09:53:43 +0100 (CET) Date: Thu, 2 Nov 2006 09:53:43 +0100 (CET) From: Mohacsi Janos X-X-Sender: mohacsi@mignon.ki.iif.hu To: josh.carroll@psualum.com In-Reply-To: <8cb6106e0610311058s7144d38bp2b1dafd114e2b433@mail.gmail.com> Message-ID: <20061102094748.G75543@mignon.ki.iif.hu> References: <8cb6106e0610311058s7144d38bp2b1dafd114e2b433@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: josh.carroll@gmail.com, 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: Thu, 02 Nov 2006 08:53:46 -0000 Hi, 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}, also for portability you should use: no_argument or required_argument as a second field.... Regards, Janos Mohacsi On Tue, 31 Oct 2006, Josh Carroll wrote: > All, > > I have added two options to the sockstat command to list tcp and/or udp > sockets. > > -t ([-]-tcp) : display tcp sockets > -d ([-]-udp) : display udp sockets > > The previous command line options are unchanged, although I did change > the use of getopt to getopt_long_only and added long options for the > other command line switches. > > I know the same effect can be accomplished with grep, but figured it'd > be nice to have it included in the sockstat command line. > > Thoughts/comments? Patch is below. patch with: > > patch -p0 < /path/to/sockstat.patch > > from the /usr/src/usr.bin/sockstat directory. > > Please cc: me on replies, as I am not subscribed to the hackers mailing list. > > Thanks! > Josh > > > > --- sockstat.c.orig Tue Oct 31 10:51:40 2006 > +++ sockstat.c Tue Oct 31 10:51:58 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", 0, NULL, '4'}, > + {"ipv6", 0, NULL, 0}, > + {"connected", 0, NULL, 'c'}, > + {"listening", 0, NULL, 'l'}, > + {"unix", 0, NULL, 'u'}, > + {"verbose", 0, NULL, 'v'}, > + {"port", 1, NULL, 'p'}, > + {"tcp", 0, NULL, 't'}, > + {"udp", 0, 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" >