diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-27 09:09:10 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-27 09:12:57 -0400 |
commit | 3930416dec02f801ee9c0e1d99fd782c414ffef0 (patch) | |
tree | c716bee781aa0657c6a8df2da646164cbe3b5d4c /src/lib/net | |
parent | 42b3caa6ad70106e7bca90bceca378b91045f545 (diff) | |
download | tor-3930416dec02f801ee9c0e1d99fd782c414ffef0.tar.gz tor-3930416dec02f801ee9c0e1d99fd782c414ffef0.zip |
Link GetAdaptersAddresses, rather than loading it on-demand.
This function has been present since Windows XP.
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/address.c | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 70b09b419d..69abb98a1e 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1479,17 +1479,7 @@ ip_adapter_addresses_to_smartlist(const IP_ADAPTER_ADDRESSES *addresses) STATIC smartlist_t * get_interface_addresses_win32(int severity, sa_family_t family) { - /* - XXXX We can assume that this function exists now; we can't - XXXX provide backward compatibility to pre-windows-XP. - */ - /* Windows XP began to provide GetAdaptersAddresses. Windows 2000 had a - "GetAdaptersInfo", but that's deprecated; let's just try - GetAdaptersAddresses and fall back to connect+getsockname. - */ - HANDLE lib = load_windows_system_library(TEXT("iphlpapi.dll")); smartlist_t *result = NULL; - GetAdaptersAddresses_fn_t fn; ULONG size, res; IP_ADAPTER_ADDRESSES *addresses = NULL; @@ -1499,27 +1489,16 @@ get_interface_addresses_win32(int severity, sa_family_t family) GAA_FLAG_SKIP_MULTICAST | \ GAA_FLAG_SKIP_DNS_SERVER) - if (!lib) { - log_fn(severity, LD_NET, "Unable to load iphlpapi.dll"); - goto done; - } - - if (!(fn = (GetAdaptersAddresses_fn_t) - GetProcAddress(lib, "GetAdaptersAddresses"))) { - log_fn(severity, LD_NET, "Unable to obtain pointer to " - "GetAdaptersAddresses"); - goto done; - } - /* Guess how much space we need. */ size = 15*1024; addresses = tor_malloc(size); - res = fn(family, FLAGS, NULL, addresses, &size); + /* Exists in windows XP and later. */ + res = GetAdaptersAddresses(family, FLAGS, NULL, addresses, &size); if (res == ERROR_BUFFER_OVERFLOW) { /* we didn't guess that we needed enough space; try again */ tor_free(addresses); addresses = tor_malloc(size); - res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); + res = GetAdaptersAddresses(AF_UNSPEC, FLAGS, NULL, addresses, &size); } if (res != NO_ERROR) { log_fn(severity, LD_NET, "GetAdaptersAddresses failed (result: %lu)", res); @@ -1529,8 +1508,6 @@ get_interface_addresses_win32(int severity, sa_family_t family) result = ip_adapter_addresses_to_smartlist(addresses); done: - if (lib) - FreeLibrary(lib); tor_free(addresses); return result; } |