diff --git a/CMakeLists.txt b/CMakeLists.txt index c4f3a09613..a322568c1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,6 +235,7 @@ check_include_file(strings.h HAVE_STRINGS_H) check_include_file(string.h HAVE_STRING_H) check_include_file(sys/sysctl.h HAVE_SYS_SYSCTL_H) check_include_file(net/if.h HAVE_NET_IF_H) +check_include_file(ifaddrs.h HAVE_IFADDRS_H) check_include_file(netinet/in.h HAVE_NETINET_IN_H) check_include_file(sys/epoll.h HAVE_EPOLL_H) check_include_file(sys/timerfd.h HAVE_TIMERFD_H) diff --git a/configure.ac b/configure.ac index 0a297775e8..213f1bde50 100644 --- a/configure.ac +++ b/configure.ac @@ -925,7 +925,7 @@ fi AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h \ pthread.h errno.h winsock2.h ws2tcpip.h \ stdlib.h string.h strings.h sys/socket.h sys/time.h \ - time.h unistd.h sys/unistd.h sys/ioctl.h net/if.h]) + time.h unistd.h sys/unistd.h sys/ioctl.h net/if.h ifaddrs.h]) # For epoll, need two headers (sys/epoll.h sys/timerfd.h), but set up one #define AC_CHECK_HEADER([sys/epoll.h]) diff --git a/src/coap_address.c b/src/coap_address.c index 5e0020acb6..6b36423d9f 100644 --- a/src/coap_address.c +++ b/src/coap_address.c @@ -25,6 +25,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_NET_IF_H +#include +#endif +#ifdef HAVE_IFADDRS_H +#include +#endif #ifdef HAVE_WS2TCPIP_H #include #endif @@ -139,8 +145,6 @@ coap_is_mcast(const coap_address_t *a) { return 0; } -#if !defined(WIN32) && !defined(__ZEPHYR__) - #ifndef COAP_BCST_CNT #define COAP_BCST_CNT 15 #endif /* COAP_BCST_CNT */ @@ -150,25 +154,20 @@ coap_is_mcast(const coap_address_t *a) { #define COAP_BCST_REFRESH_SECS 30 #endif /* COAP_BCST_REFRESH_SECS */ -#if COAP_IPV4_SUPPORT && !defined(ESPIDF_VERSION) +#if COAP_IPV4_SUPPORT && defined(HAVE_IFADDRS_H) static int bcst_cnt = -1; static coap_tick_t last_refresh; static struct in_addr b_ipv4[COAP_BCST_CNT]; -#endif /* COAP_IPV4_SUPPORT && ! ESPIDF_VERSION */ - -#if !defined(ESPIDF_VERSION) -#include -#include -#endif /* ! ESPIDF_VERSION */ +#endif /* COAP_IPV4_SUPPORT && HAVE_IFADDRS_H */ int coap_is_bcast(const coap_address_t *a) { #if COAP_IPV4_SUPPORT struct in_addr ipv4; -#if !defined(ESPIDF_VERSION) +#if defined(HAVE_IFADDRS_H) int i; coap_tick_t now; -#endif /* ! ESPIDF_VERSION */ +#endif /* HAVE_IFADDRS_H */ #endif /* COAP_IPV4_SUPPORT */ if (!a) @@ -195,10 +194,13 @@ coap_is_bcast(const coap_address_t *a) { return 0; } #if COAP_IPV4_SUPPORT +#ifndef INADDR_BROADCAST +#define INADDR_BROADCAST ((uint32_t)0xffffffffUL) +#endif /* !INADDR_BROADCAST */ if (ipv4.s_addr == INADDR_BROADCAST) return 1; -#if !defined(ESPIDF_VERSION) +#if defined(HAVE_IFADDRS_H) coap_ticks(&now); if (bcst_cnt == -1 || (now - last_refresh) > (COAP_BCST_REFRESH_SECS * COAP_TICKS_PER_SECOND)) { @@ -230,17 +232,10 @@ coap_is_bcast(const coap_address_t *a) { if (ipv4.s_addr == b_ipv4[i].s_addr) return 1; } -#endif /* ESPIDF_VERSION */ +#endif /* HAVE_IFADDRS_H */ return 0; #endif /* COAP_IPV4_SUPPORT */ } -#else /* WIN32 || __ZEPHYR__ */ -int -coap_is_bcast(const coap_address_t *a) { - (void)a; - return 0; -} -#endif /* WIN32 || __ZEPHYR__ */ #endif /* !defined(WITH_CONTIKI) && !defined(WITH_LWIP) */