| 1633 | */ |
| 1634 | static char digits[] = "0123456789abcdef"; |
| 1635 | char * |
| 1636 | ip6_sprintf(char *ip6buf, const struct in6_addr *addr) |
| 1637 | { |
| 1638 | int i, cnt = 0, maxcnt = 0, idx = 0, index = 0; |
| 1639 | char *cp; |
| 1640 | const u_int16_t *a = (const u_int16_t *)addr; |
| 1641 | const u_int8_t *d; |
| 1642 | int dcolon = 0, zero = 0; |
| 1643 | |
| 1644 | cp = ip6buf; |
| 1645 | |
| 1646 | for (i = 0; i < 8; i++) { |
| 1647 | if (*(a + i) == 0) { |
| 1648 | cnt++; |
| 1649 | if (cnt == 1) |
| 1650 | idx = i; |
| 1651 | } |
| 1652 | else if (maxcnt < cnt) { |
| 1653 | maxcnt = cnt; |
| 1654 | index = idx; |
| 1655 | cnt = 0; |
| 1656 | } |
| 1657 | } |
| 1658 | if (maxcnt < cnt) { |
| 1659 | maxcnt = cnt; |
| 1660 | index = idx; |
| 1661 | } |
| 1662 | |
| 1663 | for (i = 0; i < 8; i++) { |
| 1664 | if (dcolon == 1) { |
| 1665 | if (*a == 0) { |
| 1666 | if (i == 7) |
| 1667 | *cp++ = ':'; |
| 1668 | a++; |
| 1669 | continue; |
| 1670 | } else |
| 1671 | dcolon = 2; |
| 1672 | } |
| 1673 | if (*a == 0) { |
| 1674 | if (dcolon == 0 && *(a + 1) == 0 && i == index) { |
| 1675 | if (i == 0) |
| 1676 | *cp++ = ':'; |
| 1677 | *cp++ = ':'; |
| 1678 | dcolon = 1; |
| 1679 | } else { |
| 1680 | *cp++ = '0'; |
| 1681 | *cp++ = ':'; |
| 1682 | } |
| 1683 | a++; |
| 1684 | continue; |
| 1685 | } |
| 1686 | d = (const u_char *)a; |
| 1687 | /* Try to eliminate leading zeros in printout like in :0001. */ |
| 1688 | zero = 1; |
| 1689 | *cp = digits[*d >> 4]; |
| 1690 | if (*cp != '0') { |
| 1691 | zero = 0; |
| 1692 | cp++; |
no outgoing calls
no test coverage detected