MCPcopy Index your code
hub / github.com/F-Stack/f-stack / ip6_sprintf

Function ip6_sprintf

freebsd/netinet6/in6.c:1635–1710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1633 */
1634static char digits[] = "0123456789abcdef";
1635char *
1636ip6_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++;

Callers 15

ifFunction · 0.85
print_dyn_rule_flagsFunction · 0.85
ipfw_logFunction · 0.85
sctp_print_addressFunction · 0.85
db_print_inconninfoFunction · 0.85
sysctl_tcp_hc_listFunction · 0.85
tcp_log_addrFunction · 0.85
in6_update_ifa_join_mcFunction · 0.85
in6_validate_ifraFunction · 0.85
in6_unlink_ifaFunction · 0.85
in6_notify_ifaFunction · 0.85
in6_lltable_rtcheckFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected