untabified
This commit is contained in:
Родитель
6b7f6369ec
Коммит
070da3c08f
|
@ -38,19 +38,19 @@ int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
|
||||||
{
|
{
|
||||||
server = &channel->servers[i];
|
server = &channel->servers[i];
|
||||||
if (server->udp_socket != ARES_SOCKET_BAD)
|
if (server->udp_socket != ARES_SOCKET_BAD)
|
||||||
{
|
{
|
||||||
FD_SET(server->udp_socket, read_fds);
|
FD_SET(server->udp_socket, read_fds);
|
||||||
if (server->udp_socket >= nfds)
|
if (server->udp_socket >= nfds)
|
||||||
nfds = server->udp_socket + 1;
|
nfds = server->udp_socket + 1;
|
||||||
}
|
}
|
||||||
if (server->tcp_socket != ARES_SOCKET_BAD)
|
if (server->tcp_socket != ARES_SOCKET_BAD)
|
||||||
{
|
{
|
||||||
FD_SET(server->tcp_socket, read_fds);
|
FD_SET(server->tcp_socket, read_fds);
|
||||||
if (server->qhead)
|
if (server->qhead)
|
||||||
FD_SET(server->tcp_socket, write_fds);
|
FD_SET(server->tcp_socket, write_fds);
|
||||||
if (server->tcp_socket >= nfds)
|
if (server->tcp_socket >= nfds)
|
||||||
nfds = server->tcp_socket + 1;
|
nfds = server->tcp_socket + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (int)nfds;
|
return (int)nfds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,13 @@ struct addr_query {
|
||||||
|
|
||||||
static void next_lookup(struct addr_query *aquery);
|
static void next_lookup(struct addr_query *aquery);
|
||||||
static void addr_callback(void *arg, int status, unsigned char *abuf,
|
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,
|
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);
|
static int file_lookup(struct in_addr *addr, struct hostent **host);
|
||||||
|
|
||||||
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
|
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;
|
struct addr_query *aquery;
|
||||||
|
|
||||||
|
@ -90,27 +90,27 @@ static void next_lookup(struct addr_query *aquery)
|
||||||
for (p = aquery->remaining_lookups; *p; p++)
|
for (p = aquery->remaining_lookups; *p; p++)
|
||||||
{
|
{
|
||||||
switch (*p)
|
switch (*p)
|
||||||
{
|
{
|
||||||
case 'b':
|
case 'b':
|
||||||
addr = ntohl(aquery->addr.s_addr);
|
addr = ntohl(aquery->addr.s_addr);
|
||||||
a1 = (int)((addr >> 24) & 0xff);
|
a1 = (int)((addr >> 24) & 0xff);
|
||||||
a2 = (int)((addr >> 16) & 0xff);
|
a2 = (int)((addr >> 16) & 0xff);
|
||||||
a3 = (int)((addr >> 8) & 0xff);
|
a3 = (int)((addr >> 8) & 0xff);
|
||||||
a4 = (int)(addr & 0xff);
|
a4 = (int)(addr & 0xff);
|
||||||
sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
|
sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
|
||||||
aquery->remaining_lookups = p + 1;
|
aquery->remaining_lookups = p + 1;
|
||||||
ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
|
ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
|
||||||
aquery);
|
aquery);
|
||||||
return;
|
return;
|
||||||
case 'f':
|
case 'f':
|
||||||
status = file_lookup(&aquery->addr, &host);
|
status = file_lookup(&aquery->addr, &host);
|
||||||
if (status != ARES_ENOTFOUND)
|
if (status != ARES_ENOTFOUND)
|
||||||
{
|
{
|
||||||
end_aquery(aquery, status, host);
|
end_aquery(aquery, status, host);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end_aquery(aquery, ARES_ENOTFOUND, NULL);
|
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)
|
if (status == ARES_SUCCESS)
|
||||||
{
|
{
|
||||||
status = ares_parse_ptr_reply(abuf, alen, &aquery->addr,
|
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);
|
end_aquery(aquery, status, host);
|
||||||
}
|
}
|
||||||
else if (status == ARES_EDESTRUCTION)
|
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,
|
static void end_aquery(struct addr_query *aquery, int status,
|
||||||
struct hostent *host)
|
struct hostent *host)
|
||||||
{
|
{
|
||||||
aquery->callback(aquery->arg, status, host);
|
aquery->callback(aquery->arg, status, host);
|
||||||
if (host)
|
if (host)
|
||||||
|
@ -150,18 +150,18 @@ static int file_lookup(struct in_addr *addr, struct hostent **host)
|
||||||
|
|
||||||
char PATH_HOSTS[MAX_PATH];
|
char PATH_HOSTS[MAX_PATH];
|
||||||
if (IS_NT()) {
|
if (IS_NT()) {
|
||||||
char tmp[MAX_PATH];
|
char tmp[MAX_PATH];
|
||||||
HKEY hkeyHosts;
|
HKEY hkeyHosts;
|
||||||
|
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
|
||||||
== ERROR_SUCCESS)
|
== ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DWORD dwLength = MAX_PATH;
|
DWORD dwLength = MAX_PATH;
|
||||||
RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
|
RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
|
||||||
&dwLength);
|
&dwLength);
|
||||||
ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
|
ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
|
||||||
RegCloseKey(hkeyHosts);
|
RegCloseKey(hkeyHosts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
|
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)
|
while ((status = ares__get_hostent(fp, host)) == ARES_SUCCESS)
|
||||||
{
|
{
|
||||||
if (memcmp((*host)->h_addr, addr, sizeof(struct in_addr)) == 0)
|
if (memcmp((*host)->h_addr, addr, sizeof(struct in_addr)) == 0)
|
||||||
break;
|
break;
|
||||||
ares_free_hostent(*host);
|
ares_free_hostent(*host);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
|
@ -50,19 +50,19 @@ struct host_query {
|
||||||
|
|
||||||
static void next_lookup(struct host_query *hquery);
|
static void next_lookup(struct host_query *hquery);
|
||||||
static void host_callback(void *arg, int status, unsigned char *abuf,
|
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,
|
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,
|
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 int file_lookup(const char *name, struct hostent **host);
|
||||||
static void sort_addresses(struct hostent *host, struct apattern *sortlist,
|
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,
|
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,
|
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;
|
struct host_query *hquery;
|
||||||
|
|
||||||
|
@ -108,24 +108,24 @@ static void next_lookup(struct host_query *hquery)
|
||||||
for (p = hquery->remaining_lookups; *p; p++)
|
for (p = hquery->remaining_lookups; *p; p++)
|
||||||
{
|
{
|
||||||
switch (*p)
|
switch (*p)
|
||||||
{
|
{
|
||||||
case 'b':
|
case 'b':
|
||||||
/* DNS lookup */
|
/* DNS lookup */
|
||||||
hquery->remaining_lookups = p + 1;
|
hquery->remaining_lookups = p + 1;
|
||||||
ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
|
ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
|
||||||
hquery);
|
hquery);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
/* Host file lookup */
|
/* Host file lookup */
|
||||||
status = file_lookup(hquery->name, &host);
|
status = file_lookup(hquery->name, &host);
|
||||||
if (status != ARES_ENOTFOUND)
|
if (status != ARES_ENOTFOUND)
|
||||||
{
|
{
|
||||||
end_hquery(hquery, status, host);
|
end_hquery(hquery, status, host);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end_hquery(hquery, ARES_ENOTFOUND, NULL);
|
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);
|
status = ares_parse_a_reply(abuf, alen, &host);
|
||||||
if (host && channel->nsort)
|
if (host && channel->nsort)
|
||||||
sort_addresses(host, channel->sortlist, channel->nsort);
|
sort_addresses(host, channel->sortlist, channel->nsort);
|
||||||
end_hquery(hquery, status, host);
|
end_hquery(hquery, status, host);
|
||||||
}
|
}
|
||||||
else if (status == ARES_EDESTRUCTION)
|
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,
|
static void end_hquery(struct host_query *hquery, int status,
|
||||||
struct hostent *host)
|
struct hostent *host)
|
||||||
{
|
{
|
||||||
hquery->callback(hquery->arg, status, host);
|
hquery->callback(hquery->arg, status, host);
|
||||||
if (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.
|
* query immediately, and return true. Otherwise return false.
|
||||||
*/
|
*/
|
||||||
static int fake_hostent(const char *name, ares_host_callback callback,
|
static int fake_hostent(const char *name, ares_host_callback callback,
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
struct hostent hostent;
|
struct hostent hostent;
|
||||||
|
@ -175,7 +175,7 @@ static int fake_hostent(const char *name, ares_host_callback callback,
|
||||||
for (p = name; *p; p++)
|
for (p = name; *p; p++)
|
||||||
{
|
{
|
||||||
if (!isdigit((unsigned char)*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
|
/* 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
|
#ifdef WIN32
|
||||||
char PATH_HOSTS[MAX_PATH];
|
char PATH_HOSTS[MAX_PATH];
|
||||||
if (IS_NT()) {
|
if (IS_NT()) {
|
||||||
char tmp[MAX_PATH];
|
char tmp[MAX_PATH];
|
||||||
HKEY hkeyHosts;
|
HKEY hkeyHosts;
|
||||||
|
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
|
||||||
== ERROR_SUCCESS)
|
== ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DWORD dwLength = MAX_PATH;
|
DWORD dwLength = MAX_PATH;
|
||||||
RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
|
RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
|
||||||
&dwLength);
|
&dwLength);
|
||||||
ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
|
ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
|
||||||
RegCloseKey(hkeyHosts);
|
RegCloseKey(hkeyHosts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
|
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)
|
while ((status = ares__get_hostent(fp, host)) == ARES_SUCCESS)
|
||||||
{
|
{
|
||||||
if (strcasecmp((*host)->h_name, name) == 0)
|
if (strcasecmp((*host)->h_name, name) == 0)
|
||||||
break;
|
break;
|
||||||
for (alias = (*host)->h_aliases; *alias; alias++)
|
for (alias = (*host)->h_aliases; *alias; alias++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(*alias, name) == 0)
|
if (strcasecmp(*alias, name) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*alias)
|
if (*alias)
|
||||||
break;
|
break;
|
||||||
ares_free_hostent(*host);
|
ares_free_hostent(*host);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
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,
|
static void sort_addresses(struct hostent *host, struct apattern *sortlist,
|
||||||
int nsort)
|
int nsort)
|
||||||
{
|
{
|
||||||
struct in_addr a1, a2;
|
struct in_addr a1, a2;
|
||||||
int i1, i2, ind1, ind2;
|
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));
|
memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
|
||||||
ind1 = get_address_index(&a1, sortlist, nsort);
|
ind1 = get_address_index(&a1, sortlist, nsort);
|
||||||
for (i2 = i1 - 1; i2 >= 0; i2--)
|
for (i2 = i1 - 1; i2 >= 0; i2--)
|
||||||
{
|
{
|
||||||
memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
|
memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
|
||||||
ind2 = get_address_index(&a2, sortlist, nsort);
|
ind2 = get_address_index(&a2, sortlist, nsort);
|
||||||
if (ind2 <= ind1)
|
if (ind2 <= ind1)
|
||||||
break;
|
break;
|
||||||
memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
|
memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
|
||||||
}
|
}
|
||||||
memcpy(host->h_addr_list[i2 + 1], &a1, 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.
|
* if none of them match.
|
||||||
*/
|
*/
|
||||||
static int get_address_index(struct in_addr *addr, struct apattern *sortlist,
|
static int get_address_index(struct in_addr *addr, struct apattern *sortlist,
|
||||||
int nsort)
|
int nsort)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < nsort; i++)
|
for (i = 0; i < nsort; i++)
|
||||||
{
|
{
|
||||||
if ((addr->s_addr & sortlist[i].mask.s_addr) == sortlist[i].addr.s_addr)
|
if ((addr->s_addr & sortlist[i].mask.s_addr) == sortlist[i].addr.s_addr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
174
ares/ares_init.c
174
ares/ares_init.c
|
@ -50,7 +50,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int init_by_options(ares_channel channel, struct ares_options *options,
|
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_environment(ares_channel channel);
|
||||||
static int init_by_resolv_conf(ares_channel channel);
|
static int init_by_resolv_conf(ares_channel channel);
|
||||||
static int init_by_defaults(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,
|
static int config_lookup(ares_channel channel, const char *str,
|
||||||
const char *bindch, const char *filech);
|
const char *bindch, const char *filech);
|
||||||
static int config_nameserver(struct server_state **servers, int *nservers,
|
static int config_nameserver(struct server_state **servers, int *nservers,
|
||||||
char *str);
|
char *str);
|
||||||
static int config_sortlist(struct apattern **sortlist, int *nsort,
|
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_search(ares_channel channel, const char *str);
|
||||||
static int set_options(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);
|
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 ares_init_options(ares_channel *channelptr, struct ares_options *options,
|
||||||
int optmask)
|
int optmask)
|
||||||
{
|
{
|
||||||
ares_channel channel;
|
ares_channel channel;
|
||||||
int i, status;
|
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. */
|
/* Something failed; clean up memory we may have allocated. */
|
||||||
if (channel->nservers != -1)
|
if (channel->nservers != -1)
|
||||||
free(channel->servers);
|
free(channel->servers);
|
||||||
if (channel->domains)
|
if (channel->domains)
|
||||||
{
|
{
|
||||||
for (i = 0; i < channel->ndomains; i++)
|
for (i = 0; i < channel->ndomains; i++)
|
||||||
free(channel->domains[i]);
|
free(channel->domains[i]);
|
||||||
free(channel->domains);
|
free(channel->domains);
|
||||||
}
|
}
|
||||||
if (channel->sortlist)
|
if (channel->sortlist)
|
||||||
free(channel->sortlist);
|
free(channel->sortlist);
|
||||||
if(channel->lookups)
|
if(channel->lookups)
|
||||||
free(channel->lookups);
|
free(channel->lookups);
|
||||||
free(channel);
|
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,
|
static int init_by_options(ares_channel channel, struct ares_options *options,
|
||||||
int optmask)
|
int optmask)
|
||||||
{
|
{
|
||||||
int i;
|
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)
|
if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1)
|
||||||
{
|
{
|
||||||
channel->servers =
|
channel->servers =
|
||||||
malloc(options->nservers * sizeof(struct server_state));
|
malloc(options->nservers * sizeof(struct server_state));
|
||||||
if (!channel->servers && options->nservers != 0)
|
if (!channel->servers && options->nservers != 0)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
for (i = 0; i < options->nservers; i++)
|
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;
|
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 *));
|
channel->domains = malloc(options->ndomains * sizeof(char *));
|
||||||
if (!channel->domains && options->ndomains != 0)
|
if (!channel->domains && options->ndomains != 0)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
for (i = 0; i < options->ndomains; i++)
|
for (i = 0; i < options->ndomains; i++)
|
||||||
{
|
{
|
||||||
channel->ndomains = i;
|
channel->ndomains = i;
|
||||||
channel->domains[i] = strdup(options->domains[i]);
|
channel->domains[i] = strdup(options->domains[i]);
|
||||||
if (!channel->domains[i])
|
if (!channel->domains[i])
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
}
|
}
|
||||||
channel->ndomains = options->ndomains;
|
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);
|
channel->lookups = strdup(options->lookups);
|
||||||
if (!channel->lookups)
|
if (!channel->lookups)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ARES_SUCCESS;
|
return ARES_SUCCESS;
|
||||||
|
@ -232,7 +232,7 @@ static int init_by_environment(ares_channel channel)
|
||||||
{
|
{
|
||||||
status = set_search(channel, localdomain);
|
status = set_search(channel, localdomain);
|
||||||
if (status != ARES_SUCCESS)
|
if (status != ARES_SUCCESS)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
res_options = getenv("RES_OPTIONS");
|
res_options = getenv("RES_OPTIONS");
|
||||||
|
@ -240,7 +240,7 @@ static int init_by_environment(ares_channel channel)
|
||||||
{
|
{
|
||||||
status = set_options(channel, res_options);
|
status = set_options(channel, res_options);
|
||||||
if (status != ARES_SUCCESS)
|
if (status != ARES_SUCCESS)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ARES_SUCCESS;
|
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:
|
On Windows 9X, the DNS server can be found in:
|
||||||
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer
|
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
|
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer
|
||||||
or
|
or
|
||||||
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
|
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
|
||||||
or
|
or
|
||||||
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
|
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
|
||||||
NameServer
|
NameServer
|
||||||
or
|
or
|
||||||
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
|
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
|
||||||
DhcpNameServer
|
DhcpNameServer
|
||||||
*/
|
*/
|
||||||
|
@ -664,7 +664,7 @@ static int init_by_defaults(ares_channel channel)
|
||||||
/* If nobody specified servers, try a local named. */
|
/* If nobody specified servers, try a local named. */
|
||||||
channel->servers = malloc(sizeof(struct server_state));
|
channel->servers = malloc(sizeof(struct server_state));
|
||||||
if (!channel->servers)
|
if (!channel->servers)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
channel->servers[0].addr.s_addr = htonl(INADDR_LOOPBACK);
|
channel->servers[0].addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||||
channel->nservers = 1;
|
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.
|
* or set it to empty if the hostname isn't helpful.
|
||||||
*/
|
*/
|
||||||
if (gethostname(hostname, sizeof(hostname)) == -1
|
if (gethostname(hostname, sizeof(hostname)) == -1
|
||||||
|| !strchr(hostname, '.'))
|
|| !strchr(hostname, '.'))
|
||||||
{
|
{
|
||||||
channel->domains = malloc(0);
|
channel->domains = malloc(0);
|
||||||
channel->ndomains = 0;
|
channel->ndomains = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
channel->domains = malloc(sizeof(char *));
|
channel->domains = malloc(sizeof(char *));
|
||||||
if (!channel->domains)
|
if (!channel->domains)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
channel->ndomains = 0;
|
channel->ndomains = 0;
|
||||||
channel->domains[0] = strdup(strchr(hostname, '.') + 1);
|
channel->domains[0] = strdup(strchr(hostname, '.') + 1);
|
||||||
if (!channel->domains[0])
|
if (!channel->domains[0])
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
channel->ndomains = 1;
|
channel->ndomains = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->nsort == -1)
|
if (channel->nsort == -1)
|
||||||
|
@ -703,7 +703,7 @@ static int init_by_defaults(ares_channel channel)
|
||||||
{
|
{
|
||||||
channel->lookups = strdup("fb");
|
channel->lookups = strdup("fb");
|
||||||
if (!channel->lookups)
|
if (!channel->lookups)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ARES_SUCCESS;
|
return ARES_SUCCESS;
|
||||||
|
@ -736,13 +736,13 @@ static int config_lookup(ares_channel channel, const char *str,
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
|
if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
|
||||||
if (*p == *bindch) *l++ = 'b';
|
if (*p == *bindch) *l++ = 'b';
|
||||||
else *l++ = 'f';
|
else *l++ = 'f';
|
||||||
}
|
}
|
||||||
while (*p && !isspace((unsigned char)*p) && (*p != ','))
|
while (*p && !isspace((unsigned char)*p) && (*p != ','))
|
||||||
p++;
|
p++;
|
||||||
while (*p && (isspace((unsigned char)*p) || (*p == ',')))
|
while (*p && (isspace((unsigned char)*p) || (*p == ',')))
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*l = 0;
|
*l = 0;
|
||||||
channel->lookups = strdup(lookups);
|
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,
|
static int config_nameserver(struct server_state **servers, int *nservers,
|
||||||
char *str)
|
char *str)
|
||||||
{
|
{
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
struct server_state *newserv;
|
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,
|
static int config_sortlist(struct apattern **sortlist, int *nsort,
|
||||||
const char *str)
|
const char *str)
|
||||||
{
|
{
|
||||||
struct apattern pat, *newsort;
|
struct apattern pat, *newsort;
|
||||||
const char *q;
|
const char *q;
|
||||||
|
@ -821,37 +821,37 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
|
||||||
{
|
{
|
||||||
q = str;
|
q = str;
|
||||||
while (*q && *q != '/' && *q != ';' && !isspace((unsigned char)*q))
|
while (*q && *q != '/' && *q != ';' && !isspace((unsigned char)*q))
|
||||||
q++;
|
q++;
|
||||||
if (ip_addr(str, (int)(q - str), &pat.addr) == 0)
|
if (ip_addr(str, (int)(q - str), &pat.addr) == 0)
|
||||||
{
|
{
|
||||||
/* We have a pattern address; now determine the mask. */
|
/* We have a pattern address; now determine the mask. */
|
||||||
if (*q == '/')
|
if (*q == '/')
|
||||||
{
|
{
|
||||||
str = q + 1;
|
str = q + 1;
|
||||||
while (*q && *q != ';' && !isspace((unsigned char)*q))
|
while (*q && *q != ';' && !isspace((unsigned char)*q))
|
||||||
q++;
|
q++;
|
||||||
if (ip_addr(str, (int)(q - str), &pat.mask) != 0)
|
if (ip_addr(str, (int)(q - str), &pat.mask) != 0)
|
||||||
natural_mask(&pat);
|
natural_mask(&pat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
natural_mask(&pat);
|
natural_mask(&pat);
|
||||||
|
|
||||||
/* Add this pattern to our list. */
|
/* Add this pattern to our list. */
|
||||||
newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
|
newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
|
||||||
if (!newsort)
|
if (!newsort)
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
newsort[*nsort] = pat;
|
newsort[*nsort] = pat;
|
||||||
*sortlist = newsort;
|
*sortlist = newsort;
|
||||||
(*nsort)++;
|
(*nsort)++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (*q && *q != ';' && !isspace((unsigned char)*q))
|
while (*q && *q != ';' && !isspace((unsigned char)*q))
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
str = q;
|
str = q;
|
||||||
while (isspace((unsigned char)*str))
|
while (isspace((unsigned char)*str))
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ARES_SUCCESS;
|
return ARES_SUCCESS;
|
||||||
|
@ -876,9 +876,9 @@ static int set_search(ares_channel channel, const char *str)
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
while (*p && !isspace((unsigned char)*p))
|
while (*p && !isspace((unsigned char)*p))
|
||||||
p++;
|
p++;
|
||||||
while (isspace((unsigned char)*p))
|
while (isspace((unsigned char)*p))
|
||||||
p++;
|
p++;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -894,15 +894,15 @@ static int set_search(ares_channel channel, const char *str)
|
||||||
channel->ndomains = n;
|
channel->ndomains = n;
|
||||||
q = p;
|
q = p;
|
||||||
while (*q && !isspace((unsigned char)*q))
|
while (*q && !isspace((unsigned char)*q))
|
||||||
q++;
|
q++;
|
||||||
channel->domains[n] = malloc(q - p + 1);
|
channel->domains[n] = malloc(q - p + 1);
|
||||||
if (!channel->domains[n])
|
if (!channel->domains[n])
|
||||||
return ARES_ENOMEM;
|
return ARES_ENOMEM;
|
||||||
memcpy(channel->domains[n], p, q - p);
|
memcpy(channel->domains[n], p, q - p);
|
||||||
channel->domains[n][q - p] = 0;
|
channel->domains[n][q - p] = 0;
|
||||||
p = q;
|
p = q;
|
||||||
while (isspace((unsigned char)*p))
|
while (isspace((unsigned char)*p))
|
||||||
p++;
|
p++;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
channel->ndomains = n;
|
channel->ndomains = n;
|
||||||
|
@ -919,19 +919,19 @@ static int set_options(ares_channel channel, const char *str)
|
||||||
{
|
{
|
||||||
q = p;
|
q = p;
|
||||||
while (*q && !isspace((unsigned char)*q))
|
while (*q && !isspace((unsigned char)*q))
|
||||||
q++;
|
q++;
|
||||||
val = try_option(p, q, "ndots:");
|
val = try_option(p, q, "ndots:");
|
||||||
if (val && channel->ndots == -1)
|
if (val && channel->ndots == -1)
|
||||||
channel->ndots = atoi(val);
|
channel->ndots = atoi(val);
|
||||||
val = try_option(p, q, "retrans:");
|
val = try_option(p, q, "retrans:");
|
||||||
if (val && channel->timeout == -1)
|
if (val && channel->timeout == -1)
|
||||||
channel->timeout = atoi(val);
|
channel->timeout = atoi(val);
|
||||||
val = try_option(p, q, "retry:");
|
val = try_option(p, q, "retry:");
|
||||||
if (val && channel->tries == -1)
|
if (val && channel->tries == -1)
|
||||||
channel->tries = atoi(val);
|
channel->tries = atoi(val);
|
||||||
p = q;
|
p = q;
|
||||||
while (isspace((unsigned char)*p))
|
while (isspace((unsigned char)*p))
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ARES_SUCCESS;
|
return ARES_SUCCESS;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче