[IOT-2063] provide available endpoints in CAGetNetworkInformation
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Thu, 27 Apr 2017 07:25:34 +0000 (16:25 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 27 Apr 2017 12:54:30 +0000 (12:54 +0000)
Current IoTivity is sending response including all available endpoints,
which is not desired.

Change-Id: Ib0f20bebc92e0fd8a443ba2a98594381746061fa
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19355
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 3dfbc6d..030fd31 100644 (file)
@@ -235,6 +235,12 @@ static bool CAParsingNetorkInfo(int idx, u_arraylist_t *iflist)
             continue;
         }
 
+        if ((family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (family == AF_INET && !caglobals.ip.ipv4enabled))
+        {
+            continue;
+        }
+
         int ifindex = if_nametoindex(ifa->ifa_name);
         if (idx && (ifindex != idx))
         {
index 82b5012..e88715c 100644 (file)
@@ -1536,15 +1536,16 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size)
         return CA_STATUS_FAILED;
     }
 
-    size_t len = u_arraylist_length(iflist);
-    size_t length = len;
-
 #ifdef __WITH_DTLS__
-    //If DTLS is supported, each interface can support secure port as well
-    length = len * 2;
+    const size_t endpointsPerInterface = 2;
+#else
+    const size_t endpointsPerInterface = 1;
 #endif
 
-    CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(length, sizeof (CAEndpoint_t));
+    size_t interfaces = u_arraylist_length(iflist);
+    size_t totalEndpoints = interfaces * endpointsPerInterface;
+
+    CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(totalEndpoints, sizeof (CAEndpoint_t));
     if (!eps)
     {
         OIC_LOG(ERROR, TAG, "Malloc Failed");
@@ -1552,7 +1553,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size)
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    for (size_t i = 0, j = 0; i < len; i++)
+    for (size_t i = 0, j = 0; i < interfaces; i++)
     {
         CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
         if(!ifitem)
@@ -1597,7 +1598,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size)
     }
 
     *info = eps;
-    *size = length;
+    *size = totalEndpoints;
 
     u_arraylist_destroy(iflist);
 
index 596b4a7..b870216 100644 (file)
@@ -444,6 +444,12 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
             continue;
         }
 
+        if ((family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (family == AF_INET && !caglobals.ip.ipv4enabled))
+        {
+            continue;
+        }
+
         CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof(CAInterface_t));
         if (!ifitem)
         {
index 7f37f78..60bdc4c 100644 (file)
@@ -283,6 +283,12 @@ static bool CAIPGetAddrInfo(int idx, u_arraylist_t *iflist)
             continue;
         }
 
+        if ((family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (family == AF_INET && !caglobals.ip.ipv4enabled))
+        {
+            continue;
+        }
+
         int ifindex = if_nametoindex(ifa->ifa_name);
         if (idx && (ifindex != idx))
         {
index 85a7df9..3f7c6f6 100644 (file)
@@ -1081,22 +1081,26 @@ CAResult_t CATCPStartServer(const ca_thread_pool_t threadPool)
         return res;
     }
 
-    if (caglobals.server)
+    if (caglobals.tcp.ipv6tcpenabled)
     {
-        NEWSOCKET(AF_INET, ipv4);
-        NEWSOCKET(AF_INET, ipv4s);
         NEWSOCKET(AF_INET6, ipv6);
         NEWSOCKET(AF_INET6, ipv6s);
-        OIC_LOG_V(DEBUG, TAG, "IPv4 socket fd=%d, port=%d",
-                  caglobals.tcp.ipv4.fd, caglobals.tcp.ipv4.port);
-        OIC_LOG_V(DEBUG, TAG, "IPv4 secure socket fd=%d, port=%d",
-                  caglobals.tcp.ipv4s.fd, caglobals.tcp.ipv4s.port);
         OIC_LOG_V(DEBUG, TAG, "IPv6 socket fd=%d, port=%d",
                   caglobals.tcp.ipv6.fd, caglobals.tcp.ipv6.port);
         OIC_LOG_V(DEBUG, TAG, "IPv6 secure socket fd=%d, port=%d",
                   caglobals.tcp.ipv6s.fd, caglobals.tcp.ipv6s.port);
     }
 
+    if (caglobals.tcp.ipv4tcpenabled)
+    {
+        NEWSOCKET(AF_INET, ipv4);
+        NEWSOCKET(AF_INET, ipv4s);
+        OIC_LOG_V(DEBUG, TAG, "IPv4 socket fd=%d, port=%d",
+                  caglobals.tcp.ipv4.fd, caglobals.tcp.ipv4.port);
+        OIC_LOG_V(DEBUG, TAG, "IPv4 secure socket fd=%d, port=%d",
+                  caglobals.tcp.ipv4s.fd, caglobals.tcp.ipv4s.port);
+    }
+
     // create mechanism for fast shutdown
 #ifdef WSA_WAIT_EVENT_0
     caglobals.tcp.updateEvent = WSACreateEvent();