From 78d1fe9622b6a5dd7d2d01126676e82101ff70fe Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Wed, 10 Jan 2001 23:06:31 +0000 Subject: [PATCH] Fix so that the netmask is displayed correctly when it does not consist of contiguous bits in little endian format. Before the fix the netmask of 0xfffffff0 (0xf0ffffff in little endian format) was displayed /24 instead of /28. Also, add a missing include. Submitted by: Maxime Soule --- release/picobsd/tinyware/ns/ns.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/release/picobsd/tinyware/ns/ns.c b/release/picobsd/tinyware/ns/ns.c index a5e6a25b48a..2d625291751 100644 --- a/release/picobsd/tinyware/ns/ns.c +++ b/release/picobsd/tinyware/ns/ns.c @@ -58,6 +58,7 @@ #ifdef BRIDGING #include /* IFT_ETHER */ +#include #include #endif @@ -98,15 +99,19 @@ sock_ntop(const struct sockaddr *sa, size_t salen) switch (sa->sa_family) { case 255: { - struct sockaddr_in *sin = (struct sockaddr_in *) sa; u_long mask; + u_int index = 1 << 31; + u_short new_mask = 0; int i; i=0; - mask=ntohl(sin->sin_addr.s_addr); + mask = ntohl(((struct sockaddr_in *)sa)->sin_addr.s_addr); - while(mask & (0x80000000>>i)) i++; - sprintf(str,"/%d",i); + while(mask & index) { + new_mask++; + index >>= 1; + } + sprintf(str,"/%hu", new_mask); return(str); } case AF_UNSPEC: