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 \
$(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 \
@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 >> $@
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
$(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
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)
{
wait_ares(channel);
ares_destroy(channel);
+ ares_library_cleanup();
+
#if defined(WIN32) && !defined(WATT32)
WSACleanup();
#endif
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;
ares_destroy(channel);
+ ares_library_cleanup();
+
#ifdef USE_WINSOCK
WSACleanup();
#endif
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)
ares_destroy(channel);
+ ares_library_cleanup();
+
#ifdef USE_WINSOCK
WSACleanup();
#endif
#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)
#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
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);
#include <errno.h>
#include "ares.h"
#include "inet_net_pton.h"
+#include "ares_library_init.h"
#include "ares_private.h"
#ifdef WATT32
{
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;
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))
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
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");
"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)))
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\ares_library_init.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\ares_llist.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\ares_library_init.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\ares_llist.h\r
# End Source File\r
# Begin Source File\r