From 6ddc59dadf33bcbe667a750ba72e867f463eb8ed Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Wed, 10 Nov 2004 14:23:20 +0000 Subject: Replace IsNT with IS_NT(). Return correct timeval in windows_port.c. Squelch gcc warnings: use 'ares_socket_t' in ares_fds.c. Don't cast a 'lvalue' in ares_init.c. --- ares/ares_gethostbyname.c | 114 +++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'ares/ares_gethostbyname.c') diff --git a/ares/ares_gethostbyname.c b/ares/ares_gethostbyname.c index adf2f78ee..a368008c0 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 @@ -221,19 +221,19 @@ static int file_lookup(const char *name, struct hostent **host) #ifdef WIN32 char PATH_HOSTS[MAX_PATH]; - if (IsNT) { - 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); - } + 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); + } } 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; } -- cgit v1.2.3