26 static const char *
inet_ntop4(
const unsigned char *src,
char *dst,
28 static const char *
inet_ntop6(
const unsigned char *src,
char *dst,
66 inet_ntop4(
const unsigned char *src,
char *dst,
size_t size)
68 static const char fmt[] =
"%u.%u.%u.%u";
69 char tmp[
sizeof(
"255.255.255.255")];
72 len =
Q_snprintf(tmp,
sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
89 inet_ntop6(
const unsigned char *src,
char *dst,
size_t size)
98 char tmp[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp;
110 memset(words,
'\0',
sizeof(words));
112 words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
120 cur.base = i, cur.len = 1;
124 if (cur.base != -1) {
125 if (best.base == -1 || cur.len > best.len)
131 if (cur.base != -1) {
132 if (best.base == -1 || cur.len > best.len)
135 if (best.base != -1 && best.len < 2)
144 if (best.base != -1 && i >= best.base &&
145 i < (best.base + best.len)) {
154 if (i == 6 && best.base == 0 &&
155 (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
157 sizeof(tmp) - (tp - tmp)))
162 tp += sprintf(tp,
"%x", words[i]);
165 if (best.base != -1 && (best.base + best.len) ==
173 if ((
size_t)(tp - tmp) > size) {