Skip to content

Commit

Permalink
ESP-IDF: Fix handling broadcast address
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jul 31, 2023
1 parent 7146a45 commit 65f0be8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/coap_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,32 +139,36 @@ coap_is_mcast(const coap_address_t *a) {
return 0;
}

#if !defined(WIN32) && !defined(ESPIDF_VERSION)
#if !defined(WIN32)

#ifndef COAP_BCST_CNT
#define COAP_BCST_CNT 6
#define COAP_BCST_CNT 15
#endif /* COAP_BCST_CNT */

/* How frequently to refresh the list of valid IPv4 broadcast addresses */
#ifndef COAP_BCST_REFRESH_SECS
#define COAP_BCST_REFRESH_SECS 30
#endif /* COAP_BCST_REFRESH_SECS */

#if COAP_IPV4_SUPPORT
#if COAP_IPV4_SUPPORT && !defined(ESPIDF_VERSION)
static int bcst_cnt = -1;
static coap_tick_t last_refresh;
static struct in_addr b_ipv4[COAP_BCST_CNT];
#endif /* COAP_IPV4_SUPPORT */
#endif /* COAP_IPV4_SUPPORT && ! ESPIDF_VERSION */

#if !defined(ESPIDF_VERSION)
#include <net/if.h>
#include <ifaddrs.h>
#endif /* ! ESPIDF_VERSION */

int
coap_is_bcast(const coap_address_t *a) {
#if COAP_IPV4_SUPPORT
struct in_addr ipv4;
#if !defined(ESPIDF_VERSION)
int i;
coap_tick_t now;
#endif /* ! ESPIDF_VERSION */
#endif /* COAP_IPV4_SUPPORT */

if (!a)
Expand Down Expand Up @@ -194,6 +198,7 @@ coap_is_bcast(const coap_address_t *a) {
if (ipv4.s_addr == INADDR_BROADCAST)
return 1;

#if !defined(ESPIDF_VERSION)
coap_ticks(&now);
if (bcst_cnt == -1 ||
(now - last_refresh) > (COAP_BCST_REFRESH_SECS * COAP_TICKS_PER_SECOND)) {
Expand Down Expand Up @@ -225,10 +230,11 @@ coap_is_bcast(const coap_address_t *a) {
if (ipv4.s_addr == b_ipv4[i].s_addr)
return 1;
}
#endif /* ESPIDF_VERSION */
return 0;
#endif /* COAP_IPV4_SUPPORT */
}
#else /* WIN32 || ESPIDF_VERSION */
#else /* WIN32 */
int
coap_is_bcast(const coap_address_t *a) {
(void)a;
Expand Down

0 comments on commit 65f0be8

Please sign in to comment.