struct asr_query * getnameinfo_async(const struct sockaddr *sa, socklen_t slen, char *host, size_t hostlen, char *serv, size_t servlen, int flags, void *asr) { struct asr_ctx *ac; struct asr_query *as; ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETNAMEINFO)) == NULL) goto abort; /* errno set */ as->as_run = getnameinfo_async_run; if (sa->sa_family == AF_INET) memmove(&as->as.ni.sa.sa, sa, sizeof (as->as.ni.sa.sain)); else if (sa->sa_family == AF_INET6) memmove(&as->as.ni.sa.sa, sa, sizeof (as->as.ni.sa.sain6)); #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN as->as.ni.sa.sa.sa_len = slen; #endif as->as.ni.hostname = host; as->as.ni.hostnamelen = hostlen; as->as.ni.servname = serv; as->as.ni.servnamelen = servlen; as->as.ni.flags = flags; asr_ctx_unref(ac); return (as); abort: if (as) asr_async_free(as); asr_ctx_unref(ac); return (NULL); }
struct async * gethostbyname2_async(const char *name, int af, struct asr *asr) { struct asr_ctx *ac; struct async *as; /* the original segfaults */ if (name == NULL) { errno = EINVAL; return (NULL); } ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETHOSTBYNAME)) == NULL) goto abort; /* errno set */ as->as_run = gethostnamadr_async_run; as->as.hostnamadr.family = af; if (af == AF_INET) as->as.hostnamadr.addrlen = INADDRSZ; else if (af == AF_INET6) as->as.hostnamadr.addrlen = IN6ADDRSZ; as->as.hostnamadr.name = strdup(name); if (as->as.hostnamadr.name == NULL) goto abort; /* errno set */ asr_ctx_unref(ac); return (as); abort: if (as) asr_async_free(as); asr_ctx_unref(ac); return (NULL); }
struct async * gethostbyaddr_async_ctx(const void *addr, socklen_t len, int af, struct asr_ctx *ac) { struct async *as; if ((as = asr_async_new(ac, ASR_GETHOSTBYADDR)) == NULL) goto abort; /* errno set */ as->as_run = gethostnamadr_async_run; as->as.hostnamadr.family = af; as->as.hostnamadr.addrlen = len; if (len > 0) memmove(as->as.hostnamadr.addr, addr, (len > 16) ? 16 : len); return (as); abort: if (as) asr_async_free(as); return (NULL); }
struct asr_query * getaddrinfo_async(const char *hostname, const char *servname, const struct addrinfo *hints, void *asr) { struct asr_ctx *ac; struct asr_query *as; char alias[MAXDNAME]; ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETADDRINFO)) == NULL) goto abort; /* errno set */ as->as_run = getaddrinfo_async_run; if (hostname) { if (asr_hostalias(ac, hostname, alias, sizeof(alias))) hostname = alias; if ((as->as.ai.hostname = strdup(hostname)) == NULL) goto abort; /* errno set */ } if (servname && (as->as.ai.servname = strdup(servname)) == NULL) goto abort; /* errno set */ if (hints) memmove(&as->as.ai.hints, hints, sizeof *hints); else { memset(&as->as.ai.hints, 0, sizeof as->as.ai.hints); as->as.ai.hints.ai_family = PF_UNSPEC; as->as.ai.hints.ai_flags = AI_ADDRCONFIG; } asr_ctx_unref(ac); return (as); abort: if (as) asr_async_free(as); asr_ctx_unref(ac); return (NULL); }