From fcc75c6a3ff7759afa6c2f5bf97d01eeaa381334 Mon Sep 17 00:00:00 2001 From: Ilia Penev <i.penev@allterco.com> Date: Fri, 21 Oct 2016 13:52:21 +0200 Subject: [PATCH] Fix CoAP packet size calculation PUBLISHED_FROM=43532ec3951779d17438b457fe6de6dea8f514fd --- mongoose.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mongoose.c b/mongoose.c index c0237a247..3b4d8bff3 100644 --- a/mongoose.c +++ b/mongoose.c @@ -9694,7 +9694,7 @@ static uint32_t coap_calculate_packet_size(struct mg_coap_message *cm, prev_opt_number = 0; while (opt != NULL) { *len += 1; /* basic delta/length */ - *len += coap_get_ext_opt_size(opt->number); + *len += coap_get_ext_opt_size(opt->number - prev_opt_number); *len += coap_get_ext_opt_size((uint32_t) opt->value.len); /* * Current implementation performs check if @@ -9708,6 +9708,7 @@ static uint32_t coap_calculate_packet_size(struct mg_coap_message *cm, return MG_COAP_ERROR | MG_COAP_OPTIOMG_FIELD; } *len += opt->value.len; + prev_opt_number = opt->number; opt = opt->next; } -- GitLab