diff options
author | bz <bz@FreeBSD.org> | 2006-12-16 14:15:31 +0000 |
---|---|---|
committer | bz <bz@FreeBSD.org> | 2006-12-16 14:15:31 +0000 |
commit | 2ea10fad249fb6f33048faaa674b5782fd5feaae (patch) | |
tree | 1d296c71bd17609314e89a5d01b9601de64a9fe9 /sys/netinet6/in6.c | |
parent | d52399f3b00af9edcb91834d1b9ac60b603344e1 (diff) | |
download | FreeBSD-src-2ea10fad249fb6f33048faaa674b5782fd5feaae.zip FreeBSD-src-2ea10fad249fb6f33048faaa674b5782fd5feaae.tar.gz |
In ip6_sprintf print the addresses in a more common/readable
format eliminating leading zeros like in :0001 -> :1.
Reviewed by: mlaier
Diffstat (limited to 'sys/netinet6/in6.c')
-rw-r--r-- | sys/netinet6/in6.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index a2dc235..230f932 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++; |