coap_address.c: Make coap_is_bcast() more generic for different builds

This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2023-10-04 22:00:27 +01:00
1 parent 9cde7cdee1
commit d9bdf4b284
3 files changed
+17 -21

No files matched your search

+1
View File
@@ -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)
+1 -1
View File
@@ -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])
+15 -20
View File
@@ -25,6 +25,12 @@
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#ifdef HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#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 <net/if.h>
#include <ifaddrs.h>
#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) */