From 1e2de7fa4db8695b6f004bb6a47dfe80e6332068 Mon Sep 17 00:00:00 2001 From: alfred Date: Wed, 19 May 2010 00:35:47 +0000 Subject: Fix our version of IPv6 address representation. We do not respect rules 3 and 4 in the required list: 1. omit leading zeros 2. "::" used to their maximum extent whenever possible 3. "::" used where shortens address the most 4. "::" used in the former part in case of a tie breaker 5. do not shorten one 16 bit 0 field 6. use lower case http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04.html Submitted by: Kalluru Abhiram @ Juniper Networks Obtained from: Juniper Networks Reviewed by: hrs, dougb --- sys/netinet6/in6.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'sys/netinet6') diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 15ff6b2..00ad6cc 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1898,7 +1898,7 @@ static char digits[] = "0123456789abcdef"; char * ip6_sprintf(char *ip6buf, const struct in6_addr *addr) { - int i; + int i, cnt = 0, maxcnt = 0, idx = 0, index = 0; char *cp; const u_int16_t *a = (const u_int16_t *)addr; const u_int8_t *d; @@ -1907,6 +1907,23 @@ ip6_sprintf(char *ip6buf, const struct in6_addr *addr) cp = ip6buf; for (i = 0; i < 8; i++) { + if (*(a + i) == 0) { + cnt++; + if (cnt == 1) + idx = i; + } + else if (maxcnt < cnt) { + maxcnt = cnt; + index = idx; + cnt = 0; + } + } + if (maxcnt < cnt) { + maxcnt = cnt; + index = idx; + } + + for (i = 0; i < 8; i++) { if (dcolon == 1) { if (*a == 0) { if (i == 7) @@ -1917,7 +1934,7 @@ ip6_sprintf(char *ip6buf, const struct in6_addr *addr) dcolon = 2; } if (*a == 0) { - if (dcolon == 0 && *(a + 1) == 0) { + if (dcolon == 0 && *(a + 1) == 0 && i == index) { if (i == 0) *cp++ = ':'; *cp++ = ':'; -- cgit v1.1