Alien-cares
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
libcares/ares_gethostbyname.c view on Meta::CPAN
switch (family) {
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
break;
default:
callback(arg, ARES_ENOTIMP, 0, NULL);
return;
}
/* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
if (ares__is_onion_domain(name))
{
callback(arg, ARES_ENOTFOUND, 0, NULL);
return;
}
if (fake_hostent(name, family, callback, arg))
return;
/* Allocate and fill in the host query structure. */
hquery = ares_malloc(sizeof(struct host_query));
if (!hquery)
{
callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
hquery->channel = channel;
hquery->name = ares_strdup(name);
hquery->want_family = family;
hquery->sent_family = -1; /* nothing is sent yet */
if (!hquery->name) {
ares_free(hquery);
callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
hquery->callback = callback;
hquery->arg = arg;
hquery->remaining_lookups = channel->lookups;
hquery->timeouts = 0;
/* Start performing lookups according to channel->lookups. */
next_lookup(hquery, ARES_ECONNREFUSED /* initial error code */);
}
static void next_lookup(struct host_query *hquery, int status_code)
{
const char *p;
struct hostent *host;
int status = status_code;
for (p = hquery->remaining_lookups; *p; p++)
{
switch (*p)
{
case 'b':
/* DNS lookup */
hquery->remaining_lookups = p + 1;
if ((hquery->want_family == AF_INET6) ||
(hquery->want_family == AF_UNSPEC)) {
/* if inet6 or unspec, start out with AAAA */
hquery->sent_family = AF_INET6;
ares_search(hquery->channel, hquery->name, C_IN, T_AAAA,
host_callback, hquery);
}
else {
hquery->sent_family = AF_INET;
ares_search(hquery->channel, hquery->name, C_IN, T_A,
host_callback, hquery);
}
return;
case 'f':
/* Host file lookup */
status = file_lookup(hquery->name, hquery->want_family, &host);
/* this status check below previously checked for !ARES_ENOTFOUND,
but we should not assume that this single error code is the one
that can occur, as that is in fact no longer the case */
if (status == ARES_SUCCESS)
{
end_hquery(hquery, status, host);
return;
}
status = status_code; /* Use original status code */
break;
}
}
end_hquery(hquery, status, NULL);
}
static void host_callback(void *arg, int status, int timeouts,
unsigned char *abuf, int alen)
{
struct host_query *hquery = (struct host_query *) arg;
ares_channel channel = hquery->channel;
struct hostent *host = NULL;
hquery->timeouts += timeouts;
if (status == ARES_SUCCESS)
{
if (hquery->sent_family == AF_INET)
{
status = ares_parse_a_reply(abuf, alen, &host, NULL, NULL);
if (host && channel->nsort)
sort_addresses(host, channel->sortlist, channel->nsort);
}
else if (hquery->sent_family == AF_INET6)
{
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
(status == ARES_SUCCESS && host && host->h_addr_list[0] == NULL)) &&
hquery->want_family == AF_UNSPEC) {
/* The query returned something but either there were no AAAA
records (e.g. just CNAME) or the response was malformed. Try
looking up A instead. */
if (host)
ares_free_hostent(host);
hquery->sent_family = AF_INET;
ares_search(hquery->channel, hquery->name, C_IN, T_A,
host_callback, hquery);
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.586 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )