aboutsummaryrefslogtreecommitdiff
path: root/ares/ares_gethostbyname.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-12-10 21:46:00 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-12-10 21:46:00 +0000
commit070da3c08f2018aa02f18605eb58fa020ddacdc9 (patch)
tree2e6fd284a389509ce0c8159c109d3045f4f5c0d8 /ares/ares_gethostbyname.c
parent6b7f6369ece6fa217dfd39b95b040679d08faaef (diff)
untabified
Diffstat (limited to 'ares/ares_gethostbyname.c')
-rw-r--r--ares/ares_gethostbyname.c112
1 files changed, 56 insertions, 56 deletions
diff --git a/ares/ares_gethostbyname.c b/ares/ares_gethostbyname.c
index a368008c0..e03b343f1 100644
--- a/ares/ares_gethostbyname.c
+++ b/ares/ares_gethostbyname.c
@@ -50,19 +50,19 @@ struct host_query {
static void next_lookup(struct host_query *hquery);
static void host_callback(void *arg, int status, unsigned char *abuf,
- int alen);
+ int alen);
static void end_hquery(struct host_query *hquery, int status,
- struct hostent *host);
+ struct hostent *host);
static int fake_hostent(const char *name, ares_host_callback callback,
- void *arg);
+ void *arg);
static int file_lookup(const char *name, struct hostent **host);
static void sort_addresses(struct hostent *host, struct apattern *sortlist,
- int nsort);
+ int nsort);
static int get_address_index(struct in_addr *addr, struct apattern *sortlist,
- int nsort);
+ int nsort);
void ares_gethostbyname(ares_channel channel, const char *name, int family,
- ares_host_callback callback, void *arg)
+ ares_host_callback callback, void *arg)
{
struct host_query *hquery;
@@ -108,24 +108,24 @@ static void next_lookup(struct host_query *hquery)
for (p = hquery->remaining_lookups; *p; p++)
{
switch (*p)
- {
- case 'b':
- /* DNS lookup */
- hquery->remaining_lookups = p + 1;
- ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
- hquery);
- return;
-
- case 'f':
- /* Host file lookup */
- status = file_lookup(hquery->name, &host);
- if (status != ARES_ENOTFOUND)
- {
- end_hquery(hquery, status, host);
- return;
- }
- break;
- }
+ {
+ case 'b':
+ /* DNS lookup */
+ hquery->remaining_lookups = p + 1;
+ ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
+ hquery);
+ return;
+
+ case 'f':
+ /* Host file lookup */
+ status = file_lookup(hquery->name, &host);
+ if (status != ARES_ENOTFOUND)
+ {
+ end_hquery(hquery, status, host);
+ return;
+ }
+ break;
+ }
}
end_hquery(hquery, ARES_ENOTFOUND, NULL);
}
@@ -140,7 +140,7 @@ static void host_callback(void *arg, int status, unsigned char *abuf, int alen)
{
status = ares_parse_a_reply(abuf, alen, &host);
if (host && channel->nsort)
- sort_addresses(host, channel->sortlist, channel->nsort);
+ sort_addresses(host, channel->sortlist, channel->nsort);
end_hquery(hquery, status, host);
}
else if (status == ARES_EDESTRUCTION)
@@ -150,7 +150,7 @@ static void host_callback(void *arg, int status, unsigned char *abuf, int alen)
}
static void end_hquery(struct host_query *hquery, int status,
- struct hostent *host)
+ struct hostent *host)
{
hquery->callback(hquery->arg, status, host);
if (host)
@@ -163,7 +163,7 @@ static void end_hquery(struct host_query *hquery, int status,
* query immediately, and return true. Otherwise return false.
*/
static int fake_hostent(const char *name, ares_host_callback callback,
- void *arg)
+ void *arg)
{
struct in_addr addr;
struct hostent hostent;
@@ -175,7 +175,7 @@ static int fake_hostent(const char *name, ares_host_callback callback,
for (p = name; *p; p++)
{
if (!isdigit((unsigned char)*p) && *p != '.')
- return 0;
+ return 0;
}
/* It also only looks like an IP address if it's non-zero-length and
@@ -222,18 +222,18 @@ static int file_lookup(const char *name, struct hostent **host)
#ifdef WIN32
char PATH_HOSTS[MAX_PATH];
if (IS_NT()) {
- char tmp[MAX_PATH];
- HKEY hkeyHosts;
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
- == ERROR_SUCCESS)
- {
- DWORD dwLength = MAX_PATH;
- RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
- &dwLength);
- ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
- RegCloseKey(hkeyHosts);
- }
+ char tmp[MAX_PATH];
+ HKEY hkeyHosts;
+
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
+ == ERROR_SUCCESS)
+ {
+ DWORD dwLength = MAX_PATH;
+ RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
+ &dwLength);
+ ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
+ RegCloseKey(hkeyHosts);
+ }
}
else
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
@@ -255,14 +255,14 @@ static int file_lookup(const char *name, struct hostent **host)
while ((status = ares__get_hostent(fp, host)) == ARES_SUCCESS)
{
if (strcasecmp((*host)->h_name, name) == 0)
- break;
+ break;
for (alias = (*host)->h_aliases; *alias; alias++)
- {
- if (strcasecmp(*alias, name) == 0)
- break;
- }
+ {
+ if (strcasecmp(*alias, name) == 0)
+ break;
+ }
if (*alias)
- break;
+ break;
ares_free_hostent(*host);
}
fclose(fp);
@@ -274,7 +274,7 @@ static int file_lookup(const char *name, struct hostent **host)
}
static void sort_addresses(struct hostent *host, struct apattern *sortlist,
- int nsort)
+ int nsort)
{
struct in_addr a1, a2;
int i1, i2, ind1, ind2;
@@ -289,13 +289,13 @@ static void sort_addresses(struct hostent *host, struct apattern *sortlist,
memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
ind1 = get_address_index(&a1, sortlist, nsort);
for (i2 = i1 - 1; i2 >= 0; i2--)
- {
- memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
- ind2 = get_address_index(&a2, sortlist, nsort);
- if (ind2 <= ind1)
- break;
- memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
- }
+ {
+ memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
+ ind2 = get_address_index(&a2, sortlist, nsort);
+ if (ind2 <= ind1)
+ break;
+ memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
+ }
memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr));
}
}
@@ -304,14 +304,14 @@ static void sort_addresses(struct hostent *host, struct apattern *sortlist,
* if none of them match.
*/
static int get_address_index(struct in_addr *addr, struct apattern *sortlist,
- int nsort)
+ int nsort)
{
int i;
for (i = 0; i < nsort; i++)
{
if ((addr->s_addr & sortlist[i].mask.s_addr) == sortlist[i].addr.s_addr)
- break;
+ break;
}
return i;
}