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
This commit is contained in:
parent
3753228779
commit
8e96292d91
@ -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;
|
||||
@ -1906,6 +1906,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) {
|
||||
@ -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++ = ':';
|
||||
|
Loading…
x
Reference in New Issue
Block a user