mingw does not have inet_ntop, which were taken as is from the musl C library.
| 296 | // mingw does not have inet_ntop, which were taken as is from the musl C library. |
| 297 | // |
| 298 | const char* inet_ntop(int af, const void* a0, char* s, socklen_t l) |
| 299 | { |
| 300 | #if defined(_WIN32) && defined(__GNUC__) |
| 301 | const unsigned char* a = (const unsigned char*) a0; |
| 302 | int i, j, max, best; |
| 303 | char buf[100]; |
| 304 | |
| 305 | switch (af) |
| 306 | { |
| 307 | case AF_INET: |
| 308 | if (snprintf(s, l, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]) < l) return s; |
| 309 | break; |
| 310 | case AF_INET6: |
| 311 | if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\377\377", 12)) |
| 312 | snprintf(buf, |
| 313 | sizeof buf, |
| 314 | "%x:%x:%x:%x:%x:%x:%x:%x", |
| 315 | 256 * a[0] + a[1], |
| 316 | 256 * a[2] + a[3], |
| 317 | 256 * a[4] + a[5], |
| 318 | 256 * a[6] + a[7], |
| 319 | 256 * a[8] + a[9], |
| 320 | 256 * a[10] + a[11], |
| 321 | 256 * a[12] + a[13], |
| 322 | 256 * a[14] + a[15]); |
| 323 | else |
| 324 | snprintf(buf, |
| 325 | sizeof buf, |
| 326 | "%x:%x:%x:%x:%x:%x:%d.%d.%d.%d", |
| 327 | 256 * a[0] + a[1], |
| 328 | 256 * a[2] + a[3], |
| 329 | 256 * a[4] + a[5], |
| 330 | 256 * a[6] + a[7], |
| 331 | 256 * a[8] + a[9], |
| 332 | 256 * a[10] + a[11], |
| 333 | a[12], |
| 334 | a[13], |
| 335 | a[14], |
| 336 | a[15]); |
| 337 | /* Replace longest /(^0|:)[:0]{2,}/ with "::" */ |
| 338 | for (i = best = 0, max = 2; buf[i]; i++) |
| 339 | { |
| 340 | if (i && buf[i] != ':') continue; |
| 341 | j = strspn(buf + i, ":0"); |
| 342 | if (j > max) best = i, max = j; |
| 343 | } |
| 344 | if (max > 3) |
| 345 | { |
| 346 | buf[best] = buf[best + 1] = ':'; |
| 347 | memmove(buf + best + 2, buf + best + max, i - best - max + 1); |
| 348 | } |
| 349 | if (strlen(buf) < (size_t)l) |
| 350 | { |
| 351 | strcpy(s, buf); |
| 352 | return s; |
| 353 | } |
| 354 | break; |
| 355 | default: errno = EAFNOSUPPORT; return 0; |