1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

gcoap: add remote sock_udp_ep_t to coap_request_ctx_t

This commit is contained in:
Benjamin Valentin 2022-08-26 19:27:05 +02:00
parent 82f7598167
commit 2376343547
4 changed files with 35 additions and 0 deletions

View File

@ -96,6 +96,12 @@
#include <arpa/inet.h>
#endif
#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN)
#include "net/sock/udp.h"
#else
typedef void sock_udp_ep_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -347,6 +353,18 @@ void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx);
*/
uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx);
/**
* @brief Get the remote endpoint from which the request was received
*
* @note This is currently only implemented for GCoAP
*
* @param[in] ctx The request context
*
* @return Remote endpoint from which the request originated
* @return NULL The request was not received via UDP
*/
const sock_udp_ep_t *coap_request_ctx_get_remote_udp(const coap_request_ctx_t *ctx);
/**
* @brief Block1 helper struct
*/

View File

@ -711,6 +711,7 @@ static size_t _handle_req(gcoap_socket_t *sock, coap_pkt_t *pdu, uint8_t *buf,
coap_request_ctx_t ctx = {
.resource = resource,
.tl_type = (uint32_t)sock->type,
.remote = remote,
};
if (coap_get_proxy_uri(pdu, &offset) > 0) {

View File

@ -1256,3 +1256,13 @@ uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx)
return 0;
#endif
}
const sock_udp_ep_t *coap_request_ctx_get_remote_udp(const coap_request_ctx_t *ctx)
{
#ifdef MODULE_GCOAP
return ctx->remote;
#else
(void)ctx;
return NULL;
#endif
}

View File

@ -20,6 +20,11 @@
#define NANOCOAP_INTERNAL_H
#include "net/nanocoap.h"
#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN)
#include "net/sock/udp.h"
#else
typedef void sock_udp_ep_t;
#endif
#ifdef __cplusplus
extern "C" {
@ -40,6 +45,7 @@ struct _coap_request_ctx {
* cyclically include the @ref net_gcoap header.
*/
uint32_t tl_type;
sock_udp_ep_t *remote; /**< remote endpoint of the request */
#endif
};