fixed the bug related to coap over tcp pdu creation.
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Tue, 15 Mar 2016 05:58:46 +0000 (14:58 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Thu, 17 Mar 2016 01:55:20 +0000 (01:55 +0000)
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>
resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c

index 7c5c993..1da4034 100644 (file)
@@ -15,6 +15,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <limits.h>
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
@@ -262,22 +263,24 @@ size_t coap_get_total_message_length(const unsigned char *data, size_t size)
 
 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)