The first nibble of the frame is used to indecate the length of
the options/payload. and if a value is 13, an 8-bit unsigned integer
follows the initial byte and indicates the length of options/payload
minus 13. even in case the length of options/payload is 13, an 8-bit
unsigned interger has to be used to indicate 0.
Change-Id: I580e126755ae4b3018fe7eb11eae34035b0efa6c
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5901
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
coap_transport_type coap_get_tcp_header_type_from_size(unsigned int size)
{
- if (COAP_TCP_LENGTH_FIELD_8_BIT < size && COAP_TCP_LENGTH_FIELD_16_BIT >= size)
+ if (size < COAP_TCP_LENGTH_FIELD_8_BIT)
+ {
+ return coap_tcp;
+ }
+ else if (size < COAP_TCP_LENGTH_FIELD_16_BIT)
{
return coap_tcp_8bit;
}
- else if (COAP_TCP_LENGTH_FIELD_16_BIT < size && COAP_TCP_LENGTH_FIELD_32_BIT >= size)
+ else if (size < COAP_TCP_LENGTH_FIELD_32_BIT)
{
return coap_tcp_16bit;
}
- else if (COAP_TCP_LENGTH_FIELD_32_BIT < size)
+ else if (size < ULONG_MAX + COAP_TCP_LENGTH_FIELD_32_BIT)
{
return coap_tcp_32bit;
}
- else
- {
- return coap_tcp;
- }
+
+ return -1;
}
coap_transport_type coap_get_tcp_header_type_from_initbyte(unsigned int length)