Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Jul 1999 10:52:09 -0400 (EDT)
From:      Benjamin April <ben@destek.net>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/12898: netstat -c 
Message-ID:  <199907311452.KAA32545@Darkside.stagecraft.net>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 31 08:00:01 PDT 1999
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907311452.KAA32545>