static void dns_lookup_host(struct dns_session *s, const char *host, int preference) { struct dns_lookup *lookup; struct addrinfo hints; char hostcopy[HOST_NAME_MAX+1]; char *p; void *as; lookup = xcalloc(1, sizeof *lookup, "dns_lookup_host"); lookup->preference = preference; lookup->session = s; s->refcount++; if (*host == '[') { if (strncasecmp("[IPv6:", host, 6) == 0) host += 6; else host += 1; (void)strlcpy(hostcopy, host, sizeof hostcopy); p = strchr(hostcopy, ']'); if (p) *p = 0; host = hostcopy; } memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; as = getaddrinfo_async(host, NULL, &hints, NULL); event_asr_run(as, dns_dispatch_host, lookup); }
int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) { struct asr_query *as; struct asr_result ar; int saved_errno = errno; if (hints == NULL || (hints->ai_flags & AI_NUMERICHOST) == 0) res_init(); as = getaddrinfo_async(hostname, servname, hints, NULL); if (as == NULL) { if (errno == ENOMEM) { errno = saved_errno; return (EAI_MEMORY); } return (EAI_SYSTEM); } asr_run_sync(as, &ar); *res = ar.ar_addrinfo; if (ar.ar_gai_errno == EAI_SYSTEM) errno = ar.ar_errno; return (ar.ar_gai_errno); }