Skip to content

if_nametoindex availability on windows #1110

@edo9300

Description

@edo9300

The commit #923 made the library rely on the function if_nametoindex, adding this made the library dependant on another windows library Iphlpapi.lib, the issue with this, is that this function is available only since windows vista, so on xp it won't work (and this library still offers support for that), this funciton should be loaded/checked at runtime like GetAdaptersAddresses (from the same dll) is being handled here

libevent/evutil.c

Lines 887 to 905 in 2287217

#elif defined(_WIN32)
/* 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.
*/
HMODULE lib = evutil_load_windows_system_library_(TEXT("iphlpapi.dll"));
GetAdaptersAddresses_fn_t fn;
ULONG size, res;
IP_ADAPTER_ADDRESSES *addresses = NULL, *address;
int result = -1;
#define FLAGS (GAA_FLAG_SKIP_ANYCAST | \
GAA_FLAG_SKIP_MULTICAST | \
GAA_FLAG_SKIP_DNS_SERVER)
if (!lib)
goto done;
if (!(fn = (GetAdaptersAddresses_fn_t) GetProcAddress(lib, "GetAdaptersAddresses")))
to remove this compile time dependency of the library and restore compatibility for older windows versions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions