aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/netstat/route.c
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2013-10-15 09:55:07 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2013-10-15 09:55:07 +0000
commit84c1edcbad7d4cf8db3b026ee1c8adb69423e13b (patch)
treecbc27b736c75a09a773308a6dfa37003d78b5771 /usr.bin/netstat/route.c
parent1fa042f0adc398b9fe13c8e12f66fb195f48dfcd (diff)
downloadsrc-84c1edcbad7d4cf8db3b026ee1c8adb69423e13b.tar.gz
src-84c1edcbad7d4cf8db3b026ee1c8adb69423e13b.zip
Rewrite netstat/if.c to use getifaddrs(3) and getifmaddrs(3) instead of
libkvm digging in kernel memory. This is possible since r231506 made getifaddrs(3) to supply if_data for each ifaddr. The pros of this change is that now netstat(1) doesn't know about kernel struct ifnet and struct ifaddr. And these structs are about to change significantly in head soon. New netstat binary will work well with 10.0 and any future kernel. The cons is that now it isn't possible to obtain interface statistics from a vmcore. Functions intpr() and sidewaysintpr() were rewritten from scratch. The output of netstat(1) has underwent the following changes: 1) The MTU is not printed for protocol addresses, since it has no notion. Dash is printed instead. If there would be a strong desire to return previous output, it is doable. 2) Output interface queue drops are not printed. Currently this data isn't available to userland via any API. We plan to drop 'struct ifqueue' from 'struct ifnet' very soon, so old kvm(3) access to queue drops is soon to be broken, too. The plan is that drivers would handle their queues theirselves and a new field in if_data would be updated in case of drops. 3) In-kernel reference count for multicast addresses isn't printed. I doubt that anyone used it. Anyway, netstat(1) is sysadmin tool, not kernel debugger. Sponsored by: Netflix Sponsored by: Nginx, Inc.
Notes
Notes: svn path=/head/; revision=256512
Diffstat (limited to 'usr.bin/netstat/route.c')
-rw-r--r--usr.bin/netstat/route.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 1de12cc9fd5d..4381ffd31b6b 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -631,10 +631,9 @@ fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags)
cp = routename(sockin->sin_addr.s_addr);
else if (mask)
cp = netname(sockin->sin_addr.s_addr,
- ntohl(((struct sockaddr_in *)mask)
- ->sin_addr.s_addr));
+ ((struct sockaddr_in *)mask)->sin_addr.s_addr);
else
- cp = netname(sockin->sin_addr.s_addr, 0L);
+ cp = netname(sockin->sin_addr.s_addr, INADDR_ANY);
break;
}
@@ -870,19 +869,21 @@ domask(char *dst, in_addr_t addr __unused, u_long mask)
/*
* Return the name of the network whose address is given.
- * The address is assumed to be that of a net or subnet, not a host.
*/
char *
-netname(in_addr_t in, u_long mask)
+netname(in_addr_t in, in_addr_t mask)
{
char *cp = 0;
static char line[MAXHOSTNAMELEN];
struct netent *np = 0;
in_addr_t i;
+ /* It is ok to supply host address. */
+ in &= mask;
+
i = ntohl(in);
if (!numeric_addr && i) {
- np = getnetbyaddr(i >> NSHIFT(mask), AF_INET);
+ np = getnetbyaddr(i >> NSHIFT(ntohl(mask)), AF_INET);
if (np != NULL) {
cp = np->n_name;
trimdomain(cp, strlen(cp));
@@ -893,7 +894,7 @@ netname(in_addr_t in, u_long mask)
} else {
inet_ntop(AF_INET, &in, line, sizeof(line) - 1);
}
- domask(line + strlen(line), i, mask);
+ domask(line + strlen(line), i, ntohl(mask));
return (line);
}