Alien-cares
view release on metacpan or search on metacpan
libcares/ares_search.c view on Meta::CPAN
const char *p, *q;
int error;
/* If the name contains a trailing dot, then the single query is the name
* sans the trailing dot.
*/
if ((len > 0) && (name[len - 1] == '.'))
{
*s = ares_strdup(name);
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
}
if (!(channel->flags & ARES_FLAG_NOALIASES) && !strchr(name, '.'))
{
/* The name might be a host alias. */
hostaliases = getenv("HOSTALIASES");
if (hostaliases)
{
fp = fopen(hostaliases, "r");
if (fp)
{
while ((status = ares__read_line(fp, &line, &linesize))
== ARES_SUCCESS)
{
if (strncasecmp(line, name, len) != 0 ||
!ISSPACE(line[len]))
continue;
p = line + len;
while (ISSPACE(*p))
p++;
if (*p)
{
q = p + 1;
while (*q && !ISSPACE(*q))
q++;
*s = ares_malloc(q - p + 1);
if (*s)
{
memcpy(*s, p, q - p);
(*s)[q - p] = 0;
}
ares_free(line);
fclose(fp);
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
}
}
ares_free(line);
fclose(fp);
if (status != ARES_SUCCESS && status != ARES_EOF)
return status;
}
else
{
error = ERRNO;
switch(error)
{
case ENOENT:
case ESRCH:
break;
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
error, strerror(error)));
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
hostaliases));
*s = NULL;
return ARES_EFILE;
}
}
}
}
if (channel->flags & ARES_FLAG_NOSEARCH || channel->ndomains == 0)
{
/* No domain search to do; just try the name as-is. */
*s = ares_strdup(name);
return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
}
*s = NULL;
return ARES_SUCCESS;
}
( run in 1.065 second using v1.01-cache-2.11-cpan-2398b32b56e )