diff options
Diffstat (limited to 'ares')
-rw-r--r-- | ares/Makefile.inc | 5 | ||||
-rw-r--r-- | ares/Makefile.vc6 | 9 | ||||
-rw-r--r-- | ares/acountry.c | 9 | ||||
-rw-r--r-- | ares/adig.c | 9 | ||||
-rw-r--r-- | ares/ahost.c | 9 | ||||
-rw-r--r-- | ares/ares.h | 14 | ||||
-rw-r--r-- | ares/ares_init.c | 34 | ||||
-rw-r--r-- | ares/ares_strerror.c | 6 | ||||
-rw-r--r-- | ares/vc/areslib/areslib.dsp | 8 |
9 files changed, 75 insertions, 28 deletions
diff --git a/ares/Makefile.inc b/ares/Makefile.inc index 586fe0649..95686c1c0 100644 --- a/ares/Makefile.inc +++ b/ares/Makefile.inc @@ -6,12 +6,13 @@ ares_timeout.c ares_destroy.c ares_mkquery.c ares_version.c \ ares_expand_name.c ares_parse_a_reply.c windows_port.c ares_strdup.c \ ares_expand_string.c ares_parse_ptr_reply.c ares_parse_aaaa_reply.c \ ares_getnameinfo.c inet_net_pton.c bitncmp.c inet_ntop.c ares_writev.c \ -ares_parse_ns_reply.c ares_llist.c ares__timeval.c ares_strcasecmp.c +ares_parse_ns_reply.c ares_llist.c ares__timeval.c ares_strcasecmp.c \ +ares_library_init.c HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h \ nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h setup_once.h \ ares_llist.h ares_strdup.h ares_strcasecmp.h ares_writev.h ares_build.h \ - ares_rules.h + ares_rules.h ares_library_init.h MANPAGES= ares_destroy.3 ares_expand_name.3 ares_expand_string.3 ares_fds.3 \ ares_free_hostent.3 ares_free_string.3 ares_gethostbyaddr.3 \ diff --git a/ares/Makefile.vc6 b/ares/Makefile.vc6 index 84352dbe5..7fb275421 100644 --- a/ares/Makefile.vc6 +++ b/ares/Makefile.vc6 @@ -63,6 +63,7 @@ OBJECTS = $(OBJ_DIR)\ares_fds.obj \ $(OBJ_DIR)\ares_strerror.obj \ $(OBJ_DIR)\ares_cancel.obj \ $(OBJ_DIR)\ares_init.obj \ + $(OBJ_DIR)\ares_library_init.obj \ $(OBJ_DIR)\ares_llist.obj \ $(OBJ_DIR)\ares_timeout.obj \ $(OBJ_DIR)\ares__timeval.obj \ @@ -110,6 +111,8 @@ $(DEF_FILE): $(OBJECTS) Makefile.VC6 @echo ares_getsock >> $@ @echo ares_init >> $@ @echo ares_init_options >> $@ + @echo ares_library_init >> $@ + @echo ares_library_cleanup >> $@ @echo ares_mkquery >> $@ @echo ares_parse_a_reply >> $@ @echo ares_parse_ptr_reply >> $@ @@ -203,7 +206,8 @@ $(OBJ_DIR)\ares_cancel.obj: ares_cancel.c setup.h setup_once.h ares.h \ ares_private.h ares_ipv6.h ares_build.h ares_rules.h $(OBJ_DIR)\ares_init.obj: ares_init.c setup.h setup_once.h nameser.h ares.h \ - ares_private.h ares_ipv6.h inet_net_pton.h ares_build.h ares_rules.h + ares_private.h ares_ipv6.h inet_net_pton.h ares_build.h ares_rules.h \ + ares_library_init.h $(OBJ_DIR)\ares_timeout.obj: ares_timeout.c setup.h setup_once.h ares.h \ ares_private.h ares_ipv6.h ares_build.h ares_rules.h @@ -260,6 +264,9 @@ $(OBJ_DIR)\inet_ntop.obj: inet_ntop.c setup.h setup_once.h nameser.h \ $(OBJ_DIR)\ares_getopt.obj: ares_getopt.c ares_getopt.h ares_build.h \ ares_rules.h +$(OBJ_DIR)\ares_library_init.obj: ares_library_init.c setup.h setup_once.h \ + ares.h ares_private.h ares_library_init.h ares_build.h ares_rules.h + $(OBJ_DIR)\ares_llist.obj: ares_llist.c setup.h setup_once.h ares.h \ ares_private.h ares_llist.h ares_build.h ares_rules.h diff --git a/ares/acountry.c b/ares/acountry.c index cac9ae5b0..1899ae962 100644 --- a/ares/acountry.c +++ b/ares/acountry.c @@ -116,6 +116,13 @@ int main(int argc, char **argv) WSAStartup(wVersionRequested, &wsaData); #endif + status = ares_library_init(ARES_LIB_INIT_ALL); + if (status != ARES_SUCCESS) + { + fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status)); + return 1; + } + while ((ch = ares_getopt(argc, argv, "dvh?")) != -1) switch (ch) { @@ -178,6 +185,8 @@ int main(int argc, char **argv) wait_ares(channel); ares_destroy(channel); + ares_library_cleanup(); + #if defined(WIN32) && !defined(WATT32) WSACleanup(); #endif diff --git a/ares/adig.c b/ares/adig.c index 7df32d9f9..8b5cb2a80 100644 --- a/ares/adig.c +++ b/ares/adig.c @@ -187,6 +187,13 @@ int main(int argc, char **argv) WSAStartup(wVersionRequested, &wsaData); #endif + status = ares_library_init(ARES_LIB_INIT_ALL); + if (status != ARES_SUCCESS) + { + fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status)); + return 1; + } + options.flags = ARES_FLAG_NOCHECKRESP; options.servers = NULL; options.nservers = 0; @@ -325,6 +332,8 @@ int main(int argc, char **argv) ares_destroy(channel); + ares_library_cleanup(); + #ifdef USE_WINSOCK WSACleanup(); #endif diff --git a/ares/ahost.c b/ares/ahost.c index 46ec735a7..0e6797e11 100644 --- a/ares/ahost.c +++ b/ares/ahost.c @@ -77,6 +77,13 @@ int main(int argc, char **argv) WSAStartup(wVersionRequested, &wsaData); #endif + status = ares_library_init(ARES_LIB_INIT_ALL); + if (status != ARES_SUCCESS) + { + fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status)); + return 1; + } + while ((c = ares_getopt(argc,argv,"dt:h")) != -1) { switch (c) @@ -147,6 +154,8 @@ int main(int argc, char **argv) ares_destroy(channel); + ares_library_cleanup(); + #ifdef USE_WINSOCK WSACleanup(); #endif diff --git a/ares/ares.h b/ares/ares.h index 38750fed7..e942d2def 100644 --- a/ares/ares.h +++ b/ares/ares.h @@ -93,6 +93,12 @@ extern "C" { #define ARES_ENONAME 19 #define ARES_EBADHINTS 20 +/* ares_library_init error codes */ +#define ARES_ELOADIPHLPAPI 21 +#define ARES_ELOADADVAPI32 22 +#define ARES_EADDRGetNetworkParams 23 +#define ARES_EADDRSYSTEMFUNCTION036 24 + /* Flag values */ #define ARES_FLAG_USEVC (1 << 0) #define ARES_FLAG_PRIMARY (1 << 1) @@ -161,6 +167,11 @@ extern "C" { #define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \ ARES_GETSOCK_MAXNUM))) +/* c-ares library initialization flag values */ +#define ARES_LIB_INIT_NONE (0) +#define ARES_LIB_INIT_WIN32 (1 << 0) +#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32) + /* * Typedef our socket type @@ -235,6 +246,9 @@ typedef void (*ares_nameinfo_callback)(void *arg, int status, int timeouts, typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd, int type, void *data); +int ares_library_init(int flags); +void ares_library_cleanup(void); + int ares_init(ares_channel *channelptr); int ares_init_options(ares_channel *channelptr, struct ares_options *options, int optmask); diff --git a/ares/ares_init.c b/ares/ares_init.c index da6a04c40..68aae2dc6 100644 --- a/ares/ares_init.c +++ b/ares/ares_init.c @@ -67,6 +67,7 @@ #include <errno.h> #include "ares.h" #include "inet_net_pton.h" +#include "ares_library_init.h" #include "ares_private.h" #ifdef WATT32 @@ -560,9 +561,6 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size) { FIXED_INFO *fi, *newfi; DWORD size = sizeof (*fi); - typedef DWORD (WINAPI* get_net_param_func) (FIXED_INFO*, DWORD*); - get_net_param_func fpGetNetworkParams; /* available only on Win-98/2000+ */ - HMODULE handle; IP_ADDR_STRING *ipAddr; int i, count = 0; int debug = 0; @@ -573,15 +571,7 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size) fi = malloc(size); if (!fi) - return (0); - - handle = LoadLibrary ("iphlpapi.dll"); - if (!handle) - goto quit; - - fpGetNetworkParams = (get_net_param_func) GetProcAddress (handle, "GetNetworkParams"); - if (!fpGetNetworkParams) - goto quit; + return 0; res = (*fpGetNetworkParams) (fi, &size); if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS)) @@ -628,14 +618,12 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size) quit: if (fi) free(fi); - if (handle) - FreeLibrary (handle); if (debug && left <= ip_size) printf ("Too many nameservers. Truncating to %d addressess", count); if (ret > ret_buf) ret[-1] = '\0'; - return (count); + return count; } #endif @@ -1497,15 +1485,13 @@ static void randomize_key(unsigned char* key,int key_data_len) int randomized = 0; int counter=0; #ifdef WIN32 - HMODULE lib=LoadLibrary("ADVAPI32.DLL"); - if (lib) { - BOOLEAN (APIENTRY *pfn)(void*, ULONG) = - (BOOLEAN (APIENTRY *)(void*,ULONG))GetProcAddress(lib,"SystemFunction036"); - if (pfn && pfn(key,key_data_len) ) - randomized = 1; - - FreeLibrary(lib); - } + BOOLEAN res; + if (fpSystemFunction036) + { + res = (*fpSystemFunction036) (key, key_data_len); + if (res) + randomized = 1; + } #else /* !WIN32 */ #ifdef RANDOM_FILE FILE *f = fopen(RANDOM_FILE, "rb"); diff --git a/ares/ares_strerror.c b/ares/ares_strerror.c index ce2edb192..4a2f4538e 100644 --- a/ares/ares_strerror.c +++ b/ares/ares_strerror.c @@ -43,7 +43,11 @@ const char *ares_strerror(int code) "Misformatted string", "Illegal flags specified", "Given hostname is not numeric", - "Illegal hints flags specified" + "Illegal hints flags specified", + "Error loading iphlpapi.dll", + "Error loading advapi32.dll", + "Unknown GetNetworkParams function address", + "Unknown SystemFunction036 function address" }; if(code >= 0 && code < (int)(sizeof(errtext) / sizeof(*errtext))) diff --git a/ares/vc/areslib/areslib.dsp b/ares/vc/areslib/areslib.dsp index 92bb4cd5b..8a8624bd9 100644 --- a/ares/vc/areslib/areslib.dsp +++ b/ares/vc/areslib/areslib.dsp @@ -145,6 +145,10 @@ SOURCE=..\..\ares_init.c # End Source File
# Begin Source File
+SOURCE=..\..\ares_library_init.c
+# End Source File
+# Begin Source File
+
SOURCE=..\..\ares_llist.c
# End Source File
# Begin Source File
@@ -237,6 +241,10 @@ SOURCE=..\..\ares_ipv6.h # End Source File
# Begin Source File
+SOURCE=..\..\ares_library_init.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\ares_llist.h
# End Source File
# Begin Source File
|