Date: Wed, 19 May 2010 00:35:47 +0000 (UTC) From: Alfred Perlstein <alfred@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r208284 - head/sys/netinet6 Message-ID: <201005190035.o4J0Zl8F014392@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: alfred Date: Wed May 19 00:35:47 2010 New Revision: 208284 URL: http://svn.freebsd.org/changeset/base/208284 Log: 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 Modified: head/sys/netinet6/in6.c Modified: head/sys/netinet6/in6.c ============================================================================== --- head/sys/netinet6/in6.c Wed May 19 00:23:10 2010 (r208283) +++ head/sys/netinet6/in6.c Wed May 19 00:35:47 2010 (r208284) @@ -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 i 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 i dcolon = 2; } if (*a == 0) { - if (dcolon == 0 && *(a + 1) == 0) { + if (dcolon == 0 && *(a + 1) == 0 && i == index) { if (i == 0) *cp++ = ':'; *cp++ = ':';
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005190035.o4J0Zl8F014392>