summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2006-12-16 14:15:31 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2006-12-16 14:15:31 +0000
commite521ae0c6466791d3444ec380f97b210aa5670a5 (patch)
tree1d296c71bd17609314e89a5d01b9601de64a9fe9
parentc29765b647677cc7f47d06b3ece7db14d534668d (diff)
Notes
-rw-r--r--sys/netinet6/in6.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index a2dc23589d10..230f932ceafa 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1904,7 +1904,7 @@ ip6_sprintf(char *ip6buf, const struct in6_addr *addr)
char *cp;
const u_int16_t *a = (const u_int16_t *)addr;
const u_int8_t *d;
- int dcolon = 0;
+ int dcolon = 0, zero = 0;
cp = ip6buf;
@@ -1932,9 +1932,23 @@ ip6_sprintf(char *ip6buf, const struct in6_addr *addr)
continue;
}
d = (const u_char *)a;
- *cp++ = digits[*d >> 4];
- *cp++ = digits[*d++ & 0xf];
- *cp++ = digits[*d >> 4];
+ /* Try to eliminate leading zeros in printout like in :0001. */
+ zero = 1;
+ *cp = digits[*d >> 4];
+ if (*cp != '0') {
+ zero = 0;
+ cp++;
+ }
+ *cp = digits[*d++ & 0xf];
+ if (zero == 0 || (*cp != '0')) {
+ zero = 0;
+ cp++;
+ }
+ *cp = digits[*d >> 4];
+ if (zero == 0 || (*cp != '0')) {
+ zero = 0;
+ cp++;
+ }
*cp++ = digits[*d & 0xf];
*cp++ = ':';
a++;