diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index d99857e99d..b966834aeb 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -687,6 +687,17 @@ static inline void coap_hdr_set_code(coap_hdr_t *hdr, uint8_t code) hdr->code = code; } +/** + * @brief Write the given raw message code to given CoAP pkt + * + * @param[out] pkt CoAP packet to write to + * @param[in] code raw message code + */ +static inline void coap_pkt_set_code(coap_pkt_t *pkt, uint8_t code) +{ + coap_hdr_set_code(pkt->hdr, code); +} + /** * @brief Set the message type for the given CoAP header * diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index b316371396..2e9d4e7e46 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -585,7 +585,7 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ if (messagelayer_emptyresponse_type != NO_IMMEDIATE_REPLY) { coap_hdr_set_type(pdu.hdr, (uint8_t)messagelayer_emptyresponse_type); - coap_hdr_set_code(pdu.hdr, COAP_CODE_EMPTY); + coap_pkt_set_code(&pdu, COAP_CODE_EMPTY); /* Set the token length to 0, preserving the CoAP version as it was and * the empty message type that was just set. * diff --git a/sys/net/application_layer/nanocoap/fileserver.c b/sys/net/application_layer/nanocoap/fileserver.c index a2965a14b0..6a4e61ae07 100644 --- a/sys/net/application_layer/nanocoap/fileserver.c +++ b/sys/net/application_layer/nanocoap/fileserver.c @@ -292,7 +292,7 @@ static ssize_t _get_file(coap_pkt_t *pdu, uint8_t *buf, size_t len, late_err: vfs_close(fd); - coap_hdr_set_code(pdu->hdr, COAP_CODE_INTERNAL_SERVER_ERROR); + coap_pkt_set_code(pdu, COAP_CODE_INTERNAL_SERVER_ERROR); return coap_get_total_hdr_len(pdu); }