From owner-svn-src-head@FreeBSD.ORG Fri Jul 12 17:11:31 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 45E89981; Fri, 12 Jul 2013 17:11:31 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 3796210FE; Fri, 12 Jul 2013 17:11:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r6CHBVuf080142; Fri, 12 Jul 2013 17:11:31 GMT (envelope-from hrs@svn.freebsd.org) Received: (from hrs@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r6CHBUfX080136; Fri, 12 Jul 2013 17:11:30 GMT (envelope-from hrs@svn.freebsd.org) Message-Id: <201307121711.r6CHBUfX080136@svn.freebsd.org> From: Hiroki Sato Date: Fri, 12 Jul 2013 17:11:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r253275 - head/usr.bin/netstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Jul 2013 17:11:31 -0000 Author: hrs Date: Fri Jul 12 17:11:30 2013 New Revision: 253275 URL: http://svnweb.freebsd.org/changeset/base/253275 Log: Add -F fibnum option to specify an FIB number for -r flag. Modified: head/usr.bin/netstat/main.c head/usr.bin/netstat/netstat.1 head/usr.bin/netstat/netstat.h head/usr.bin/netstat/route.c Modified: head/usr.bin/netstat/main.c ============================================================================== --- head/usr.bin/netstat/main.c Fri Jul 12 17:09:50 2013 (r253274) +++ head/usr.bin/netstat/main.c Fri Jul 12 17:11:30 2013 (r253275) @@ -363,10 +363,12 @@ main(int argc, char *argv[]) { struct protox *tp = NULL; /* for printing cblocks & stats */ int ch; + int fib = -1; + char *endptr; af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSTsuWw:xz")) + while ((ch = getopt(argc, argv, "AaBbdF:f:ghI:iLlM:mN:np:Qq:rSTsuWw:xz")) != -1) switch(ch) { case 'A': @@ -384,6 +386,12 @@ main(int argc, char *argv[]) case 'd': dflag = 1; break; + case 'F': + fib = strtol(optarg, &endptr, 0); + if (*endptr != '\0' || + (fib == 0 && (errno == EINVAL || errno == ERANGE))) + errx(1, "%s: invalid fib", optarg); + break; case 'f': if (strcmp(optarg, "ipx") == 0) af = AF_IPX; @@ -571,7 +579,7 @@ main(int argc, char *argv[]) if (sflag) rt_stats(nl[N_RTSTAT].n_value, nl[N_RTTRASH].n_value); else - routepr(nl[N_RTREE].n_value); + routepr(nl[N_RTREE].n_value, fib); exit(0); } if (gflag) { Modified: head/usr.bin/netstat/netstat.1 ============================================================================== --- head/usr.bin/netstat/netstat.1 Fri Jul 12 17:09:50 2013 (r253274) +++ head/usr.bin/netstat/netstat.1 Fri Jul 12 17:11:30 2013 (r253275) @@ -28,7 +28,7 @@ .\" @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd March 10, 2013 +.Dd May 17, 2013 .Dt NETSTAT 1 .Os .Sh NAME @@ -217,14 +217,29 @@ states. .Nm .Fl r .Op Fl AanW +.Op Fl F Ar fibnum .Op Fl f Ar address_family .Op Fl M Ar core .Op Fl N Ar system .Ek .Xc -Display the contents of all routing tables, -or a routing table for a particular -.Ar address_family . +Display the contents of routing tables. +When +.Fl f +is specified, a routing table for a particular +.Ar address_family +is displayed. +When +.Fl F +is specified, a routing table with the number +.Ar fibnum +is displayed. +If the specified +.Ar fibnum +is -1 or +.Fl F +is not specified, +the default routing table is displayed. If .Fl A is also present, Modified: head/usr.bin/netstat/netstat.h ============================================================================== --- head/usr.bin/netstat/netstat.h Fri Jul 12 17:09:50 2013 (r253274) +++ head/usr.bin/netstat/netstat.h Fri Jul 12 17:11:30 2013 (r253275) @@ -135,7 +135,7 @@ char *atalk_print(struct sockaddr *, int char *atalk_print2(struct sockaddr *, struct sockaddr *, int); char *ipx_print(struct sockaddr *); char *ns_print(struct sockaddr *); -void routepr(u_long); +void routepr(u_long, int); void ipxprotopr(u_long, const char *, int, int); void spx_stats(u_long, const char *, int, int); Modified: head/usr.bin/netstat/route.c ============================================================================== --- head/usr.bin/netstat/route.c Fri Jul 12 17:09:50 2013 (r253274) +++ head/usr.bin/netstat/route.c Fri Jul 12 17:11:30 2013 (r253275) @@ -143,17 +143,20 @@ static void domask(char *, in_addr_t, u_ * Print routing tables. */ void -routepr(u_long rtree) +routepr(u_long rtree, int fibnum) { struct radix_node_head **rnhp, *rnh, head; size_t intsize; - int fam, fibnum, numfibs; + int fam, numfibs; intsize = sizeof(int); - if (sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1) + if (fibnum == -1 && + sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1) fibnum = 0; if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) numfibs = 1; + if (fibnum < 0 || fibnum > numfibs - 1) + errx(EX_USAGE, "%d: invalid fib", fibnum); rt_tables = calloc(numfibs * (AF_MAX+1), sizeof(struct radix_node_head *)); if (rt_tables == NULL) @@ -166,7 +169,10 @@ routepr(u_long rtree) if (clock_gettime(CLOCK_UPTIME, &uptime) < 0) err(EX_OSERR, "clock_gettime() failed"); - printf("Routing tables\n"); + printf("Routing tables"); + if (fibnum) + printf(" (fib: %d)", fibnum); + printf("\n"); if (Aflag == 0 && NewTree) ntreestuff();