From 0a0e51426506985ae1e7cf8c581d109fdad7a725 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Mon, 13 May 2019 14:42:24 +0200 Subject: [HICN-194] support for android environment Change-Id: I11a614709152035784e492ccd99bc383765a0aa1 Signed-off-by: Angelo Mantellini --- hicn-light/CMakeLists.txt | 2 + hicn-light/src/hicn/api/api.c | 5 ++ hicn-light/src/hicn/api/ip_address.h | 7 +++ lib/CMakeLists.txt | 4 -- lib/src/compat.c | 72 +++++++++++++------------- lib/src/protocol/tcp.h | 6 +-- libtransport/CMakeLists.txt | 4 ++ libtransport/src/hicn/transport/utils/membuf.h | 2 + utils/src/hiperf.cc | 2 + 9 files changed, 61 insertions(+), 43 deletions(-) diff --git a/hicn-light/CMakeLists.txt b/hicn-light/CMakeLists.txt index c9f90de6a..70ca8ed15 100644 --- a/hicn-light/CMakeLists.txt +++ b/hicn-light/CMakeLists.txt @@ -70,6 +70,8 @@ include( Packaging ) find_package(Threads REQUIRED) +find_package(OpenSSL REQUIRED) + set(HICN_LIGHT_LINK_LIBRARIES hicn-light ${HICN_LIBRARIES} diff --git a/hicn-light/src/hicn/api/api.c b/hicn-light/src/hicn/api/api.c index 9b3882379..e139734f5 100644 --- a/hicn-light/src/hicn/api/api.c +++ b/hicn-light/src/hicn/api/api.c @@ -27,6 +27,11 @@ #include // XXX debug +#ifndef bzero +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) +#endif + + #include #include #include diff --git a/hicn-light/src/hicn/api/ip_address.h b/hicn-light/src/hicn/api/ip_address.h index b58981d85..f44fb1bc3 100644 --- a/hicn-light/src/hicn/api/ip_address.h +++ b/hicn-light/src/hicn/api/ip_address.h @@ -27,6 +27,9 @@ #include #else #include +#ifdef __ANDROID__ +#include +#endif #endif #include #include // struct addrinfo @@ -82,7 +85,11 @@ typedef union { /* No htonl() with const */ static const ip_address_t IPV4_LOOPBACK = { #if __BYTE_ORDER == __LITTLE_ENDIAN +#ifdef __ANDROID__ + .v4.as_inaddr.s_addr = bswap_32(INADDR_LOOPBACK), +#else .v4.as_inaddr.s_addr = __bswap_constant_32(INADDR_LOOPBACK), +#endif #else .v4.as_inaddr.s_addr = INADDR_LOOPBACK, #endif diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0c10759fa..512bcb619 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -45,10 +45,6 @@ else () set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996") endif () -if (ANDROID_API) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ANDROID_C_FLAGS} -std=c99") -endif () - add_subdirectory (src) add_subdirectory (doc) diff --git a/lib/src/compat.c b/lib/src/compat.c index 23683ff8e..63431a384 100644 --- a/lib/src/compat.c +++ b/lib/src/compat.c @@ -541,10 +541,10 @@ hicn_packet_get_payload_type (const hicn_header_t * h, switch (HICN_IP_VERSION (h)) { case 6: - *payload_type = ((h->v6.tcp.flags & TCP_FLAG_URG) == TCP_FLAG_URG); + *payload_type = ((h->v6.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG); break; case 4: - *payload_type = ((h->v4.tcp.flags & TCP_FLAG_URG) == TCP_FLAG_URG); + *payload_type = ((h->v4.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG); break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -571,15 +571,15 @@ hicn_packet_set_payload_type (hicn_header_t * h, { case 6: if (payload_type) - h->v6.tcp.flags = h->v6.tcp.flags | TCP_FLAG_URG; + h->v6.tcp.flags = h->v6.tcp.flags | HICN_TCP_FLAG_URG; else - h->v6.tcp.flags = h->v6.tcp.flags & ~TCP_FLAG_URG; + h->v6.tcp.flags = h->v6.tcp.flags & ~HICN_TCP_FLAG_URG; break; case 4: if (payload_type) - h->v4.tcp.flags = h->v4.tcp.flags | TCP_FLAG_URG; + h->v4.tcp.flags = h->v4.tcp.flags | HICN_TCP_FLAG_URG; else - h->v4.tcp.flags = h->v4.tcp.flags & ~TCP_FLAG_URG; + h->v4.tcp.flags = h->v4.tcp.flags & ~HICN_TCP_FLAG_URG; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -594,10 +594,10 @@ hicn_packet_set_syn (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags | TCP_FLAG_SYN; + h->v6.tcp.flags = h->v6.tcp.flags | HICN_TCP_FLAG_SYN; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags | TCP_FLAG_SYN; + h->v4.tcp.flags = h->v4.tcp.flags | HICN_TCP_FLAG_SYN; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -611,10 +611,10 @@ hicn_packet_reset_syn (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags & ~TCP_FLAG_SYN; + h->v6.tcp.flags = h->v6.tcp.flags & ~HICN_TCP_FLAG_SYN; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags & ~TCP_FLAG_SYN; + h->v4.tcp.flags = h->v4.tcp.flags & ~HICN_TCP_FLAG_SYN; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -628,10 +628,10 @@ hicn_packet_test_syn (const hicn_header_t * h, bool * flag) switch (HICN_IP_VERSION (h)) { case 6: - *flag = h->v6.tcp.flags & TCP_FLAG_SYN; + *flag = h->v6.tcp.flags & HICN_TCP_FLAG_SYN; break; case 4: - *flag = h->v4.tcp.flags & TCP_FLAG_SYN; + *flag = h->v4.tcp.flags & HICN_TCP_FLAG_SYN; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -645,10 +645,10 @@ hicn_packet_set_ack (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags | TCP_FLAG_ACK; + h->v6.tcp.flags = h->v6.tcp.flags | HICN_TCP_FLAG_ACK; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags | TCP_FLAG_ACK; + h->v4.tcp.flags = h->v4.tcp.flags | HICN_TCP_FLAG_ACK; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -662,10 +662,10 @@ hicn_packet_reset_ack (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags & ~TCP_FLAG_ACK; + h->v6.tcp.flags = h->v6.tcp.flags & ~HICN_TCP_FLAG_ACK; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags & ~TCP_FLAG_ACK; + h->v4.tcp.flags = h->v4.tcp.flags & ~HICN_TCP_FLAG_ACK; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -679,10 +679,10 @@ hicn_packet_test_ack (const hicn_header_t * h, bool * flag) switch (HICN_IP_VERSION (h)) { case 6: - *flag = h->v6.tcp.flags & TCP_FLAG_ACK; + *flag = h->v6.tcp.flags & HICN_TCP_FLAG_ACK; break; case 4: - *flag = h->v4.tcp.flags & TCP_FLAG_ACK; + *flag = h->v4.tcp.flags & HICN_TCP_FLAG_ACK; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -696,10 +696,10 @@ hicn_packet_set_rst (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags | TCP_FLAG_RST; + h->v6.tcp.flags = h->v6.tcp.flags | HICN_TCP_FLAG_RST; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags | TCP_FLAG_RST; + h->v4.tcp.flags = h->v4.tcp.flags | HICN_TCP_FLAG_RST; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -713,10 +713,10 @@ hicn_packet_reset_rst (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags & ~TCP_FLAG_RST; + h->v6.tcp.flags = h->v6.tcp.flags & ~HICN_TCP_FLAG_RST; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags & ~TCP_FLAG_RST; + h->v4.tcp.flags = h->v4.tcp.flags & ~HICN_TCP_FLAG_RST; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -730,10 +730,10 @@ hicn_packet_test_rst (const hicn_header_t * h, bool * flag) switch (HICN_IP_VERSION (h)) { case 6: - *flag = h->v6.tcp.flags & TCP_FLAG_RST; + *flag = h->v6.tcp.flags & HICN_TCP_FLAG_RST; break; case 4: - *flag = h->v4.tcp.flags & TCP_FLAG_RST; + *flag = h->v4.tcp.flags & HICN_TCP_FLAG_RST; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -747,10 +747,10 @@ hicn_packet_set_fin (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags | TCP_FLAG_FIN; + h->v6.tcp.flags = h->v6.tcp.flags | HICN_TCP_FLAG_FIN; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags | TCP_FLAG_FIN; + h->v4.tcp.flags = h->v4.tcp.flags | HICN_TCP_FLAG_FIN; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -764,10 +764,10 @@ hicn_packet_reset_fin (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags & ~TCP_FLAG_FIN; + h->v6.tcp.flags = h->v6.tcp.flags & ~HICN_TCP_FLAG_FIN; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags & ~TCP_FLAG_FIN; + h->v4.tcp.flags = h->v4.tcp.flags & ~HICN_TCP_FLAG_FIN; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -781,10 +781,10 @@ hicn_packet_test_fin (const hicn_header_t * h, bool * flag) switch (HICN_IP_VERSION (h)) { case 6: - *flag = h->v6.tcp.flags & TCP_FLAG_FIN; + *flag = h->v6.tcp.flags & HICN_TCP_FLAG_FIN; break; case 4: - *flag = h->v4.tcp.flags & TCP_FLAG_FIN; + *flag = h->v4.tcp.flags & HICN_TCP_FLAG_FIN; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -798,10 +798,10 @@ hicn_packet_set_ece (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags | TCP_FLAG_ECE; + h->v6.tcp.flags = h->v6.tcp.flags | HICN_TCP_FLAG_ECE; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags | TCP_FLAG_ECE; + h->v4.tcp.flags = h->v4.tcp.flags | HICN_TCP_FLAG_ECE; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -815,10 +815,10 @@ hicn_packet_reset_ece (hicn_header_t * h) switch (HICN_IP_VERSION (h)) { case 6: - h->v6.tcp.flags = h->v6.tcp.flags & ~TCP_FLAG_ECE; + h->v6.tcp.flags = h->v6.tcp.flags & ~HICN_TCP_FLAG_ECE; break; case 4: - h->v4.tcp.flags = h->v4.tcp.flags & ~TCP_FLAG_ECE; + h->v4.tcp.flags = h->v4.tcp.flags & ~HICN_TCP_FLAG_ECE; break; default: return HICN_LIB_ERROR_UNEXPECTED; @@ -832,10 +832,10 @@ hicn_packet_test_ece (const hicn_header_t * h, bool * flag) switch (HICN_IP_VERSION (h)) { case 6: - *flag = h->v6.tcp.flags & TCP_FLAG_ECE; + *flag = h->v6.tcp.flags & HICN_TCP_FLAG_ECE; break; case 4: - *flag = h->v4.tcp.flags & TCP_FLAG_ECE; + *flag = h->v4.tcp.flags & HICN_TCP_FLAG_ECE; break; default: return HICN_LIB_ERROR_UNEXPECTED; diff --git a/lib/src/protocol/tcp.h b/lib/src/protocol/tcp.h index 3a15a93b3..ded9a06b2 100644 --- a/lib/src/protocol/tcp.h +++ b/lib/src/protocol/tcp.h @@ -143,15 +143,15 @@ static_assert (EXPECTED_TCP_HDRLEN == TCP_HDRLEN, enum { -#define _(f) TCP_FLAG_BIT_##f, +#define _(f) HICN_TCP_FLAG_BIT_##f, foreach_tcp_flag #undef _ - TCP_N_FLAG_BITS, + HICN_TCP_N_FLAG_BITS, }; enum { -#define _(f) TCP_FLAG_##f = 1 << TCP_FLAG_BIT_##f, +#define _(f) HICN_TCP_FLAG_##f = 1 << HICN_TCP_FLAG_BIT_##f, foreach_tcp_flag #undef _ }; diff --git a/libtransport/CMakeLists.txt b/libtransport/CMakeLists.txt index 5cd33cfdc..757521574 100644 --- a/libtransport/CMakeLists.txt +++ b/libtransport/CMakeLists.txt @@ -107,6 +107,10 @@ if (${COMPILE_TESTS}) ) endif() +if(ANDROID_API) +find_package(OpenSSL REQUIRED) +endif () + list(APPEND LIBRARIES ${LIBPARC_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} diff --git a/libtransport/src/hicn/transport/utils/membuf.h b/libtransport/src/hicn/transport/utils/membuf.h index a150483b1..66e9d7afa 100644 --- a/libtransport/src/hicn/transport/utils/membuf.h +++ b/libtransport/src/hicn/transport/utils/membuf.h @@ -35,6 +35,8 @@ #include #include +#include + #ifndef _WIN32 TRANSPORT_GNU_DISABLE_WARNING("-Wshadow") #endif diff --git a/utils/src/hiperf.cc b/utils/src/hiperf.cc index 681696dbf..66cd559cb 100644 --- a/utils/src/hiperf.cc +++ b/utils/src/hiperf.cc @@ -27,8 +27,10 @@ #include #ifdef __linux__ +#ifndef __ANDROID__ #include #endif +#endif #ifdef _WIN32 #include -- cgit 1.2.3-korg