From ed0aec25c50b53e63070c2a4a25480724bdf343a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 3 Sep 2014 17:24:00 +0200 Subject: Fix UHASH build on *BSD --- cmake/checks.cmake | 32 ++++++++++++++++++++++++++++ src/crypto/mac/uhash/builtin/uhash_builtin.c | 2 -- src/fastd_config.h.in | 8 +++++++ src/util.h | 23 ++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/cmake/checks.cmake b/cmake/checks.cmake index 64dae58..d42f336 100644 --- a/cmake/checks.cmake +++ b/cmake/checks.cmake @@ -57,3 +57,35 @@ endif(NOT DARWIN) set(CMAKE_EXTRA_INCLUDE_FILES "netinet/if_ether.h") check_type_size("struct ethhdr" SIZEOF_ETHHDR) string(COMPARE NOTEQUAL "${SIZEOF_ETHHDR}" "" HAVE_ETHHDR) + + +set(CMAKE_REQUIRED_INCLUDES "sys/types.h") + +check_c_source_compiles(" +#include + +int main() { + return 0; +} +" HAVE_ENDIAN_H) + +if(HAVE_ENDIAN_H) + check_symbol_exists("be32toh" "endian.h" HAVE_LINUX_ENDIAN) + +else(HAVE_ENDIAN_H) + check_c_source_compiles(" + #include + #include + + int main() { + return 0; + } + " HAVE_SYS_ENDIAN_H) + + if(HAVE_SYS_ENDIAN_H) + check_symbol_exists("be32toh" "sys/types.h;sys/endian.h" HAVE_LINUX_ENDIAN) + + else(HAVE_SYS_ENDIAN_H) + message(FATAL_ERROR "Neither nor found") + endif(HAVE_SYS_ENDIAN_H) +endif(HAVE_ENDIAN_H) diff --git a/src/crypto/mac/uhash/builtin/uhash_builtin.c b/src/crypto/mac/uhash/builtin/uhash_builtin.c index 07ee749..e4710ae 100644 --- a/src/crypto/mac/uhash/builtin/uhash_builtin.c +++ b/src/crypto/mac/uhash/builtin/uhash_builtin.c @@ -35,8 +35,6 @@ #include "../../../../util.h" #include "../../../../log.h" -#include - /** MAC state used by this UHASH implmentation */ struct fastd_mac_state { diff --git a/src/fastd_config.h.in b/src/fastd_config.h.in index 9949eca..e396bf8 100644 --- a/src/fastd_config.h.in +++ b/src/fastd_config.h.in @@ -41,6 +41,14 @@ /** Defined if the platform defines get_current_dir_name() */ #cmakedefine HAVE_GET_CURRENT_DIR_NAME +/** Defined if exists */ +#cmakedefine HAVE_ENDIAN_H + +/** Defined if exists */ +#cmakedefine HAVE_SYS_ENDIAN_H + +/** Defined if be32toh etc. exist */ +#cmakedefine HAVE_LINUX_ENDIAN /** Defined if the platform supports SO_BINDTODEVICE */ #cmakedefine USE_BINDTODEVICE diff --git a/src/util.h b/src/util.h index fe6720b..3acc42f 100644 --- a/src/util.h +++ b/src/util.h @@ -32,6 +32,18 @@ #pragma once + +#include + +#ifdef HAVE_ENDIAN_H +#include +#endif + +#ifdef HAVE_SYS_ENDIAN_H +#include +#endif + + /** Returns a pointer to a data structure, given the address of a member contained in the structure @@ -91,3 +103,14 @@ static inline size_t max_size_t(size_t a, size_t b) { static inline size_t min_size_t(size_t a, size_t b) { return (a < b) ? a : b; } + + +#ifndef HAVE_LINUX_ENDIAN + +/** converts a 32bit integer from big endian to host byte order */ +#define be32toh(x) betoh32(x) + +/** converts a 32bit integer from little endian to host byte order */ +#define le32toh(x) letoh32(x) + +#endif -- cgit v1.2.3