From 21263bb48ddc0bce02157a735cb2f26522a33d7b Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 12 Mar 2020 11:14:01 +0100 Subject: [PATCH 1/2] net/nanocoap: add remote to pkt_t --- sys/include/net/nanocoap.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index adcb94077552..2710031b0cde 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -91,6 +91,10 @@ #include #endif +#ifdef MODULE_GCOAP +#include "net/sock/udp.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -189,6 +193,11 @@ typedef struct { coap_optpos_t options[NANOCOAP_NOPTS_MAX]; /**< option offset array */ #ifdef MODULE_GCOAP uint32_t observe_value; /**< observe value */ + /** + * remote UDP endpoint. As of now, gcoap supports only UDP as transport, so + * we use sock_udp_ep_t here directly. If gcoap is extended to provide other + * transports, this probably needs to be changed to some union type here */ + sock_udp_ep_t *udp_remote; #endif } coap_pkt_t; From 33f8874c9ba5598d2a4aa90cd8ab2940c0e370f9 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 12 Mar 2020 11:35:28 +0100 Subject: [PATCH 2/2] net/gcoap: set remote pointer on receiving packets --- sys/net/application_layer/gcoap/gcoap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 762f18a3d492..e28883f531c7 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -155,6 +155,9 @@ static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type, void *arg) return; } + /* remember set senders port and address for later use */ + pdu.udp_remote = &remote; + /* validate class and type for incoming */ switch (coap_get_code_class(&pdu)) { /* incoming request */