Skip to content

Commit 26cbd4f

Browse files
author
Stanisław Maciaś
committed
if_nametoindex function is now used when available
1 parent 1014005 commit 26cbd4f

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,13 @@ if(ZMQ_HAVE_WINDOWS)
546546

547547
set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib")
548548
check_cxx_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI)
549+
check_cxx_symbol_exists(if_nametoindex "iphlpapi.h" HAVE_IF_NAMETOINDEX)
549550

550551
set(CMAKE_REQUIRED_LIBRARIES "")
551552
# TODO: This not the symbol we're looking for. What is the symbol?
552553
check_library_exists(ws2 fopen "" HAVE_WS2)
553554
else()
555+
check_cxx_symbol_exists(if_nametoindex net/if.h HAVE_IF_NAMETOINDEX)
554556
check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED)
555557
check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED)
556558
endif()

builds/cmake/platform.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#cmakedefine SODIUM_STATIC
7474
#cmakedefine ZMQ_USE_GNUTLS
7575
#cmakedefine ZMQ_USE_RADIX_TREE
76+
#cmakedefine HAVE_IF_NAMETOINDEX
7677

7778
#ifdef _AIX
7879
#define ZMQ_HAVE_AIX

configure.ac

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,25 @@ AC_COMPILE_IFELSE(
788788
AC_MSG_RESULT([no])
789789
])
790790

791+
AC_MSG_CHECKING([whether if_nametoindex is available])
792+
AC_COMPILE_IFELSE(
793+
[AC_LANG_PROGRAM([[
794+
#ifdef _WIN32
795+
#include <iphlpapi.h>
796+
#else
797+
#include <sys/types.h>
798+
#include <sys/socket.h>
799+
#include <net/if.h>
800+
#endif]], [[
801+
if_nametoindex("");
802+
]])],[
803+
AC_MSG_RESULT([yes])
804+
AC_DEFINE(HAVE_IF_NAMETOINDEX, [1],
805+
[if_nametoindex is available])
806+
],[
807+
AC_MSG_RESULT([no])
808+
])
809+
791810
AC_ARG_ENABLE([libbsd],
792811
[AS_HELP_STRING([--enable-libbsd],
793812
[enable libbsd [default=auto]])],

src/ip_resolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,10 @@ void zmq::ip_resolver_t::do_freeaddrinfo (struct addrinfo *res_)
726726
freeaddrinfo (res_);
727727
}
728728

729+
729730
unsigned int zmq::ip_resolver_t::do_if_nametoindex (const char *ifname_)
730731
{
731-
#if _WIN32_WINNT > _WIN32_WINNT_WINXP && !defined ZMQ_HAVE_WINDOWS_UWP \
732-
&& !defined ZMQ_HAVE_VXWORKS
732+
#ifdef HAVE_IF_NAMETOINDEX
733733
return if_nametoindex (ifname_);
734734
#else
735735
LIBZMQ_UNUSED (ifname_);

src/udp_address.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ int zmq::udp_address_t::resolve (const char *name_, bool bind_, bool ipv6_)
104104
if (src_name == "*") {
105105
_bind_interface = 0;
106106
} else {
107-
#if _WIN32_WINNT > _WIN32_WINNT_WINXP && !defined ZMQ_HAVE_WINDOWS_UWP \
108-
&& !defined ZMQ_HAVE_VXWORKS
107+
#ifdef HAVE_IF_NAMETOINDEX
109108
_bind_interface = if_nametoindex (src_name.c_str ());
110109
if (_bind_interface == 0) {
111110
// Error, probably not an interface name.

0 commit comments

Comments
 (0)