From c9b6e990f7b8e0d1fbe17f0cfb12ad06b6897e95 Mon Sep 17 00:00:00 2001
From: Ken Bannister <kb2ma@runbox.com>
Date: Fri, 12 Jan 2018 05:40:03 -0500
Subject: [PATCH] net/nanocoap: message ID received in host order

---
 sys/net/application_layer/nanocoap/nanocoap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c
index 15eca0860f..5b8a60f3a1 100644
--- a/sys/net/application_layer/nanocoap/nanocoap.c
+++ b/sys/net/application_layer/nanocoap/nanocoap.c
@@ -207,7 +207,8 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code,
     /* if code is COAP_CODE_EMPTY (zero), use RST as type, else RESP */
     unsigned type = code ? COAP_RESP : COAP_RST;
 
-    coap_build_hdr((coap_hdr_t *)rbuf, type, pkt->token, tkl, code, pkt->hdr->id);
+    coap_build_hdr((coap_hdr_t *)rbuf, type, pkt->token, tkl, code,
+                   ntohs(pkt->hdr->id));
     coap_hdr_set_type((coap_hdr_t *)rbuf, type);
     coap_hdr_set_code((coap_hdr_t *)rbuf, code);
 
@@ -224,7 +225,7 @@ ssize_t coap_build_hdr(coap_hdr_t *hdr, unsigned type, uint8_t *token, size_t to
     memset(hdr, 0, sizeof(coap_hdr_t));
     hdr->ver_t_tkl = (0x1 << 6) | (type << 4) | token_len;
     hdr->code = code;
-    hdr->id = id;
+    hdr->id = htons(id);
 
     if (token_len) {
         memcpy(hdr->data, token, token_len);
-- 
GitLab