From ben@Darkside.stagecraft.net Sat Jul 31 07:54:35 1999
Return-Path: <ben@Darkside.stagecraft.net>
Received: from Darkside.stagecraft.net (Ben.Aspi.net [207.228.215.73])
	by hub.freebsd.org (Postfix) with ESMTP id 754D614DC9
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 31 Jul 1999 07:54:20 -0700 (PDT)
	(envelope-from ben@Darkside.stagecraft.net)
Received: (from ben@localhost)
	by Darkside.stagecraft.net (8.9.2/8.9.1) id KAA32545;
	Sat, 31 Jul 1999 10:52:09 -0400 (EDT)
	(envelope-from ben)
Message-Id: <199907311452.KAA32545@Darkside.stagecraft.net>
Date: Sat, 31 Jul 1999 10:52:09 -0400 (EDT)
From: Benjamin April <ben@destek.net>
Sender: ben@Darkside.stagecraft.net
Reply-To: ben@destek.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: netstat -c 
X-Send-Pr-Version: 3.2

>Number:         12898
>Category:       bin
>Synopsis:       Added a command-line switch to netstat to output the number of routes in the routing table.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 31 08:00:01 PDT 1999
>Closed-Date:    Thu Jun 14 06:02:20 PDT 2001
>Last-Modified:  Thu Jun 14 06:03:18 PDT 2001
>Originator:     Ben April
>Release:        FreeBSD 3.1-RELEASE i386
>Organization:
The Destek Group, Inc.
>Environment:

	This has been tested on 3.1-RELEASE and 3.2-RELEASE running
	gated.

>Description:

	Basicly runnign netstat -c is a faster version of
	netstat -rn|wc. -c follows about the same code path as
	-rn does but -c only outputs the total number of routes
	in each type(IP/appletak ect...)

>How-To-Repeat:

	N/A

>Fix:

*** main.c	Sun Jul 25 22:02:16 1999
--- ./main.c.old	Sat Jul 24 12:12:53 1999
***************
*** 221,227 ****
  
  	af = AF_UNSPEC;
  
! 	while ((ch = getopt(argc, argv, "Aabcdf:ghI:iM:mN:np:rstuw:")) != -1)
  		switch(ch) {
  		case 'A':
  			Aflag = 1;
--- 221,227 ----
  
  	af = AF_UNSPEC;
  
! 	while ((ch = getopt(argc, argv, "Aabdf:ghI:iM:mN:np:rstuw:")) != -1)
  		switch(ch) {
  		case 'A':
  			Aflag = 1;
***************
*** 232,241 ****
  		case 'b':
  			bflag = 1;
  			break;
- 		case 'c':
- 			cflag = 1;
- 			nflag = 1;
- 			break;
  		case 'd':
  			dflag = 1;
  			break;
--- 232,237 ----
***************
*** 381,391 ****
  		intpr(interval, nl[N_IFNET].n_value);
  		exit(0);
  	}
- 	if (cflag) {
- 		kread(0, 0, 0);
- 		routecount(nl[N_RTREE].n_value);
- 		exit(0);	
- 	}
  	if (rflag) {
  		kread(0, 0, 0);
  		if (sflag)
--- 377,382 ----
***************
*** 571,582 ****
  static void
  usage()
  {
! 	(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
  "usage: netstat [-Aan] [-f address_family] [-M core] [-N system]",
  "       netstat [-bdghimnrs] [-f address_family] [-M core] [-N system]",
  "       netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
! "       netstat [-M core] [-N system] [-p protocol]",
! "       netstat [-c]");
  	exit(1);
  }
  
--- 562,572 ----
  static void
  usage()
  {
! 	(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
  "usage: netstat [-Aan] [-f address_family] [-M core] [-N system]",
  "       netstat [-bdghimnrs] [-f address_family] [-M core] [-N system]",
  "       netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
! "       netstat [-M core] [-N system] [-p protocol]");
  	exit(1);
  }
  

*** netstat.1	Mon Jul 26 07:52:39 1999
--- ./netstat.1.old	Sat Jul 24 13:21:41 1999
***************
*** 58,65 ****
  .Op Fl p Ar protocol
  .Op Fl M Ar core
  .Op Fl N Ar system
- .Nm netstat
- .Op Fl c
  .Sh DESCRIPTION
  The
  .Nm netstat
--- 58,63 ----
***************
*** 94,107 ****
  .Fl i
  , as described below),
  show the number of bytes in and out.
- .It Fl c
- prints the number of routes in the kernel table to stdout. 
- A faster equivlant to 
- .Nm netstat 
- .Fl rn
- |
- .Nm wc
- .Fl l
  .It Fl d
  With either interface display (option
  .Fl i
--- 92,97 ----


*** route.c	Sat Jul 24 14:16:41 1999
--- ./route.c.old	Sat Jul 24 12:10:49 1999
***************
*** 114,131 ****
  struct	radix_node_head *rt_tables[AF_MAX+1];
  
  int	NewTree = 0;
- int	total = 0;
  
  static struct sockaddr *kgetsa __P((struct sockaddr *));
  static void p_tree __P((struct radix_node *));
- static void c_tree __P((struct radix_node *));
  static void p_rtnode __P((void));
  static void ntreestuff __P((void));
  static void np_rtentry __P((struct rt_msghdr *));
  static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
  static void p_flags __P((int, char *));
  static void p_rtentry __P((struct rtentry *));
- static void c_rtentry __P((struct rtentry *));
  static u_long forgemask __P((u_long));
  static void domask __P((char *, u_long, u_long));
  
--- 114,128 ----
***************
*** 880,968 ****
  			*p += ('A' - 'a');
  			break;
  		}
- }
- 
- void
- routecount(rtree) 
-         u_long rtree;
- {
-         struct radix_node_head *rnh, head;
-         int i;
- 
-         printf("Routing tables\n");
- 
-         if (Aflag == 0 && NewTree)
-                 ntreestuff();
-         else {
-                 if (rtree == 0) {
-                         printf("rt_tables: symbol not in namelist\n");
-                         return;
-                 }
- 
-                 kget(rtree, rt_tables);
-                 for (i = 0; i <= AF_MAX; i++) {
-                         if ((rnh = rt_tables[i]) == 0)
-                                 continue;
-                         kget(rnh, head);
-                         if (i == AF_UNSPEC) {
-                                 if (Aflag && af == 0) {
-                                         printf("Netmasks:\n");
-                                         c_tree(head.rnh_treetop);
-                                 }
-                         } else if (af == AF_UNSPEC || af == i) {
-                                 pr_family(i);
-                                 do_rtent = 1;
- 				total=0;
-                                 c_tree(head.rnh_treetop);
- 				printf("%d Routes\n",total);
-                         }
-                 }
-         }
- }
- 
- static void
- c_tree(rn)
-         struct radix_node *rn;
- {
- 
- again:
-         kget(rn, rnode);
-         if (rnode.rn_b < 0) {
-                 if (Aflag)
-                         printf("%-8.8lx ", (u_long)rn);
-                 if (rnode.rn_flags & RNF_ROOT) {
-                         if (Aflag)
-                                 printf("(root node)%s",
-                                     rnode.rn_dupedkey ? " =>\n" : "\n");
-                 } else if (do_rtent) {
-                         kget(rn, rtentry);
-                         c_rtentry(&rtentry);
-                         if (Aflag)
-                                 p_rtnode();
-                 } else {
-                         p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
-                                    NULL, 0, 44);
-                         putchar('\n');
-                 }
-                 if ((rn = rnode.rn_dupedkey))
-                         goto again;
-         } else {
-                 if (Aflag && do_rtent) {
-                         printf("%-8.8lx ", (u_long)rn);
-                         p_rtnode();
-                 }
-                 rn = rnode.rn_r;
-                 c_tree(rnode.rn_l);
-                 c_tree(rn);
-         }
- }
- 
- 
- static void
- c_rtentry(rt)
- 	register struct rtentry *rt;
- {
- 			if (!(rt->rt_parent && !aflag)) {
- 			++total;
- 			}
  }
--- 877,880 ----


	

>Release-Note:
>Audit-Trail:

From: Bill Fumerola <billf@jade.chc-chimes.com>
To: Benjamin April <ben@destek.net>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12898: netstat -c 
Date: Sat, 31 Jul 1999 10:45:23 -0400 (EDT)

 On Sat, 31 Jul 1999, Benjamin April wrote:
 
 > *** main.c	Sun Jul 25 22:02:16 1999
 > --- ./main.c.old	Sat Jul 24 12:12:53 1999
 
 This patch is reversed.
 
 

From: Ben April <ben@test.destek.net>
To: freebsd-gnats-submit@freebsd.org, ben@destek.net
Cc:  
Subject: Re: bin/12898: Added a command-line switch to netstat to output the 
 number of routes in the routing table.
Date: Tue, 17 Aug 1999 10:28:45 -0400

 The diffs done correctly.
 
 --- main.c.old  Sat Jul 24 12:12:53 1999
 +++ main.c      Sun Jul 25 22:02:16 1999
 @@ -221,7 +221,7 @@
 
         af = AF_UNSPEC;
 
 -       while ((ch = getopt(argc, argv, "Aabdf:ghI:iM:mN:np:rstuw:")) !=
 -1)
 +       while ((ch = getopt(argc, argv, "Aabcdf:ghI:iM:mN:np:rstuw:"))
 != -1)
                 switch(ch) {
                 case 'A':
                         Aflag = 1;
 @@ -232,6 +232,10 @@
                 case 'b':
                         bflag = 1;
                         break;
 +               case 'c':
 +                       cflag = 1;
 +                       nflag = 1;
 +                       break;
                 case 'd':
                         dflag = 1;
                         break;
 @@ -377,6 +381,11 @@
                 intpr(interval, nl[N_IFNET].n_value);
                 exit(0);
         }
 +       if (cflag) {
 +               kread(0, 0, 0);
 +               routecount(nl[N_RTREE].n_value);
 +               exit(0);
 +       }
         if (rflag) {
                 kread(0, 0, 0);
                 if (sflag)
 @@ -562,11 +571,12 @@
  static void
  usage()
  {
 -       (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
 +       (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
  "usage: netstat [-Aan] [-f address_family] [-M core] [-N system]",
  "       netstat [-bdghimnrs] [-f address_family] [-M core] [-N
 system]",
  "       netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
 
 -"       netstat [-M core] [-N system] [-p protocol]");
 +"       netstat [-M core] [-N system] [-p protocol]",
 +"       netstat [-c]");
         exit(1);
  }
 
 --- netstat.1.old       Sat Jul 24 13:21:41 1999
 +++ netstat.1   Mon Jul 26 07:52:39 1999
 @@ -58,6 +58,8 @@
  .Op Fl p Ar protocol
  .Op Fl M Ar core
  .Op Fl N Ar system
 +.Nm netstat
 +.Op Fl c
  .Sh DESCRIPTION
  The
  .Nm netstat
 @@ -92,6 +94,14 @@
  .Fl i
  , as described below),
  show the number of bytes in and out.
 +.It Fl c
 +prints the number of routes in the kernel table to stdout.
 +A faster equivlant to
 +.Nm netstat
 +.Fl rn
 +|
 +.Nm wc
 +.Fl l
  .It Fl d
  With either interface display (option
  .Fl i
 
 --- route.c.old Sat Jul 24 12:10:49 1999
 +++ route.c     Sat Jul 24 14:16:41 1999
 @@ -114,15 +114,18 @@
  struct radix_node_head *rt_tables[AF_MAX+1];
 
  int    NewTree = 0;
 +int    total = 0;
 
  static struct sockaddr *kgetsa __P((struct sockaddr *));
  static void p_tree __P((struct radix_node *));
 +static void c_tree __P((struct radix_node *));
  static void p_rtnode __P((void));
  static void ntreestuff __P((void));
  static void np_rtentry __P((struct rt_msghdr *));
  static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int,
 int));
  static void p_flags __P((int, char *));
  static void p_rtentry __P((struct rtentry *));
 +static void c_rtentry __P((struct rtentry *));
  static u_long forgemask __P((u_long));
  static void domask __P((char *, u_long, u_long));
 
 @@ -877,4 +880,89 @@
                         *p += ('A' - 'a');
                         break;
                 }
 +}
 +
 +void
 +routecount(rtree)
 +        u_long rtree;
 +{
 +        struct radix_node_head *rnh, head;
 +        int i;
 +
 +        printf("Routing tables\n");
 +
 +        if (Aflag == 0 && NewTree)
 +                ntreestuff();
 +        else {
 +                if (rtree == 0) {
 +                        printf("rt_tables: symbol not in namelist\n");
 +                        return;
 +                }
 +
 +                kget(rtree, rt_tables);
 +                for (i = 0; i <= AF_MAX; i++) {
 +                        if ((rnh = rt_tables[i]) == 0)
 +                                continue;
 +                        kget(rnh, head);
 +                        if (i == AF_UNSPEC) {
 +                                if (Aflag && af == 0) {
 +                                        printf("Netmasks:\n");
 +                                        c_tree(head.rnh_treetop);
 +                                }
 +                        } else if (af == AF_UNSPEC || af == i) {
 +                                pr_family(i);
 +                                do_rtent = 1;
 +                               total=0;
 +                                c_tree(head.rnh_treetop);
 +                               printf("%d Routes\n",total);
 +                        }
 +                }
 +        }
 +}
 +
 +static void
 +c_tree(rn)
 +        struct radix_node *rn;
 +{
 +
 +again:
 +        kget(rn, rnode);
 +        if (rnode.rn_b < 0) {
 +                if (Aflag)
 +                        printf("%-8.8lx ", (u_long)rn);
 +                if (rnode.rn_flags & RNF_ROOT) {
 +                        if (Aflag)
 +                                printf("(root node)%s",
 +                                    rnode.rn_dupedkey ? " =>\n" :
 "\n");
 +                } else if (do_rtent) {
 +                        kget(rn, rtentry);
 +                        c_rtentry(&rtentry);
 +                        if (Aflag)
 +                                p_rtnode();
 +                } else {
 +                        p_sockaddr(kgetsa((struct sockaddr
 *)rnode.rn_key),
 +                                   NULL, 0, 44);
 +                        putchar('\n');
 +                }
 +                if ((rn = rnode.rn_dupedkey))
 +                        goto again;
 +        } else {
 +                if (Aflag && do_rtent) {
 +                        printf("%-8.8lx ", (u_long)rn);
 +                        p_rtnode();
 +                }
 +                rn = rnode.rn_r;
 +                c_tree(rnode.rn_l);
 +                c_tree(rn);
 +        }
 +}
 +
 +
 +static void
 +c_rtentry(rt)
 +       register struct rtentry *rt;
 +{
 +                       if (!(rt->rt_parent && !aflag)) {
 +                       ++total;
 +                       }
  }
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: ru 
State-Changed-When: Thu Jun 14 06:02:20 PDT 2001 
State-Changed-Why:  
Sorry, but this smells more like a bloat. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=12898 
>Unformatted:
