From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 2 23:07:17 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 2873216A47E for ; Thu, 2 Nov 2006 23:07:17 +0000 (UTC) (envelope-from josh.carroll@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.174]) by mx1.FreeBSD.org (Postfix) with ESMTP id 42F6843D7F for ; Thu, 2 Nov 2006 23:07:13 +0000 (GMT) (envelope-from josh.carroll@gmail.com) Received: by ug-out-1314.google.com with SMTP id o2so242088uge for ; Thu, 02 Nov 2006 15:07:12 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=uH+kzvg645/+dq+UAOuKbkew5lBQuvwIYCualHjJVH/rBaYBWEnaPDSsPkbDXuVWvZm9qcaD6FH77evVFmhVvImkwzoH2R395kHL6xtgyXBPtFJDUFXb8AViRzYt3X5QlYMmGNTcdTw44T3el22hwBhQlkeg7FaM/AqO3lqxEn8= Received: by 10.82.135.13 with SMTP id i13mr513983bud.1162508830727; Thu, 02 Nov 2006 15:07:10 -0800 (PST) Received: by 10.82.163.16 with HTTP; Thu, 2 Nov 2006 15:07:10 -0800 (PST) Message-ID: <8cb6106e0611021507n6315b629kad8cbbf901343c2@mail.gmail.com> Date: Thu, 2 Nov 2006 15:07:10 -0800 From: "Josh Carroll" To: freebsd-hackers@freebsd.org In-Reply-To: <20061102094748.G75543@mignon.ki.iif.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8cb6106e0610311058s7144d38bp2b1dafd114e2b433@mail.gmail.com> <20061102094748.G75543@mignon.ki.iif.hu> Subject: Re: sockstat tcp/udp switches X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: josh.carroll@psualum.com 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 23:07:17 -0000 > 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. Thanks, Josh --- 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();