diff options
author | ru <ru@FreeBSD.org> | 2001-06-08 15:44:17 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2001-06-08 15:44:17 +0000 |
commit | b6e786accf3164ac2ce3e99044b21244abe78df1 (patch) | |
tree | 08decc843a1c1cb7092cc8c5efe89af572ebe9a9 /usr.bin | |
parent | ee82ec559f84dbf03ee700045babbda8c8608121 (diff) | |
download | FreeBSD-src-b6e786accf3164ac2ce3e99044b21244abe78df1.zip FreeBSD-src-b6e786accf3164ac2ce3e99044b21244abe78df1.tar.gz |
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
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/route.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 75cc325..db7f190 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -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); } |