From 26cbd4f43f1f4dad878c02d0a095c2fe9731c44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Macia=C5=9B?= Date: Wed, 23 Dec 2020 12:32:16 +0100 Subject: [PATCH] if_nametoindex function is now used when available --- CMakeLists.txt | 2 ++ builds/cmake/platform.hpp.in | 1 + configure.ac | 19 +++++++++++++++++++ src/ip_resolver.cpp | 4 ++-- src/udp_address.cpp | 3 +-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74dd99ae..8b548302 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,11 +546,13 @@ if(ZMQ_HAVE_WINDOWS) set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib") check_cxx_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI) + check_cxx_symbol_exists(if_nametoindex "iphlpapi.h" HAVE_IF_NAMETOINDEX) set(CMAKE_REQUIRED_LIBRARIES "") # TODO: This not the symbol we're looking for. What is the symbol? check_library_exists(ws2 fopen "" HAVE_WS2) else() + check_cxx_symbol_exists(if_nametoindex net/if.h HAVE_IF_NAMETOINDEX) check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED) check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED) endif() diff --git a/builds/cmake/platform.hpp.in b/builds/cmake/platform.hpp.in index ff75ecfb..4b69606d 100644 --- a/builds/cmake/platform.hpp.in +++ b/builds/cmake/platform.hpp.in @@ -73,6 +73,7 @@ #cmakedefine SODIUM_STATIC #cmakedefine ZMQ_USE_GNUTLS #cmakedefine ZMQ_USE_RADIX_TREE +#cmakedefine HAVE_IF_NAMETOINDEX #ifdef _AIX #define ZMQ_HAVE_AIX diff --git a/configure.ac b/configure.ac index a7a1609a..c486615b 100644 --- a/configure.ac +++ b/configure.ac @@ -788,6 +788,25 @@ AC_COMPILE_IFELSE( AC_MSG_RESULT([no]) ]) +AC_MSG_CHECKING([whether if_nametoindex is available]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #ifdef _WIN32 + #include + #else + #include + #include + #include + #endif]], [[ + if_nametoindex(""); + ]])],[ + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_IF_NAMETOINDEX, [1], + [if_nametoindex is available]) + ],[ + AC_MSG_RESULT([no]) +]) + AC_ARG_ENABLE([libbsd], [AS_HELP_STRING([--enable-libbsd], [enable libbsd [default=auto]])], diff --git a/src/ip_resolver.cpp b/src/ip_resolver.cpp index 535096d8..97d87b21 100644 --- a/src/ip_resolver.cpp +++ b/src/ip_resolver.cpp @@ -726,10 +726,10 @@ void zmq::ip_resolver_t::do_freeaddrinfo (struct addrinfo *res_) freeaddrinfo (res_); } + unsigned int zmq::ip_resolver_t::do_if_nametoindex (const char *ifname_) { -#if _WIN32_WINNT > _WIN32_WINNT_WINXP && !defined ZMQ_HAVE_WINDOWS_UWP \ - && !defined ZMQ_HAVE_VXWORKS +#ifdef HAVE_IF_NAMETOINDEX return if_nametoindex (ifname_); #else LIBZMQ_UNUSED (ifname_); diff --git a/src/udp_address.cpp b/src/udp_address.cpp index 76d4bac4..41e4770d 100644 --- a/src/udp_address.cpp +++ b/src/udp_address.cpp @@ -104,8 +104,7 @@ int zmq::udp_address_t::resolve (const char *name_, bool bind_, bool ipv6_) if (src_name == "*") { _bind_interface = 0; } else { -#if _WIN32_WINNT > _WIN32_WINNT_WINXP && !defined ZMQ_HAVE_WINDOWS_UWP \ - && !defined ZMQ_HAVE_VXWORKS +#ifdef HAVE_IF_NAMETOINDEX _bind_interface = if_nametoindex (src_name.c_str ()); if (_bind_interface == 0) { // Error, probably not an interface name.