diff options
author | alfred <alfred@FreeBSD.org> | 2010-05-19 00:35:47 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2010-05-19 00:35:47 +0000 |
commit | 1e2de7fa4db8695b6f004bb6a47dfe80e6332068 (patch) | |
tree | 5a7bd5d2dbd00b603f62ad45b6b7f755b3d29308 | |
parent | b651ec8311fe5a47b48b420c1b7108503e0889ce (diff) | |
download | FreeBSD-src-1e2de7fa4db8695b6f004bb6a47dfe80e6332068.zip FreeBSD-src-1e2de7fa4db8695b6f004bb6a47dfe80e6332068.tar.gz |
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
-rw-r--r-- | sys/netinet6/in6.c | 21 |
1 files changed, 19 insertions, 2 deletions
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++ = ':'; |