diff --git a/include/coap3/coap_async_internal.h b/include/coap3/coap_async_internal.h index 32318ff4..4e33ca88 100644 --- a/include/coap3/coap_async_internal.h +++ b/include/coap3/coap_async_internal.h @@ -42,6 +42,8 @@ struct coap_async_t { void *app_data; /**< User definable data pointer */ coap_app_data_free_callback_t app_cb; /**< callback to call when async is being released (or NULL) */ + coap_address_t local_if; /**< local address the request was + received on */ }; /** diff --git a/src/coap_async.c b/src/coap_async.c index be393ae2..46b2ca35 100644 --- a/src/coap_async.c +++ b/src/coap_async.c @@ -103,6 +103,9 @@ coap_register_async_lkd(coap_session_t *session, s->session = coap_session_reference_lkd(session); + /* Snapshot local address; addr_info.local may change before the async fires (multicast). */ + coap_address_copy(&s->local_if, &session->addr_info.local); + coap_async_set_delay_lkd(s, delay); return s; diff --git a/src/coap_net.c b/src/coap_net.c index 1dd5bda0..2e6be544 100644 --- a/src/coap_net.c +++ b/src/coap_net.c @@ -5397,6 +5397,8 @@ coap_check_async(coap_context_t *context, coap_tick_t now, coap_tick_t *tim_rem) LL_FOREACH_SAFE(context->async_state, async, tmp) { if (async->delay != 0 && !async->session->is_rate_limiting) { if (async->delay <= now) { + /* Restore the local address the request was received on */ + coap_address_copy(&async->session->addr_info.local, &async->local_if); /* Send off the request to the application */ coap_log_debug("Async PDU presented to app.\n"); coap_show_pdu(COAP_LOG_DEBUG, async->pdu);