Merge pull request #4109 from stanpl/if_nametoindex_fix

Solution: if_nametoindex function is now used when available
This commit is contained in:
Luca Boccassi 2020-12-23 14:12:07 +00:00 committed by GitHub
commit a49aa0d294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 4 deletions

View File

@ -546,11 +546,13 @@ if(ZMQ_HAVE_WINDOWS)
set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib") set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib")
check_cxx_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI) 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 "") set(CMAKE_REQUIRED_LIBRARIES "")
# TODO: This not the symbol we're looking for. What is the symbol? # TODO: This not the symbol we're looking for. What is the symbol?
check_library_exists(ws2 fopen "" HAVE_WS2) check_library_exists(ws2 fopen "" HAVE_WS2)
else() 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(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED)
check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED) check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED)
endif() endif()

15
RELICENSE/stanpl.md Normal file
View File

@ -0,0 +1,15 @@
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current ZeroMQ BDFL
This is a statement by Stanisław Maciaś
that grants permission to relicense its copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current ZeroMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the Github handle "stanpl", with
commit author "Stanisław Maciaś", are copyright of Stanisław Maciaś.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Stanisław Maciaś
2020/12/23

View File

@ -73,6 +73,7 @@
#cmakedefine SODIUM_STATIC #cmakedefine SODIUM_STATIC
#cmakedefine ZMQ_USE_GNUTLS #cmakedefine ZMQ_USE_GNUTLS
#cmakedefine ZMQ_USE_RADIX_TREE #cmakedefine ZMQ_USE_RADIX_TREE
#cmakedefine HAVE_IF_NAMETOINDEX
#ifdef _AIX #ifdef _AIX
#define ZMQ_HAVE_AIX #define ZMQ_HAVE_AIX

View File

@ -788,6 +788,25 @@ AC_COMPILE_IFELSE(
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
]) ])
AC_MSG_CHECKING([whether if_nametoindex is available])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#ifdef _WIN32
#include <iphlpapi.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#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], AC_ARG_ENABLE([libbsd],
[AS_HELP_STRING([--enable-libbsd], [AS_HELP_STRING([--enable-libbsd],
[enable libbsd [default=auto]])], [enable libbsd [default=auto]])],

View File

@ -726,10 +726,10 @@ void zmq::ip_resolver_t::do_freeaddrinfo (struct addrinfo *res_)
freeaddrinfo (res_); freeaddrinfo (res_);
} }
unsigned int zmq::ip_resolver_t::do_if_nametoindex (const char *ifname_) unsigned int zmq::ip_resolver_t::do_if_nametoindex (const char *ifname_)
{ {
#if _WIN32_WINNT > _WIN32_WINNT_WINXP && !defined ZMQ_HAVE_WINDOWS_UWP \ #ifdef HAVE_IF_NAMETOINDEX
&& !defined ZMQ_HAVE_VXWORKS
return if_nametoindex (ifname_); return if_nametoindex (ifname_);
#else #else
LIBZMQ_UNUSED (ifname_); LIBZMQ_UNUSED (ifname_);

View File

@ -104,8 +104,7 @@ int zmq::udp_address_t::resolve (const char *name_, bool bind_, bool ipv6_)
if (src_name == "*") { if (src_name == "*") {
_bind_interface = 0; _bind_interface = 0;
} else { } else {
#if _WIN32_WINNT > _WIN32_WINNT_WINXP && !defined ZMQ_HAVE_WINDOWS_UWP \ #ifdef HAVE_IF_NAMETOINDEX
&& !defined ZMQ_HAVE_VXWORKS
_bind_interface = if_nametoindex (src_name.c_str ()); _bind_interface = if_nametoindex (src_name.c_str ());
if (_bind_interface == 0) { if (_bind_interface == 0) {
// Error, probably not an interface name. // Error, probably not an interface name.