aboutsummaryrefslogtreecommitdiff
path: root/ares_library_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'ares_library_init.c')
-rw-r--r--ares_library_init.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/ares_library_init.c b/ares_library_init.c
index f0137a1..0a853d7 100644
--- a/ares_library_init.c
+++ b/ares_library_init.c
@@ -27,6 +27,7 @@
fpGetNetworkParams_t ares_fpGetNetworkParams = ZERO_NULL;
fpSystemFunction036_t ares_fpSystemFunction036 = ZERO_NULL;
fpGetAdaptersAddresses_t ares_fpGetAdaptersAddresses = ZERO_NULL;
+fpGetBestRoute2_t ares_fpGetBestRoute2 = ZERO_NULL;
#endif
/* library-private global vars with source visibility restricted to this file */
@@ -34,6 +35,11 @@ fpGetAdaptersAddresses_t ares_fpGetAdaptersAddresses = ZERO_NULL;
static unsigned int ares_initialized;
static int ares_init_flags;
+/* library-private global vars with visibility across the whole library */
+void *(*ares_malloc)(size_t size) = malloc;
+void *(*ares_realloc)(void *ptr, size_t size) = realloc;
+void (*ares_free)(void *ptr) = free;
+
#ifdef USE_WINSOCK
static HMODULE hnd_iphlpapi;
static HMODULE hnd_advapi32;
@@ -45,7 +51,7 @@ static int ares_win32_init(void)
#ifdef USE_WINSOCK
hnd_iphlpapi = 0;
- hnd_iphlpapi = LoadLibrary("iphlpapi.dll");
+ hnd_iphlpapi = LoadLibraryW(L"iphlpapi.dll");
if (!hnd_iphlpapi)
return ARES_ELOADIPHLPAPI;
@@ -66,6 +72,15 @@ static int ares_win32_init(void)
support Windows 2000 anymore */
}
+ ares_fpGetBestRoute2 = (fpGetBestRoute2_t)
+ GetProcAddress(hnd_iphlpapi, "GetBestRoute2");
+ if (!ares_fpGetBestRoute2)
+ {
+ /* This can happen on clients before Vista, I don't
+ think it should be an error, unless we don't want to
+ support Windows XP anymore */
+ }
+
/*
* When advapi32.dll is unavailable or advapi32.dll has no SystemFunction036,
* also known as RtlGenRandom, which is the case for Windows versions prior
@@ -73,7 +88,7 @@ static int ares_win32_init(void)
*/
hnd_advapi32 = 0;
- hnd_advapi32 = LoadLibrary("advapi32.dll");
+ hnd_advapi32 = LoadLibraryW(L"advapi32.dll");
if (hnd_advapi32)
{
ares_fpSystemFunction036 = (fpSystemFunction036_t)
@@ -101,14 +116,17 @@ int ares_library_init(int flags)
int res;
if (ares_initialized)
- return ARES_SUCCESS;
+ {
+ ares_initialized++;
+ return ARES_SUCCESS;
+ }
ares_initialized++;
if (flags & ARES_LIB_INIT_WIN32)
{
res = ares_win32_init();
if (res != ARES_SUCCESS)
- return res;
+ return res; /* LCOV_EXCL_LINE: can't test Win32 init failure */
}
ares_init_flags = flags;
@@ -116,17 +134,36 @@ int ares_library_init(int flags)
return ARES_SUCCESS;
}
+int ares_library_init_mem(int flags,
+ void *(*amalloc)(size_t size),
+ void (*afree)(void *ptr),
+ void *(*arealloc)(void *ptr, size_t size))
+{
+ if (amalloc)
+ ares_malloc = amalloc;
+ if (arealloc)
+ ares_realloc = arealloc;
+ if (afree)
+ ares_free = afree;
+ return ares_library_init(flags);
+}
+
void ares_library_cleanup(void)
{
if (!ares_initialized)
return;
ares_initialized--;
+ if (ares_initialized)
+ return;
if (ares_init_flags & ARES_LIB_INIT_WIN32)
ares_win32_cleanup();
ares_init_flags = ARES_LIB_INIT_NONE;
+ ares_malloc = malloc;
+ ares_realloc = realloc;
+ ares_free = free;
}
@@ -138,5 +175,3 @@ int ares_library_initialized(void)
#endif
return ARES_SUCCESS;
}
-
-