ret_t cherokee_socket_gethostbyname (cherokee_socket_t *socket, cherokee_buffer_t *hostname) { if (SOCKET_AF(socket) == AF_UNIX) { #ifdef _WIN32 SHOULDNT_HAPPEN; return ret_no_sys; #else memset ((char*) SOCKET_SUN_PATH(socket), 0, sizeof (SOCKET_ADDR_UNIX(socket))); SOCKET_ADDR_UNIX(socket)->sun_family = AF_UNIX; strncpy (SOCKET_SUN_PATH (socket), hostname->buf, sizeof (SOCKET_ADDR_UNIX(socket)->sun_path) - sizeof(short)); return ret_ok; #endif } return cherokee_gethostbyname (hostname->buf, &SOCKET_SIN_ADDR(socket)); }
static ret_t entry_fill_up (cherokee_resolv_cache_entry_t *entry, cherokee_buffer_t *domain) { ret_t ret; char tmp[46]; // Max IPv6 length is 45 struct addrinfo *addr; time_t eagain_at = 0; while (true) { ret = cherokee_gethostbyname (domain, &entry->addr); if (ret == ret_ok) { break; } else if (ret == ret_eagain) { if (eagain_at == 0) { eagain_at = cherokee_bogonow_now; } else if (cherokee_bogonow_now > eagain_at + 3) { LOG_WARNING (CHEROKEE_ERROR_RESOLVE_TIMEOUT, domain->buf); return ret_error; } CHEROKEE_THREAD_YIELD; continue; } else { return ret_error; } } if (unlikely (entry->addr == NULL)) { return ret_error; } /* Render the text representation */ ret = cherokee_ntop (entry->addr->ai_family, entry->addr->ai_addr, tmp, sizeof(tmp)); if (ret != ret_ok) { return ret_error; } cherokee_buffer_add (&entry->ip_str, tmp, strlen(tmp)); /* Render the text representation (all the IPs) */ cherokee_buffer_add_buffer (&entry->ip_str_all, &entry->ip_str); addr = entry->addr; while (addr != NULL) { ret = cherokee_ntop (entry->addr->ai_family, addr->ai_addr, tmp, sizeof(tmp)); if (ret != ret_ok) { return ret_error; } cherokee_buffer_add_char (&entry->ip_str_all, ','); cherokee_buffer_add (&entry->ip_str_all, tmp, strlen(tmp)); addr = addr->ai_next; } return ret_ok; }