summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-10-11 14:30:42 +0000
committerru <ru@FreeBSD.org>2001-10-11 14:30:42 +0000
commitb0d7725e6d06b90f24cd57a55d75f334c3d5cce4 (patch)
tree01a65a8dcad8bdb6f2f23bb3f33d732f37165f4e /usr.bin
parent18cd2d2cea2ccd3752de4c151a861304d610249e (diff)
downloadFreeBSD-src-b0d7725e6d06b90f24cd57a55d75f334c3d5cce4.zip
FreeBSD-src-b0d7725e6d06b90f24cd57a55d75f334c3d5cce4.tar.gz
Fixed bugs from revision 1.27. Specifically:
- Restore the ability to look up network names in the networks(5) database by passing getnetbyaddr(3) shifted network numbers, but without duplicating the old bug that was fixed in 1.27 (we now only shift netnums with standard netmasks). For example: Before: $ netstat -r [...] 127.0.1/24 localhost UGSc 0 0 lo0 127.0.2/24 localhost UGSc 0 0 lo0 After: $ netstat -r [...] subnet1/24 localhost UGSc 0 0 lo0 subnet2/24 localhost UGSc 0 0 lo0 - Only try to lookup with the forged netmask if the mask was not explicitly specified, like it was before 1.27. For example: Before: $ netstat -r net-44.ampr.org/25 localhost UGSc 0 0 lo0 net-44.ampr.org/25 localhost UGSc 0 0 lo0 After: 44.108.2/25 localhost UGSc 0 0 lo0 44.108.2.128/25 localhost UGSc 0 0 lo0 - Make sure to null-terminate the resulting string. MFC after: 1 week
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/route.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index e75084d..7175977 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -714,24 +714,31 @@ netname(u_long in, u_long mask)
char *cp = 0;
static char line[MAXHOSTNAMELEN];
struct netent *np = 0;
- u_long net, omask, dmask;
+ u_long dmask;
register u_long i;
+#define NSHIFT(m) ( \
+ (m) == IN_CLASSA_NET ? IN_CLASSA_NSHIFT : \
+ (m) == IN_CLASSB_NET ? IN_CLASSB_NSHIFT : \
+ (m) == IN_CLASSC_NET ? IN_CLASSC_NSHIFT : \
+ 0)
+
i = ntohl(in);
dmask = forgemask(i);
- omask = mask;
if (!numeric_addr && i) {
- net = i & dmask;
- if (!(np = getnetbyaddr(i, AF_INET)) && net != i)
- np = getnetbyaddr(net, AF_INET);
- if (np) {
+ np = getnetbyaddr(i >> NSHIFT(mask), AF_INET);
+ if (np == NULL && mask == 0)
+ np = getnetbyaddr(i >> NSHIFT(dmask), AF_INET);
+ if (np != NULL) {
cp = np->n_name;
trimdomain(cp, strlen(cp));
}
}
- if (cp)
+#undef NSHIFT
+ if (cp != NULL) {
strncpy(line, cp, sizeof(line) - 1);
- else {
+ line[sizeof(line) - 1] = '\0';
+ } else {
switch (dmask) {
case IN_CLASSA_NET:
if ((i & IN_CLASSA_HOST) == 0) {
@@ -759,7 +766,7 @@ netname(u_long in, u_long mask)
break;
}
}
- domask(line+strlen(line), i, omask);
+ domask(line + strlen(line), i, mask);
return (line);
}
OpenPOWER on IntegriCloud