summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGisle Vanem <gvanem@broadpark.no>2004-11-10 14:23:20 +0000
committerGisle Vanem <gvanem@broadpark.no>2004-11-10 14:23:20 +0000
commit6c64cc8669d74d097a6d090a0f82a528bfba7f77 (patch)
tree62f80a4a085de2e0a502dcdfc7b38fbcf5af3a31
parenteadf3e7f0dad52d6a13b1e8615ec110434380236 (diff)
downloadc-ares-6c64cc8669d74d097a6d090a0f82a528bfba7f77.tar.gz
c-ares-6c64cc8669d74d097a6d090a0f82a528bfba7f77.tar.bz2
c-ares-6c64cc8669d74d097a6d090a0f82a528bfba7f77.zip
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.
-rw-r--r--ares_fds.c29
-rw-r--r--ares_gethostbyaddr.c80
-rw-r--r--ares_gethostbyname.c114
-rw-r--r--ares_init.c185
-rw-r--r--windows_port.c20
5 files changed, 218 insertions, 210 deletions
diff --git a/ares_fds.c b/ares_fds.c
index dd91745..0740a98 100644
--- a/ares_fds.c
+++ b/ares_fds.c
@@ -26,7 +26,8 @@
int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
{
struct server_state *server;
- int i, nfds;
+ ares_socket_t nfds;
+ int i;
/* No queries, no file descriptors. */
if (!channel->queries)
@@ -37,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 nfds;
+ return (int)nfds;
}
diff --git a/ares_gethostbyaddr.c b/ares_gethostbyaddr.c
index 827ccfe..46144fc 100644
--- a/ares_gethostbyaddr.c
+++ b/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)
@@ -149,19 +149,19 @@ static int file_lookup(struct in_addr *addr, 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);
@@ -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_gethostbyname.c b/ares_gethostbyname.c
index adf2f78..a368008 100644
--- a/ares_gethostbyname.c
+++ b/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;
}
diff --git a/ares_init.c b/ares_init.c
index c245233..c79a0ae 100644
--- a/ares_init.c
+++ b/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;
@@ -305,7 +305,8 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
{
FIXED_INFO *fi = alloca (sizeof(*fi));
DWORD size = sizeof (*fi);
- DWORD (WINAPI *GetNetworkParams) (FIXED_INFO*, DWORD*); /* available only on Win-98/2000+ */
+ typedef DWORD (WINAPI* get_net_param_func) (FIXED_INFO*, DWORD*);
+ get_net_param_func GetNetworkParams; /* available only on Win-98/2000+ */
HMODULE handle;
IP_ADDR_STRING *ipAddr;
int i, count = 0;
@@ -321,7 +322,7 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
if (!handle)
return (0);
- (void*)GetNetworkParams = GetProcAddress (handle, "GetNetworkParams");
+ GetNetworkParams = (get_net_param_func) GetProcAddress (handle, "GetNetworkParams");
if (!GetNetworkParams)
goto quit;
@@ -375,7 +376,7 @@ quit:
static int init_by_resolv_conf(ares_channel channel)
{
char *line = NULL;
- int status, nservers = 0, nsort = 0;
+ int status = -1, nservers = 0, nsort = 0;
struct server_state *servers = NULL;
struct apattern *sortlist = NULL;
@@ -392,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
*/
@@ -421,7 +422,7 @@ DhcpNameServer
goto okay;
}
- if (IsNT)
+ if (IS_NT())
{
if (RegOpenKeyEx(
HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0,
@@ -663,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;
}
@@ -674,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)
@@ -702,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;
@@ -735,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);
@@ -749,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;
@@ -810,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;
@@ -820,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);
-
- /* 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)++;
- }
+ {
+ /* 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)++;
+ }
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;
@@ -875,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++;
}
@@ -893,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;
@@ -918,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;
diff --git a/windows_port.c b/windows_port.c
index 9aa72fa..e80d00d 100644
--- a/windows_port.c
+++ b/windows_port.c
@@ -39,28 +39,34 @@ ares_strcasecmp(const char *a, const char *b)
}
#endif
+/*
+ * Number of micro-seconds between the beginning of the Windows epoch
+ * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970).
+ */
+#if defined(_MSC_VER) || defined(__WATCOMC__)
+#define EPOCH_FILETIME 11644473600000000Ui64
+#else
+#define EPOCH_FILETIME 11644473600000000ULL
+#endif
+
int
ares_gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
LARGE_INTEGER li;
__int64 t;
- static int tzflag;
if (tv)
{
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
- t = li.QuadPart; /* In 100-nanosecond intervals */
-#if 0
- t -= EPOCHFILETIME; /* Offset to the Epoch time */
-#endif
- t /= 10; /* In microseconds */
+ t = li.QuadPart / 10; /* In micro-second intervals */
+ t -= EPOCH_FILETIME; /* Offset to the Epoch time */
tv->tv_sec = (long)(t / 1000000);
tv->tv_usec = (long)(t % 1000000);
}
-
+ (void) tz;
return 0;
}