summaryrefslogtreecommitdiff
path: root/ares_gethostbyname.c
diff options
context:
space:
mode:
authorYu Jiung <jiung.yu@samsung.com>2016-11-10 07:24:08 (GMT)
committerYu Jiung <jiung.yu@samsung.com>2016-11-10 07:25:02 (GMT)
commit8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8 (patch)
tree81f0750d91aa467df3ee81cf30d22a65db2e6685 /ares_gethostbyname.c
parentccccebb78520ec3a26a18370936516b12ae5d53a (diff)
parent45e88a8337839e5fd88519bc55467053d521c9f6 (diff)
downloadc-ares-8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8.zip
c-ares-8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8.tar.gz
c-ares-8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8.tar.bz2
Conflicts: packaging/c-ares.spec Change-Id: I1ec10e394aed3ef19ee21fefbe3aba7d7a615c74
Diffstat (limited to 'ares_gethostbyname.c')
-rw-r--r--ares_gethostbyname.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c
index 5bb0d35..caab6ae 100644
--- a/ares_gethostbyname.c
+++ b/ares_gethostbyname.c
@@ -99,18 +99,18 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
return;
/* Allocate and fill in the host query structure. */
- hquery = malloc(sizeof(struct host_query));
+ hquery = ares_malloc(sizeof(struct host_query));
if (!hquery)
{
callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
hquery->channel = channel;
- hquery->name = strdup(name);
+ hquery->name = ares_strdup(name);
hquery->want_family = family;
hquery->sent_family = -1; /* nothing is sent yet */
if (!hquery->name) {
- free(hquery);
+ ares_free(hquery);
callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
@@ -188,11 +188,14 @@ static void host_callback(void *arg, int status, int timeouts,
else if (hquery->sent_family == AF_INET6)
{
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
- if ((status == ARES_ENODATA || status == ARES_EBADRESP) &&
- hquery->want_family == AF_UNSPEC) {
+ 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);
@@ -224,8 +227,8 @@ static void end_hquery(struct host_query *hquery, int status,
hquery->callback(hquery->arg, status, hquery->timeouts, host);
if (host)
ares_free_hostent(host);
- free(hquery->name);
- free(hquery);
+ ares_free(hquery->name);
+ ares_free(hquery);
}
/* If the name looks like an IP address, fake up a host entry, end the
@@ -284,7 +287,7 @@ static int fake_hostent(const char *name, int family,
addrs[0] = (char *)&in6;
}
/* Duplicate the name, to avoid a constness violation. */
- hostent.h_name = strdup(name);
+ hostent.h_name = ares_strdup(name);
if (!hostent.h_name)
{
callback(arg, ARES_ENOMEM, 0, NULL);
@@ -298,7 +301,7 @@ static int fake_hostent(const char *name, int family,
hostent.h_addr_list = addrs;
callback(arg, ARES_SUCCESS, 0, &hostent);
- free((char *)(hostent.h_name));
+ ares_free((char *)(hostent.h_name));
return 1;
}
@@ -373,7 +376,7 @@ static int file_lookup(const char *name, int family, struct hostent **host)
return ARES_ENOTFOUND;
#endif
- fp = fopen(PATH_HOSTS, "re");
+ fp = fopen(PATH_HOSTS, "r");
if (!fp)
{
error = ERRNO;