aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Mantellini <manangel@cisco.com>2019-01-30 16:47:41 +0100
committerAngelo Mantellini <manangel@cisco.com>2019-01-30 17:43:09 +0100
commit67371907c2433f5233d4a669a1c9176539e9928f (patch)
treeb4b5119c495fde382fc7c70d4398c943364c2372
parente5145b878f9de35676085409878a66899d2ee4f2 (diff)
[HICN-19] Add support for Windows 10 x64 for libhicn (lib)
Change-Id: I5109d5ce293265fca557c2ef952fcb1c13b9d816 Signed-off-by: Angelo Mantellini <manangel@cisco.com>
-rw-r--r--cmake/Modules/WindowsMacros.cmake6
-rw-r--r--lib/src/CMakeLists.txt3
-rw-r--r--lib/src/common.c6
-rw-r--r--lib/src/common.h29
-rw-r--r--lib/src/compat.c3
-rw-r--r--lib/src/name.c6
-rw-r--r--lib/src/name.h3
-rw-r--r--lib/src/ops.c2
-rw-r--r--lib/src/protocol/ipv4.c2
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 <stdlib.h>
#include <string.h> // memset
#include <sys/types.h> // getaddrinfo
-#include <sys/socket.h> // ''
-#include <netdb.h> // ''
+#ifndef _WIN32
+#include <sys/socket.h>
+#include <netdb.h>
+#endif
#include <stdio.h>
#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 <windows.h>
+#include <winsock2.h>
+#include <ws2ipdef.h>
+#include <Ws2tcpip.h>
+#include <In6addr.h>
+
+#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 <netinet/in.h>
+#ifndef _WIN32
+#include <netinet/in.h>
+#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 <netinet/in.h>
+#endif
#include <string.h> // memset
#include <stddef.h> // 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 <arpa/inet.h> // inet_ptin
+#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> // 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 <stdbool.h>
+#ifndef _WIN32
#include <netinet/in.h> // 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 <netinet/in.h>
+#endif
#include <stdlib.h>
#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 <arpa/inet.h>
#include <netinet/in.h>
+#endif
#include <stdlib.h>
#include <string.h>