1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-19 10:53:58 +00:00

Always print at least 2 bytes for IN_CLASSB_NET networks.

Always print at least 3 bytes for IN_CLASSC_NET networks.

The standard 193.0.0 class C network for example, will now
be displayed as "193.0.0" as opposed to the confusing 193.

PR:		bin/21546
MFC after:	1 week
This commit is contained in:
Ruslan Ermilov 2001-06-08 15:44:17 +00:00
parent 37e419776d
commit 54f6369da3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77911

View File

@ -726,9 +726,9 @@ netname(in, mask)
register u_long i;
i = ntohl(in);
dmask = forgemask(i);
omask = mask;
if (!nflag && i) {
dmask = forgemask(i);
net = i & dmask;
if (!(np = getnetbyaddr(i, AF_INET)) && net != i)
np = getnetbyaddr(net, AF_INET);
@ -739,15 +739,34 @@ netname(in, mask)
}
if (cp)
strncpy(line, cp, sizeof(line) - 1);
else if ((i & 0xffffff) == 0)
sprintf(line, "%lu", C(i >> 24));
else if ((i & 0xffff) == 0)
sprintf(line, "%lu.%lu", C(i >> 24) , C(i >> 16));
else if ((i & 0xff) == 0)
sprintf(line, "%lu.%lu.%lu", C(i >> 24), C(i >> 16), C(i >> 8));
else
sprintf(line, "%lu.%lu.%lu.%lu", C(i >> 24),
C(i >> 16), C(i >> 8), C(i));
else {
switch (dmask) {
case IN_CLASSA_NET:
if ((i & IN_CLASSA_HOST) == 0) {
sprintf(line, "%lu", C(i >> 24));
break;
}
/* FALLTHROUGH */
case IN_CLASSB_NET:
if ((i & IN_CLASSB_HOST) == 0) {
sprintf(line, "%lu.%lu",
C(i >> 24), C(i >> 16));
break;
}
/* FALLTHROUGH */
case IN_CLASSC_NET:
if ((i & IN_CLASSC_HOST) == 0) {
sprintf(line, "%lu.%lu.%lu",
C(i >> 24), C(i >> 16), C(i >> 8));
break;
}
/* FALLTHROUGH */
default:
sprintf(line, "%lu.%lu.%lu.%lu",
C(i >> 24), C(i >> 16), C(i >> 8), C(i));
break;
}
}
domask(line+strlen(line), i, omask);
return (line);
}