diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index 4cd99178b9..35c0c391f2 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -964,6 +964,7 @@ static inline ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len, * @param[in] buf Buffer containing the PDU * @param[in] len Length of the buffer * @param[in] remote Destination for the packet + * @param[in] local Local endpoint to send from, may be NULL * @param[in] resp_handler Callback when response received, may be NULL * @param[in] context User defined context passed to the response handler * @param[in] tl_type The transport type to use for send. When @@ -980,7 +981,7 @@ static inline ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len, * @return 0 if cannot send */ ssize_t gcoap_req_send(const uint8_t *buf, size_t len, - const sock_udp_ep_t *remote, + const sock_udp_ep_t *remote, const sock_udp_ep_t *local, gcoap_resp_handler_t resp_handler, void *context, gcoap_socket_type_t tl_type); @@ -1009,7 +1010,7 @@ static inline ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, gcoap_resp_handler_t resp_handler, void *context, gcoap_socket_type_t tl_type) { - return gcoap_req_send(buf, len, remote, resp_handler, context, tl_type); + return gcoap_req_send(buf, len, remote, NULL, resp_handler, context, tl_type); } /** diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index e6fc5d91ff..3850a47e50 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -1613,7 +1613,7 @@ int gcoap_obs_req_forget(const sock_udp_ep_t *remote, const uint8_t *token, } ssize_t gcoap_req_send(const uint8_t *buf, size_t len, - const sock_udp_ep_t *remote, + const sock_udp_ep_t *remote, const sock_udp_ep_t *local, gcoap_resp_handler_t resp_handler, void *context, gcoap_socket_type_t tl_type) { @@ -1743,7 +1743,12 @@ ssize_t gcoap_req_send(const uint8_t *buf, size_t len, } if (res == 0) { - res = _tl_send(&socket, buf, len, remote, NULL); + sock_udp_aux_tx_t aux = { 0 }; + if (local) { + memcpy(&aux.local, local, sizeof(sock_udp_ep_t)); + aux.flags = SOCK_AUX_SET_LOCAL; + } + res = _tl_send(&socket, buf, len, remote, &aux); } if (res <= 0) { if (memo != NULL) {