summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2013-07-09 09:43:03 +0000
committerae <ae@FreeBSD.org>2013-07-09 09:43:03 +0000
commit1b1e1de2b2e27f692afabbf18eee1f7a70caa049 (patch)
treeae9cc37d3d61216f4f205b4e2bf561b5cf5ea330 /usr.bin/netstat
parent027c687189cc0647592f671691e0a08064401c1d (diff)
downloadFreeBSD-src-1b1e1de2b2e27f692afabbf18eee1f7a70caa049.zip
FreeBSD-src-1b1e1de2b2e27f692afabbf18eee1f7a70caa049.tar.gz
Use new macros to implement ipstat and tcpstat using PCPU counters.
Change interface of kread_counters() similar ot kread() in the netstat(1).
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r--usr.bin/netstat/inet.c18
-rw-r--r--usr.bin/netstat/main.c16
-rw-r--r--usr.bin/netstat/netstat.h2
3 files changed, 16 insertions, 20 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index c898775..1df1bfa 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -603,13 +603,8 @@ tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
warn("sysctl: net.inet.tcp.stats");
return;
}
- } else {
- u_long tcpstat_p[sizeof(struct tcpstat)/sizeof(uint64_t)];
-
- kread(off, &tcpstat_p, sizeof(tcpstat_p));
- kread_counters(tcpstat_p, (uint64_t *)&tcpstat,
- sizeof(struct tcpstat)/sizeof(uint64_t));
- }
+ } else
+ kread_counters(off, &tcpstat, len);
printf ("%s:\n", name);
@@ -863,13 +858,8 @@ ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
warn("sysctl: net.inet.ip.stats");
return;
}
- } else {
- u_long ipstat_p[sizeof(struct ipstat)/sizeof(uint64_t)];
-
- kread(off, &ipstat_p, sizeof(ipstat_p));
- kread_counters(ipstat_p, (uint64_t *)&ipstat,
- sizeof(struct ipstat)/sizeof(uint64_t));
- }
+ } else
+ kread_counters(off, &ipstat, len);
printf("%s:\n", name);
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index ce4ff95..d9c8334 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -147,11 +147,11 @@ static struct nlist nl[] = {
#define N_IPCOMPSTAT 37
{ .n_name = "_ipcompstat" },
#define N_TCPSTAT 38
- { .n_name = "_tcpstatp" },
+ { .n_name = "_tcpstat" },
#define N_UDPSTAT 39
{ .n_name = "_udpstat" },
#define N_IPSTAT 40
- { .n_name = "_ipstatp" },
+ { .n_name = "_ipstat" },
#define N_ICMPSTAT 41
{ .n_name = "_icmpstat" },
#define N_IGMPSTAT 42
@@ -753,15 +753,21 @@ kread(u_long addr, void *buf, size_t size)
* Read an array of N counters in kernel memory into array of N uint64_t's.
*/
int
-kread_counters(u_long *addr, uint64_t *rval, size_t count)
+kread_counters(u_long addr, void *buf, size_t size)
{
+ uint64_t *c = buf;
if (kvmd_init() < 0)
return (-1);
- for (u_int i = 0; i < count; i++, addr++, rval++)
- *rval = kvm_counter_u64_fetch(kvmd, *addr);
+ if (kread(addr, buf, size) < 0)
+ return (-1);
+ while (size != 0) {
+ *c = kvm_counter_u64_fetch(kvmd, *c);
+ size -= sizeof(*c);
+ c++;
+ }
return (0);
}
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 32bea79..318fcbe 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -60,7 +60,7 @@ extern int af; /* address family */
extern int live; /* true if we are examining a live system */
int kread(u_long addr, void *buf, size_t size);
-int kread_counters(u_long *addr, uint64_t *rval, size_t count);
+int kread_counters(u_long addr, void *buf, size_t size);
const char *plural(uintmax_t);
const char *plurales(uintmax_t);
const char *pluralies(uintmax_t);
OpenPOWER on IntegriCloud