summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/main.c
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2019-04-28 17:59:51 +0000
committermpi <mpi@openbsd.org>2019-04-28 17:59:51 +0000
commit65ba51d4d8ad1eb16cc79aa196fef19bfa6a22c5 (patch)
treef4d2d959c512f89293979fce2e603c5f9549ebfd /usr.bin/netstat/main.c
parentoops, repair some BSDRD confusion (diff)
downloadwireguard-openbsd-65ba51d4d8ad1eb16cc79aa196fef19bfa6a22c5.tar.xz
wireguard-openbsd-65ba51d4d8ad1eb16cc79aa196fef19bfa6a22c5.zip
Fix reading route entries via kvm(3).
From Naoki Fukaumi, ok yasuoka@, sthen@
Diffstat (limited to 'usr.bin/netstat/main.c')
-rw-r--r--usr.bin/netstat/main.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 4c406ce60bc..13f14020332 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -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 @@ struct protox *protoprotox[] = {
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 @@ main(int argc, char *argv[])
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 @@ main(int argc, char *argv[])
++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 @@ main(int argc, char *argv[])
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,18 +458,12 @@ usage(void)
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;
@@ -481,6 +475,4 @@ gettable(const char *s)
len = sizeof(info);
if (sysctl(mib, 6, &info, &len, NULL, 0) == -1)
err(1, "routing table %d", tableid);
-
- return (tableid);
}