From 67371907c2433f5233d4a669a1c9176539e9928f Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Wed, 30 Jan 2019 16:47:41 +0100 Subject: [HICN-19] Add support for Windows 10 x64 for libhicn (lib) Change-Id: I5109d5ce293265fca557c2ef952fcb1c13b9d816 Signed-off-by: Angelo Mantellini --- cmake/Modules/WindowsMacros.cmake | 6 +++--- lib/src/CMakeLists.txt | 3 +++ lib/src/common.c | 6 ++++-- lib/src/common.h | 29 +++++++++++++++++++++++++++-- lib/src/compat.c | 3 ++- lib/src/name.c | 6 ++++-- lib/src/name.h | 3 ++- lib/src/ops.c | 2 ++ lib/src/protocol/ipv4.c | 2 ++ 9 files changed, 49 insertions(+), 11 deletions(-) diff --git a/cmake/Modules/WindowsMacros.cmake b/cmake/Modules/WindowsMacros.cmake index 20f872759..0b34cde19 100644 --- a/cmake/Modules/WindowsMacros.cmake +++ b/cmake/Modules/WindowsMacros.cmake @@ -12,9 +12,9 @@ # limitations under the License. if(WIN32) - find_package_wrapper(LibEvent REQUIRED) - find_package_wrapper(OpenSSL REQUIRED) - find_package_wrapper(PThread REQUIRED) + find_package(LibEvent REQUIRED) + find_package(OpenSSL REQUIRED) + find_package(PThread REQUIRED) find_library(WSOCK32_LIBRARY wsock32 required) find_library(WS2_32_LIBRARY ws2_32 required) list(APPEND WINDOWS_LIBRARIES diff --git a/lib/src/CMakeLists.txt b/lib/src/CMakeLists.txt index 7cd4ccdaa..453119d13 100644 --- a/lib/src/CMakeLists.txt +++ b/lib/src/CMakeLists.txt @@ -53,6 +53,8 @@ list(APPEND LIBHICN_SOURCE_FILES set (COMPILER_DEFINITIONS "-DWITH_MAPME -DWITH_MAPME_FIXES") include(BuildMacros) +include(WindowsMacros) + build_library(${LIBHICN} SHARED STATIC SOURCES ${LIBHICN_SOURCE_FILES} @@ -61,6 +63,7 @@ build_library(${LIBHICN} DEFINITIONS ${COMPILER_DEFINITIONS} INSTALL_ROOT_DIR hicn INSTALL_HEADERS ${LIBHICN_HEADER_FILES} ${LIBHICN_HEADER_FILES_PROTOCOL} + LINK_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY} ) add_custom_command(TARGET hicn PRE_BUILD diff --git a/lib/src/common.c b/lib/src/common.c index 4b7c4a2a7..de4ece339 100644 --- a/lib/src/common.c +++ b/lib/src/common.c @@ -22,8 +22,10 @@ #include #include // memset #include // getaddrinfo -#include // '' -#include // '' +#ifndef _WIN32 +#include +#include +#endif #include #include "common.h" diff --git a/lib/src/common.h b/lib/src/common.h index dd488d43b..57b9078ff 100644 --- a/lib/src/common.h +++ b/lib/src/common.h @@ -74,13 +74,36 @@ typedef uint8_t u8; #define ATTR_INIT(key, value) value #endif -/* Endianness detection for Windows platforms */ #ifdef _WIN32 + /* Endianness detection for Windows platforms */ #define __ORDER_LITTLE_ENDIAN__ 0x41424344UL #define __ORDER_BIG_ENDIAN__ 0x44434241UL #define __BYTE_ORDER__ ('ABCD') + + /* Windows compatibility headers*/ +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +#define __attribute__(A) + +#ifndef IOVEC +#define IOVEC +#define UIO_MAXIOV 16 +#define IOV_MAX UIO_MAXIOV +struct iovec { + void* iov_base; + size_t iov_len; +}; +#endif + #endif + + /* * IP address types */ @@ -92,8 +115,10 @@ typedef uint8_t u8; #else -#include +#ifndef _WIN32 +#include +#endif typedef union { u32 as_u32; diff --git a/lib/src/compat.c b/lib/src/compat.c index 8b558a56e..07f92105e 100644 --- a/lib/src/compat.c +++ b/lib/src/compat.c @@ -17,8 +17,9 @@ * @file compat.c * @brief Implementation of the compatibility layer. */ - +#ifndef _WIN32 #include +#endif #include // memset #include // offsetof diff --git a/lib/src/name.c b/lib/src/name.c index 6e5711252..9e409bd3b 100644 --- a/lib/src/name.c +++ b/lib/src/name.c @@ -18,7 +18,9 @@ * @brief Implementation of hICN name helpers. */ +#ifndef _WIN32 #include // inet_ptin +#endif #include #include #include // strtoul @@ -614,13 +616,13 @@ hicn_ip_pton (const char *ip_address_str, ip_address_t * ip_address) if (dst_len > IPV6_ADDR_LEN_BITS) goto ERR; pton_fd = inet_pton (AF_INET6, addr, &ip_address->buffer); - ip_address->prefix_len = dst_len ? : IPV6_ADDR_LEN_BITS; + ip_address->prefix_len = dst_len ? dst_len : IPV6_ADDR_LEN_BITS; break; case AF_INET: if (dst_len > IPV4_ADDR_LEN_BITS) goto ERR; pton_fd = inet_pton (AF_INET, addr, &ip_address->buffer); - ip_address->prefix_len = dst_len ? : IPV4_ADDR_LEN_BITS; + ip_address->prefix_len = dst_len ? dst_len : IPV4_ADDR_LEN_BITS; break; default: goto ERR; diff --git a/lib/src/name.h b/lib/src/name.h index ffcb4a451..0fe8f7446 100644 --- a/lib/src/name.h +++ b/lib/src/name.h @@ -25,8 +25,9 @@ #define HICN_NAME_H #include +#ifndef _WIN32 #include // struct sockadd - +#endif #include "common.h" /****************************************************************************** diff --git a/lib/src/ops.c b/lib/src/ops.c index ad45a13a5..4ccf131b5 100644 --- a/lib/src/ops.c +++ b/lib/src/ops.c @@ -18,7 +18,9 @@ * @brief Initializers for protocol-independent packet operations */ +#ifndef _WIN32 #include +#endif #include #include "ops.h" diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c index 7c6af127d..c0b2aaa8c 100644 --- a/lib/src/protocol/ipv4.c +++ b/lib/src/protocol/ipv4.c @@ -20,8 +20,10 @@ * NOTE: IPv4 options (affecting the header size) are currently not supported. */ +#ifndef _WIN32 #include #include +#endif #include #include -- cgit 1.2.3-korg