| 502 | */ |
| 503 | |
| 504 | char * /* O - Numeric address string */ |
| 505 | httpAddrString(const http_addr_t *addr, /* I - Address to convert */ |
| 506 | char *s, /* I - String buffer */ |
| 507 | int slen) /* I - Length of string */ |
| 508 | { |
| 509 | DEBUG_printf(("httpAddrString(addr=%p, s=%p, slen=%d)", (void *)addr, (void *)s, slen)); |
| 510 | |
| 511 | /* |
| 512 | * Range check input... |
| 513 | */ |
| 514 | |
| 515 | if (!addr || !s || slen <= 2) |
| 516 | { |
| 517 | if (s && slen >= 1) |
| 518 | *s = '\0'; |
| 519 | |
| 520 | return (NULL); |
| 521 | } |
| 522 | |
| 523 | #ifdef AF_LOCAL |
| 524 | if (addr->addr.sa_family == AF_LOCAL) |
| 525 | { |
| 526 | if (addr->un.sun_path[0] == '/') |
| 527 | strlcpy(s, addr->un.sun_path, (size_t)slen); |
| 528 | else |
| 529 | strlcpy(s, "localhost", (size_t)slen); |
| 530 | } |
| 531 | else |
| 532 | #endif /* AF_LOCAL */ |
| 533 | if (addr->addr.sa_family == AF_INET) |
| 534 | { |
| 535 | unsigned temp; /* Temporary address */ |
| 536 | |
| 537 | temp = ntohl(addr->ipv4.sin_addr.s_addr); |
| 538 | |
| 539 | snprintf(s, (size_t)slen, "%d.%d.%d.%d", (temp >> 24) & 255, |
| 540 | (temp >> 16) & 255, (temp >> 8) & 255, temp & 255); |
| 541 | } |
| 542 | #ifdef AF_INET6 |
| 543 | else if (addr->addr.sa_family == AF_INET6) |
| 544 | { |
| 545 | char *sptr, /* Pointer into string */ |
| 546 | temps[64]; /* Temporary string for address */ |
| 547 | |
| 548 | # ifdef HAVE_GETNAMEINFO |
| 549 | if (getnameinfo(&addr->addr, (socklen_t)httpAddrLength(addr), temps, sizeof(temps), NULL, 0, NI_NUMERICHOST)) |
| 550 | { |
| 551 | /* |
| 552 | * If we get an error back, then the address type is not supported |
| 553 | * and we should zero out the buffer... |
| 554 | */ |
| 555 | |
| 556 | s[0] = '\0'; |
| 557 | |
| 558 | return (NULL); |
| 559 | } |
| 560 | else if ((sptr = strchr(temps, '%')) != NULL) |
| 561 | { |
no outgoing calls