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
This commit is contained in:
Ruslan Ermilov 2001-10-11 14:30:42 +00:00
parent 65601f6da8
commit 146db49f97

View File

@ -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);
}