=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/netstat/main.c,v retrieving revision 1.115 retrieving revision 1.116 diff -u -r1.115 -r1.116 --- src/usr.bin/netstat/main.c 2019/03/05 06:47:12 1.115 +++ src/usr.bin/netstat/main.c 2019/04/28 17:59:51 1.116 @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.115 2019/03/05 06:47:12 jmc Exp $ */ +/* $OpenBSD: main.c,v 1.116 2019/04/28 17:59:51 mpi Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -54,14 +54,12 @@ #include "netstat.h" struct nlist nl[] = { -#define N_RTREE 0 - { "_rt_tables"}, -#define N_RTMASK 1 - { "_mask_rnhead" }, -#define N_AF2RTAFIDX 2 - { "_af2rtafidx" }, -#define N_RTBLIDMAX 3 - { "_rtbl_id_max" }, +#define N_AFMAP 0 + { "_afmap"}, +#define N_AF2IDX 1 + { "_af2idx" }, +#define N_AF2IDXMAX 2 + { "_af2idx_max" }, { "" } }; @@ -104,7 +102,7 @@ static void usage(void); static struct protox *name2protox(char *); static struct protox *knownname(char *); -u_int gettable(const char *); +void gettable(u_int); kvm_t *kvmd; @@ -168,8 +166,6 @@ af = AF_UNIX; else if (strcmp(optarg, "mpls") == 0) af = AF_MPLS; - else if (strcmp(optarg, "mask") == 0) - af = 0xff; else { (void)fprintf(stderr, "%s: %s: unknown address family\n", @@ -236,8 +232,10 @@ ++sflag; break; case 'T': + tableid = strtonum(optarg, 0, RT_TABLEID_MAX, &errstr); + if (errstr) + errx(1, "invalid table id: %s", errstr); Tflag = 1; - tableid = gettable(optarg); break; case 't': tflag = 1; @@ -341,11 +339,13 @@ errx(1, "no namelist"); } + if (!need_nlist && Tflag) + gettable(tableid); + if (rflag) { if (Aflag || nlistf != NULL || memf != NULL) - routepr(nl[N_RTREE].n_value, nl[N_RTMASK].n_value, - nl[N_AF2RTAFIDX].n_value, nl[N_RTBLIDMAX].n_value, - tableid); + routepr(nl[N_AFMAP].n_value, nl[N_AF2IDX].n_value, + nl[N_AF2IDXMAX].n_value, tableid); else p_rttables(af, tableid); exit(0); @@ -458,19 +458,13 @@ exit(1); } -u_int -gettable(const char *s) +void +gettable(u_int tableid) { - const char *errstr; struct rt_tableinfo info; int mib[6]; size_t len; - u_int tableid; - tableid = strtonum(s, 0, RT_TABLEID_MAX, &errstr); - if (errstr) - errx(1, "invalid table id: %s", errstr); - mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; @@ -481,6 +475,4 @@ len = sizeof(info); if (sysctl(mib, 6, &info, &len, NULL, 0) == -1) err(1, "routing table %d", tableid); - - return (tableid); }