From f2018ab317c06cc81207288c0e9a1e2d7bb2fce6 Mon Sep 17 00:00:00 2001 From: Matt Powley Date: Thu, 31 Mar 2016 15:45:00 +0100 Subject: [PATCH] Fixes for Windows XP compatibility A Visual Studio build from master (commit id: dac5b45dfb224ff184a7aed39c5859ae5bac3803) using the v140_xp toolset yields a binary that is not XP compatible. Two libraries contain exports that cannot be found: - IPHLPAPI.DLL : if_nametoindex - KERNEL32.DLL : InitializeConditionVariable The latter export is already dealt with in the file './src/condition_variable.hpp'; however this requires setting the _WIN32_WINNT pre-processor definition. I am not experienced enough to figure a work around for the 'if_nametoindex' method, so I have created a new pre-processor definition 'ZMQ_HAVE_WINDOWS_TARGET_XP' and removed the calling of the function with the limitation that these builds cannot handle a IPv6 address with an adapter name. To make it easier for people targeting XP with an MSVC build I have modified the MSBuild property file to add/modify the pre-processor definitions if they are building using a XP targeting tool set; such as v140_xp. --- builds/msvc/properties/Common.props | 7 +++++++ src/tcp_address.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/builds/msvc/properties/Common.props b/builds/msvc/properties/Common.props index 72588d6e3b..8912290a29 100644 --- a/builds/msvc/properties/Common.props +++ b/builds/msvc/properties/Common.props @@ -18,4 +18,11 @@ + + + + ZMQ_HAVE_WINDOWS_TARGET_XP;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions) + + + \ No newline at end of file diff --git a/src/tcp_address.cpp b/src/tcp_address.cpp index e987eb8bee..53e93c6f2c 100644 --- a/src/tcp_address.cpp +++ b/src/tcp_address.cpp @@ -450,13 +450,23 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo std::string if_str = addr_str.substr(pos + 1); addr_str = addr_str.substr(0, pos); if (isalpha (if_str.at (0))) +#if !defined ZMQ_HAVE_WINDOWS_TARGET_XP zone_id = if_nametoindex(if_str.c_str()); +#else + // The function 'if_nametoindex' is not supported on Windows XP. + // If we are targeting XP using a vxxx_xp toolset then fail. + // This is brutal as this code could be run on later windows clients + // meaning the IPv6 zone_id cannot have an interface name. + // This could be fixed with a runtime check. + zone_id = 0; +#endif else zone_id = (uint32_t) atoi (if_str.c_str ()); if (zone_id == 0) { errno = EINVAL; return -1; } + } // Allow 0 specifically, to detect invalid port error in atoi if not