diff --git a/ares/ares_fds.c b/ares/ares_fds.c index 0740a98cb..805ce7ca6 100644 --- a/ares/ares_fds.c +++ b/ares/ares_fds.c @@ -38,19 +38,19 @@ int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds) { server = &channel->servers[i]; if (server->udp_socket != ARES_SOCKET_BAD) - { - FD_SET(server->udp_socket, read_fds); - if (server->udp_socket >= nfds) - nfds = server->udp_socket + 1; - } + { + FD_SET(server->udp_socket, read_fds); + if (server->udp_socket >= nfds) + nfds = server->udp_socket + 1; + } if (server->tcp_socket != ARES_SOCKET_BAD) - { - FD_SET(server->tcp_socket, read_fds); - if (server->qhead) - FD_SET(server->tcp_socket, write_fds); - if (server->tcp_socket >= nfds) - nfds = server->tcp_socket + 1; - } + { + FD_SET(server->tcp_socket, read_fds); + if (server->qhead) + FD_SET(server->tcp_socket, write_fds); + if (server->tcp_socket >= nfds) + nfds = server->tcp_socket + 1; + } } return (int)nfds; } diff --git a/ares/ares_gethostbyaddr.c b/ares/ares_gethostbyaddr.c index 46144fc8b..b33086c01 100644 --- a/ares/ares_gethostbyaddr.c +++ b/ares/ares_gethostbyaddr.c @@ -48,13 +48,13 @@ struct addr_query { static void next_lookup(struct addr_query *aquery); static void addr_callback(void *arg, int status, unsigned char *abuf, - int alen); + int alen); static void end_aquery(struct addr_query *aquery, int status, - struct hostent *host); + struct hostent *host); static int file_lookup(struct in_addr *addr, struct hostent **host); void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen, - int family, ares_host_callback callback, void *arg) + int family, ares_host_callback callback, void *arg) { struct addr_query *aquery; @@ -90,27 +90,27 @@ static void next_lookup(struct addr_query *aquery) for (p = aquery->remaining_lookups; *p; p++) { switch (*p) - { - case 'b': - addr = ntohl(aquery->addr.s_addr); - a1 = (int)((addr >> 24) & 0xff); - a2 = (int)((addr >> 16) & 0xff); - a3 = (int)((addr >> 8) & 0xff); - a4 = (int)(addr & 0xff); - sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1); - aquery->remaining_lookups = p + 1; - ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback, - aquery); - return; - case 'f': - status = file_lookup(&aquery->addr, &host); - if (status != ARES_ENOTFOUND) - { - end_aquery(aquery, status, host); - return; - } - break; - } + { + case 'b': + addr = ntohl(aquery->addr.s_addr); + a1 = (int)((addr >> 24) & 0xff); + a2 = (int)((addr >> 16) & 0xff); + a3 = (int)((addr >> 8) & 0xff); + a4 = (int)(addr & 0xff); + sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1); + aquery->remaining_lookups = p + 1; + ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback, + aquery); + return; + case 'f': + status = file_lookup(&aquery->addr, &host); + if (status != ARES_ENOTFOUND) + { + end_aquery(aquery, status, host); + return; + } + break; + } } end_aquery(aquery, ARES_ENOTFOUND, NULL); } @@ -123,7 +123,7 @@ static void addr_callback(void *arg, int status, unsigned char *abuf, int alen) if (status == ARES_SUCCESS) { status = ares_parse_ptr_reply(abuf, alen, &aquery->addr, - sizeof(struct in_addr), AF_INET, &host); + sizeof(struct in_addr), AF_INET, &host); end_aquery(aquery, status, host); } else if (status == ARES_EDESTRUCTION) @@ -133,7 +133,7 @@ static void addr_callback(void *arg, int status, unsigned char *abuf, int alen) } static void end_aquery(struct addr_query *aquery, int status, - struct hostent *host) + struct hostent *host) { aquery->callback(aquery->arg, status, host); if (host) @@ -150,18 +150,18 @@ static int file_lookup(struct in_addr *addr, struct hostent **host) char PATH_HOSTS[MAX_PATH]; if (IS_NT()) { - char tmp[MAX_PATH]; - HKEY 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); - } + 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); @@ -183,7 +183,7 @@ static int file_lookup(struct in_addr *addr, struct hostent **host) while ((status = ares__get_hostent(fp, host)) == ARES_SUCCESS) { if (memcmp((*host)->h_addr, addr, sizeof(struct in_addr)) == 0) - break; + break; ares_free_hostent(*host); } fclose(fp); 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 '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 '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; + 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 (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; } diff --git a/ares/ares_init.c b/ares/ares_init.c index c79a0ae3a..d4a63a361 100644 --- a/ares/ares_init.c +++ b/ares/ares_init.c @@ -50,7 +50,7 @@ #endif static int init_by_options(ares_channel channel, struct ares_options *options, - int optmask); + int optmask); static int init_by_environment(ares_channel channel); static int init_by_resolv_conf(ares_channel channel); static int init_by_defaults(ares_channel channel); @@ -58,9 +58,9 @@ static int config_domain(ares_channel channel, char *str); static int config_lookup(ares_channel channel, const char *str, const char *bindch, const char *filech); static int config_nameserver(struct server_state **servers, int *nservers, - char *str); + char *str); static int config_sortlist(struct apattern **sortlist, int *nsort, - const char *str); + const char *str); static int set_search(ares_channel channel, const char *str); static int set_options(ares_channel channel, const char *str); static char *try_config(char *s, const char *opt); @@ -74,7 +74,7 @@ int ares_init(ares_channel *channelptr) } int ares_init_options(ares_channel *channelptr, struct ares_options *options, - int optmask) + int optmask) { ares_channel channel; int i, status; @@ -116,15 +116,15 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options, { /* Something failed; clean up memory we may have allocated. */ if (channel->nservers != -1) - free(channel->servers); + free(channel->servers); if (channel->domains) - { - for (i = 0; i < channel->ndomains; i++) - free(channel->domains[i]); - free(channel->domains); - } + { + for (i = 0; i < channel->ndomains; i++) + free(channel->domains[i]); + free(channel->domains); + } if (channel->sortlist) - free(channel->sortlist); + free(channel->sortlist); if(channel->lookups) free(channel->lookups); free(channel); @@ -163,7 +163,7 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options, } static int init_by_options(ares_channel channel, struct ares_options *options, - int optmask) + int optmask) { int i; @@ -185,11 +185,11 @@ static int init_by_options(ares_channel channel, struct ares_options *options, if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1) { channel->servers = - malloc(options->nservers * sizeof(struct server_state)); + malloc(options->nservers * sizeof(struct server_state)); if (!channel->servers && options->nservers != 0) - return ARES_ENOMEM; + return ARES_ENOMEM; for (i = 0; i < options->nservers; i++) - channel->servers[i].addr = options->servers[i]; + channel->servers[i].addr = options->servers[i]; channel->nservers = options->nservers; } @@ -200,14 +200,14 @@ static int init_by_options(ares_channel channel, struct ares_options *options, { channel->domains = malloc(options->ndomains * sizeof(char *)); if (!channel->domains && options->ndomains != 0) - return ARES_ENOMEM; + return ARES_ENOMEM; for (i = 0; i < options->ndomains; i++) - { - channel->ndomains = i; - channel->domains[i] = strdup(options->domains[i]); - if (!channel->domains[i]) - return ARES_ENOMEM; - } + { + channel->ndomains = i; + channel->domains[i] = strdup(options->domains[i]); + if (!channel->domains[i]) + return ARES_ENOMEM; + } channel->ndomains = options->ndomains; } @@ -216,7 +216,7 @@ static int init_by_options(ares_channel channel, struct ares_options *options, { channel->lookups = strdup(options->lookups); if (!channel->lookups) - return ARES_ENOMEM; + return ARES_ENOMEM; } return ARES_SUCCESS; @@ -232,7 +232,7 @@ static int init_by_environment(ares_channel channel) { status = set_search(channel, localdomain); if (status != ARES_SUCCESS) - return status; + return status; } res_options = getenv("RES_OPTIONS"); @@ -240,7 +240,7 @@ static int init_by_environment(ares_channel channel) { status = set_options(channel, res_options); if (status != ARES_SUCCESS) - return status; + return status; } return ARES_SUCCESS; @@ -393,14 +393,14 @@ static int init_by_resolv_conf(ares_channel channel) On Windows 9X, the DNS server can be found in: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer - On Windows NT/2000/XP/2003: + On Windows NT/2000/XP/2003: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer - or + or HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer - or + or HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\ NameServer - or + or HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\ DhcpNameServer */ @@ -664,7 +664,7 @@ static int init_by_defaults(ares_channel channel) /* If nobody specified servers, try a local named. */ channel->servers = malloc(sizeof(struct server_state)); if (!channel->servers) - return ARES_ENOMEM; + return ARES_ENOMEM; channel->servers[0].addr.s_addr = htonl(INADDR_LOOPBACK); channel->nservers = 1; } @@ -675,22 +675,22 @@ static int init_by_defaults(ares_channel channel) * or set it to empty if the hostname isn't helpful. */ if (gethostname(hostname, sizeof(hostname)) == -1 - || !strchr(hostname, '.')) - { - channel->domains = malloc(0); - channel->ndomains = 0; - } + || !strchr(hostname, '.')) + { + channel->domains = malloc(0); + channel->ndomains = 0; + } else - { - channel->domains = malloc(sizeof(char *)); - if (!channel->domains) - return ARES_ENOMEM; - channel->ndomains = 0; - channel->domains[0] = strdup(strchr(hostname, '.') + 1); - if (!channel->domains[0]) - return ARES_ENOMEM; - channel->ndomains = 1; - } + { + channel->domains = malloc(sizeof(char *)); + if (!channel->domains) + return ARES_ENOMEM; + channel->ndomains = 0; + channel->domains[0] = strdup(strchr(hostname, '.') + 1); + if (!channel->domains[0]) + return ARES_ENOMEM; + channel->ndomains = 1; + } } if (channel->nsort == -1) @@ -703,7 +703,7 @@ static int init_by_defaults(ares_channel channel) { channel->lookups = strdup("fb"); if (!channel->lookups) - return ARES_ENOMEM; + return ARES_ENOMEM; } return ARES_SUCCESS; @@ -736,13 +736,13 @@ static int config_lookup(ares_channel channel, const char *str, while (*p) { if ((*p == *bindch || *p == *filech) && l < lookups + 2) { - if (*p == *bindch) *l++ = 'b'; + if (*p == *bindch) *l++ = 'b'; else *l++ = 'f'; } while (*p && !isspace((unsigned char)*p) && (*p != ',')) - p++; + p++; while (*p && (isspace((unsigned char)*p) || (*p == ','))) - p++; + p++; } *l = 0; channel->lookups = strdup(lookups); @@ -750,7 +750,7 @@ static int config_lookup(ares_channel channel, const char *str, } static int config_nameserver(struct server_state **servers, int *nservers, - char *str) + char *str) { struct in_addr addr; struct server_state *newserv; @@ -811,7 +811,7 @@ static int config_nameserver(struct server_state **servers, int *nservers, } static int config_sortlist(struct apattern **sortlist, int *nsort, - const char *str) + const char *str) { struct apattern pat, *newsort; const char *q; @@ -821,37 +821,37 @@ static int config_sortlist(struct apattern **sortlist, int *nsort, { q = str; while (*q && *q != '/' && *q != ';' && !isspace((unsigned char)*q)) - q++; + q++; if (ip_addr(str, (int)(q - str), &pat.addr) == 0) - { - /* We have a pattern address; now determine the mask. */ - if (*q == '/') - { - str = q + 1; - while (*q && *q != ';' && !isspace((unsigned char)*q)) - q++; - if (ip_addr(str, (int)(q - str), &pat.mask) != 0) - natural_mask(&pat); - } - else - natural_mask(&pat); + { + /* We have a pattern address; now determine the mask. */ + if (*q == '/') + { + str = q + 1; + while (*q && *q != ';' && !isspace((unsigned char)*q)) + q++; + if (ip_addr(str, (int)(q - str), &pat.mask) != 0) + natural_mask(&pat); + } + else + natural_mask(&pat); - /* Add this pattern to our list. */ - newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern)); - if (!newsort) - return ARES_ENOMEM; - newsort[*nsort] = pat; - *sortlist = newsort; - (*nsort)++; - } + /* Add this pattern to our list. */ + newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern)); + if (!newsort) + return ARES_ENOMEM; + newsort[*nsort] = pat; + *sortlist = newsort; + (*nsort)++; + } else - { - while (*q && *q != ';' && !isspace((unsigned char)*q)) - q++; - } + { + while (*q && *q != ';' && !isspace((unsigned char)*q)) + q++; + } str = q; while (isspace((unsigned char)*str)) - str++; + str++; } return ARES_SUCCESS; @@ -876,9 +876,9 @@ static int set_search(ares_channel channel, const char *str) while (*p) { while (*p && !isspace((unsigned char)*p)) - p++; + p++; while (isspace((unsigned char)*p)) - p++; + p++; n++; } @@ -894,15 +894,15 @@ static int set_search(ares_channel channel, const char *str) channel->ndomains = n; q = p; while (*q && !isspace((unsigned char)*q)) - q++; + q++; channel->domains[n] = malloc(q - p + 1); if (!channel->domains[n]) - return ARES_ENOMEM; + return ARES_ENOMEM; memcpy(channel->domains[n], p, q - p); channel->domains[n][q - p] = 0; p = q; while (isspace((unsigned char)*p)) - p++; + p++; n++; } channel->ndomains = n; @@ -919,19 +919,19 @@ static int set_options(ares_channel channel, const char *str) { q = p; while (*q && !isspace((unsigned char)*q)) - q++; + q++; val = try_option(p, q, "ndots:"); if (val && channel->ndots == -1) - channel->ndots = atoi(val); + channel->ndots = atoi(val); val = try_option(p, q, "retrans:"); if (val && channel->timeout == -1) - channel->timeout = atoi(val); + channel->timeout = atoi(val); val = try_option(p, q, "retry:"); if (val && channel->tries == -1) - channel->tries = atoi(val); + channel->tries = atoi(val); p = q; while (isspace((unsigned char)*p)) - p++; + p++; } return ARES_SUCCESS;