[ITC][iotcon][Non-ACR][Add proper IP filtering when resource found]
authorHongkuk, Son <hongkuk.son@samsung.com>
Wed, 19 Jul 2017 10:58:30 +0000 (19:58 +0900)
committerHongkuk, Son <hongkuk.son@samsung.com>
Wed, 26 Jul 2017 10:53:44 +0000 (19:53 +0900)
 - There are two or more devices which execute TCT in same time, in same network.
 - A device creates a resource and wants to find its resource,
   BUT B device also creates a SAME resource, so unintentionally
   A device finds B device's resource and tries to access it.
 - Change connectivity type to IPV4 only.
 - Add proper IP filtering,
   which compares its own IP and found resource's host address.
 - Check IP via connection API which refers Wi-Fi or Ethernet.

Signed-off-by: Hongkuk, Son <hongkuk.son@samsung.com>
Change-Id: I970d6db106f4bacdf532856566782335365535cf

src/itc/iotcon/ITs-iotcon-common.c
src/itc/iotcon/ITs-iotcon-common.h
src/itc/iotcon/ITs-iotcon-presence-response.c
src/itc/iotcon/ITs-iotcon-presence.c
src/itc/iotcon/ITs-iotcon-remote-resource.c
src/itc/iotcon/ITs-iotcon-request.c
src/itc/iotcon/ITs-iotcon-resource.c
src/itc/iotcon/ITs-iotcon-response.c

index 87b87c7..52c9158 100755 (executable)
@@ -298,5 +298,64 @@ int ic_get_svr_db_path(char **path)
        return 0;
 }
 
+/**
+ * @function           icitc_get_client_ipv4_address
+ * @description                Get my device's IPv4 address and set to global variable
+ * @parameter          NA
+ * @return                     NA
+ */
+void icitc_get_client_ipv4_address(void)
+{
+       g_ipv4_address = NULL;
+       g_conn_h = NULL;
+
+       g_bFeatureWifi = TCTCheckSystemInfoFeatureSupported(WIFI_FEATURE, API_NAMESPACE);
+       g_bFeatureEthernet = TCTCheckSystemInfoFeatureSupported(ETHERNET_FEATURE, API_NAMESPACE);
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] g_bFeatureWifi(%d), g_bFeatureEthernet(%d)", __FUNCTION__, __LINE__, g_bFeatureWifi, g_bFeatureEthernet);
+
+       if ((g_bFeatureWifi == true) || (g_bFeatureEthernet == true)) {
+               int nRet = 0;
+
+               nRet = connection_create(&g_conn_h);
+               if (nRet != CONNECTION_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] (1/3) connection_create() FAIL(nRet = 0x%x)", __FUNCTION__, __LINE__, nRet);
+                       return;
+               }
+
+               nRet = connection_get_ip_address(g_conn_h, CONNECTION_ADDRESS_FAMILY_IPV4, &g_ipv4_address);
+               if (nRet != CONNECTION_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] (2/3) connection_get_ip_address() FAIL(nRet = 0x%x)", __FUNCTION__, __LINE__, nRet);
+               } else {
+                       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] g_ipv4_address(%s)", __FUNCTION__, __LINE__, g_ipv4_address);
+               }
+
+               if (g_conn_h != NULL) {
+                       nRet = connection_destroy(g_conn_h);
+                       if (nRet != CONNECTION_ERROR_NONE) {
+                               dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] (3/3) connection_destroy() FAIL(nRet = 0x%x)", __FUNCTION__, __LINE__, nRet);
+                               return;
+                       }
+               }
+       } else {
+               dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Wi-Fi and Ethernet are both NOT SUPPORTED", __FUNCTION__, __LINE__);
+       }
+}
+
+/**
+ * @function           icitc_free_client_ipv4_address
+ * @description                Free IPv4 address global variable
+ * @parameter          NA
+ * @return                     NA
+ */
+void icitc_free_client_ipv4_address(void)
+{
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] g_free() g_ipv4_address(%s)", __FUNCTION__, __LINE__, g_ipv4_address);
+
+       if (g_ipv4_address != NULL) {
+               g_free(g_ipv4_address);
+       }
+
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] g_free() g_ipv4_address done", __FUNCTION__, __LINE__);
+}
 
 /** @} */
index 8218477..1869248 100755 (executable)
@@ -27,6 +27,7 @@
 #include <glib.h>
 #include <dlog.h>
 #include <iotcon.h>
+#include <net_connection.h>
 
 /** @addtogroup itc-%{MODULE_NAME}
 *  @ingroup itc
@@ -56,6 +57,8 @@
 #define ASSIGNVAL2                                     20
 #define ASSIGNVAL3                                     30
 #define IOTCON_FEATURE                 "http://tizen.org/feature/iot.ocf"
+#define WIFI_FEATURE                   "http://tizen.org/feature/network.wifi"
+#define ETHERNET_FEATURE               "http://tizen.org/feature/network.ethernet"
 
 #define LOCAL_HOST_ADDRESS "127.0.0.1"
 #define LIGHT_RESOURCE_TYPE "core.light"
@@ -78,6 +81,11 @@ bool g_nGetCb, g_nPutCb, g_nPostCb, g_nDeleteCb;
 bool g_bCheckOnObserveCb, g_bCheckOnResponseCb, g_bCheckFoundResourceCb;
 bool g_bFeatureUnsupported;
 GMainLoop *g_pMainLoop;
+char *g_ipv4_address;
+bool g_bFeatureWifi;
+bool g_bFeatureEthernet;
+connection_h g_conn_h;
+
 gboolean TimeoutFunction(gpointer data);
 int icitc_send_ok_response(iotcon_request_h request);
 
@@ -139,6 +147,8 @@ gboolean IotConsCallbackTimeout(gpointer data);
 void IotconDestroyLiteResource(void);
 int IotconCreateLiteResource(void);
 int ic_get_svr_db_path(char **path);
+void icitc_get_client_ipv4_address(void);
+void icitc_free_client_ipv4_address(void);
 
 /** @} */
 #endif  //_ITS_IOTCON_COMMON_H_
index 071f093..ded7b14 100755 (executable)
@@ -249,7 +249,7 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource, iotcon_error_e er
                        iotcon_query_destroy(hQuery);
                        return false;
                }
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery, FoundResourceCB, user_data);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, FoundResourceCB, user_data);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE,IotConGetError(nRet));
@@ -282,15 +282,23 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource, iotcon_error_e er
                return false;
        }
 
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
+               g_found = false;
+               return true;
+       }
+
        char *uri;
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+
+       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0)
+       {
                g_found = false;
                return true;
        }
-       g_found = true;
 
        nRet = iotcon_remote_resource_get_connectivity_type(resource, &conn_type);
        if (IOTCON_ERROR_NONE != nRet)
@@ -309,6 +317,7 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource, iotcon_error_e er
        }
 
        g_idle_add(PresenceResponseResourceUpdate, NULL);
+       g_found = true;
 
        return false;
 }
@@ -334,7 +343,7 @@ static int CreateAndFindResource(int tc_index)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet), iotcon_query_destroy(hQuery);DestroyResource());
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP , hQuery, FoundResourceCB, GINT_TO_POINTER(tc_index));
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, FoundResourceCB, GINT_TO_POINTER(tc_index));
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), DestroyResource();iotcon_query_destroy(hQuery));
 
        nRet = iotcon_query_destroy(hQuery);
@@ -370,6 +379,8 @@ static int CreateAndFindResource(int tc_index)
        g_bIotconConnect = true;
        g_bFeatureUnsupported = false;
 
+       icitc_get_client_ipv4_address();
+
        ic_get_svr_db_path(&svr_db_path);
    int nRet = iotcon_initialize(svr_db_path);
        free(svr_db_path);
@@ -408,6 +419,7 @@ static int CreateAndFindResource(int tc_index)
                        return;
                }
        }
+
        return;
 }
 
@@ -420,6 +432,8 @@ static int CreateAndFindResource(int tc_index)
  */
 void ITs_iotcon_presence_response_cleanup(void)
 {
+       icitc_free_client_ipv4_address();
+
        if(g_presence != NULL)
        {
                iotcon_remove_presence_cb(g_presence);
index ace9810..5065162 100755 (executable)
@@ -141,7 +141,7 @@ static bool presence_found_resource(iotcon_remote_resource_h resource,
                        iotcon_query_destroy(hQuery);
                        return false;
                }
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery, presence_found_resource, GINT_TO_POINTER(tc_index));
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, presence_found_resource, GINT_TO_POINTER(tc_index));
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -168,6 +168,8 @@ static bool presence_found_resource(iotcon_remote_resource_h resource,
        if (g_found)
                return false;
 
+       g_found = true;
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] iotcon_remote_resource_h is null in presence_found_resource callback. \\n", __LINE__, API_NAMESPACE);
@@ -181,15 +183,16 @@ static bool presence_found_resource(iotcon_remote_resource_h resource,
                return false;
        }
 
-       char *uri;
-       iotcon_remote_resource_get_uri_path(resource, &uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, PRESENCE_LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, PRESENCE_LIGHT_RESOURCE_URI, strlen(PRESENCE_LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
+
+       char *uri;
+       iotcon_remote_resource_get_uri_path(resource, &uri);
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
 
        nRet = iotcon_remote_resource_get_connectivity_type(resource, &conn_type);
        if (IOTCON_ERROR_NONE != nRet) {
@@ -304,7 +307,7 @@ static int CreateAndFindResource(int tc_index)
                iotcon_query_destroy(hQuery);
                return false;
        }
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery, presence_found_resource, GINT_TO_POINTER(tc_index));
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, presence_found_resource, GINT_TO_POINTER(tc_index));
        if (IOTCON_ERROR_NONE != nRet)
        {
                FPRINTF("[Line : %d][%s] Handle iotcon_remote_resource_h is null in presence_found_resource callback. : %s\\n", __LINE__, API_NAMESPACE,IotConGetError(nRet));
@@ -343,6 +346,8 @@ void ITs_iotcon_presence_startup(void)
        g_bIotconConnect = true;
        g_bFeatureUnsupported = false;
 
+       icitc_get_client_ipv4_address();
+
        ic_get_svr_db_path(&svr_db_path);
    int nRet = iotcon_initialize(svr_db_path);
        free(svr_db_path);
@@ -381,6 +386,8 @@ void ITs_iotcon_presence_startup(void)
  */
 void ITs_iotcon_presence_cleanup(void)
 {
+       icitc_free_client_ipv4_address();
+
        if (g_bIotconConnect)
        {
                iotcon_deinitialize();
index ffe0a3c..da1de06 100755 (executable)
@@ -218,7 +218,7 @@ static bool IotcoRemoteResourceMonitoringCB(iotcon_remote_resource_h resource, i
                        iotcon_query_destroy(hquery);
                        return false;
                }
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hquery, IotcoRemoteResourceMonitoringCB , NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hquery, IotcoRemoteResourceMonitoringCB , NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -259,6 +259,8 @@ static bool IotcoRemoteResourceMonitoringCB(iotcon_remote_resource_h resource, i
        if (g_found)
                return false;
 
+       g_found = true;
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] IotcoRemoteResourceMonitoringCB input resource is NULL failed !!!\\n", __LINE__, API_NAMESPACE);
@@ -268,12 +270,12 @@ static bool IotcoRemoteResourceMonitoringCB(iotcon_remote_resource_h resource, i
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, REMOTE_RESOURCE_LIGHT, uri);
-       if (strncmp(uri, REMOTE_RESOURCE_LIGHT, strlen(REMOTE_RESOURCE_LIGHT)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        g_nCheckAPICb = iotcon_remote_resource_clone(resource, &g_hcacheHandle);
        if (IOTCON_ERROR_NONE != g_nCheckAPICb)
@@ -342,7 +344,7 @@ static bool IotconRemoteResourceCachingCB(iotcon_remote_resource_h resource,iotc
                nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
                PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
                
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery,  IotconRemoteResourceCachingCB, NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery,  IotconRemoteResourceCachingCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -374,6 +376,8 @@ static bool IotconRemoteResourceCachingCB(iotcon_remote_resource_h resource,iotc
        if (g_found)
                return false;
 
+       g_found = true;
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] IotconRemoteResourceCachingCB input resource is NULL failed !!!\\n", __LINE__, API_NAMESPACE);
@@ -383,12 +387,12 @@ static bool IotconRemoteResourceCachingCB(iotcon_remote_resource_h resource,iotc
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        g_nCheckAPICb = iotcon_remote_resource_clone(resource, &g_hcacheHandle);
        if (IOTCON_ERROR_NONE != g_nCheckAPICb)
@@ -448,7 +452,7 @@ static bool IotconRemoteResourceRepresentationCB(iotcon_remote_resource_h resour
                nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
                PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceRepresentationCB, NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceRepresentationCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -479,6 +483,9 @@ static bool IotconRemoteResourceRepresentationCB(iotcon_remote_resource_h resour
        if (g_found)
                return false;
 
+       g_found = true;
+
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] IotconRemoteResourceRepresentationCB input resource is NULL failed !!!\\n", __LINE__, API_NAMESPACE);
@@ -488,12 +495,12 @@ static bool IotconRemoteResourceRepresentationCB(iotcon_remote_resource_h resour
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        g_nCheckAPICb = iotcon_remote_resource_clone(resource, &g_hcacheHandle);
        if (IOTCON_ERROR_NONE != g_nCheckAPICb)
@@ -550,7 +557,7 @@ static bool IotconRemoteResourceRepresentationCB(iotcon_remote_resource_h resour
                nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
                PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery, IotconRemoteResourceOptionsCB, NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceOptionsCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -581,6 +588,9 @@ static bool IotconRemoteResourceRepresentationCB(iotcon_remote_resource_h resour
        if (g_found)
                return false;
 
+       g_found = true;
+
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] Iotcon_presence_found_resource_cb input resource is NULL failed !!!\\n", __LINE__, API_NAMESPACE);
@@ -590,12 +600,12 @@ static bool IotconRemoteResourceRepresentationCB(iotcon_remote_resource_h resour
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        nRet = iotcon_remote_resource_clone(resource, &g_hResourceHandle);
        if (IOTCON_ERROR_NONE != nRet)
@@ -838,7 +848,7 @@ static bool IotconRemoteResourceGetPutPostDelCB(iotcon_remote_resource_h resourc
                nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
                PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
                
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceGetPutPostDelCB, NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceGetPutPostDelCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -869,6 +879,9 @@ static bool IotconRemoteResourceGetPutPostDelCB(iotcon_remote_resource_h resourc
        if (g_found)
                return false;
 
+       g_found = true;
+
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] Iotcon_remote_resource_observe_cb_p input resource is NULL failed !!!\\n", __LINE__, API_NAMESPACE);
@@ -878,12 +891,12 @@ static bool IotconRemoteResourceGetPutPostDelCB(iotcon_remote_resource_h resourc
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        g_nCheckAPICb = iotcon_remote_resource_clone(resource, &g_hcacheHandle);
        if (IOTCON_ERROR_NONE != g_nCheckAPICb)
@@ -1031,7 +1044,7 @@ static bool IotconRemoteResourceObserveCB(iotcon_remote_resource_h resource, iot
                nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
                PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
                
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceObserveCB, NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceObserveCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -1064,6 +1077,8 @@ static bool IotconRemoteResourceObserveCB(iotcon_remote_resource_h resource, iot
        if (g_found)
                return false;
 
+       g_found = true;
+
        if(resource == NULL)
        {
                FPRINTF("[Line : %d][%s] IotconRemoteResourceObserveCB input resource is NULL failed !!!\\n", __LINE__, API_NAMESPACE);
@@ -1073,12 +1088,12 @@ static bool IotconRemoteResourceObserveCB(iotcon_remote_resource_h resource, iot
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        g_nCheckAPICb = iotcon_remote_resource_clone(resource, &g_hcacheHandle);
        if (IOTCON_ERROR_NONE != g_nCheckAPICb)
@@ -1121,6 +1136,8 @@ void ITs_iotcon_remote_resource_startup(void)
        g_bIotconConnect = true;
        g_bFeatureUnsupported = false;
 
+       icitc_get_client_ipv4_address();
+
        ic_get_svr_db_path(&svr_db_path);
    int nRet = iotcon_initialize(svr_db_path);
        free(svr_db_path);
@@ -1160,6 +1177,8 @@ void ITs_iotcon_remote_resource_startup(void)
  */
 void ITs_iotcon_remote_resource_cleanup(void)
 {
+       icitc_free_client_ipv4_address();
+
        if( g_bIotconConnect )
        {
                iotcon_deinitialize();
@@ -1324,7 +1343,7 @@ int ITc_iotcon_remote_resource_observe_register_deregister_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceObserveCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceObserveCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet),IotconDestroyLiteResource();iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
@@ -1384,7 +1403,7 @@ int ITc_iotcon_remote_resource_get_put_post_delete_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceGetPutPostDelCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceGetPutPostDelCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet),IotconDestroyLiteResource();iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
@@ -1444,7 +1463,7 @@ int ITc_iotcon_remote_resource_start_stop_caching_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceCachingCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceCachingCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), IotconDestroyLiteResource(); iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
@@ -1499,7 +1518,7 @@ int ITc_iotcon_remote_resource_start_stop_monitoring_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotcoRemoteResourceMonitoringCB , NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotcoRemoteResourceMonitoringCB , NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), IotconDestroyResource();iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
@@ -1674,7 +1693,7 @@ int ITc_iotcon_remote_resource_get_device_id_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery, IotconRemoteResourceOptionsCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceOptionsCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), IotconDestroyLiteResource();iotcon_query_destroy(hQuery););
        RUN_POLLING_LOOP;
 
@@ -1856,7 +1875,7 @@ int ITc_iotcon_remote_resource_set_get_options_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery,IotconRemoteResourceOptionsCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery,IotconRemoteResourceOptionsCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), IotconDestroyLiteResource(); iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
@@ -1930,7 +1949,7 @@ int ITc_iotcon_remote_resource_get_cached_representation_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, IotconRemoteResourceRepresentationCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, IotconRemoteResourceRepresentationCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), IotconDestroyLiteResource();iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
@@ -2029,7 +2048,7 @@ int ITc_remote_resource_get_device_name_p(void)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,hQuery,IotconRemoteResourceOptionsCB, NULL);
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery,IotconRemoteResourceOptionsCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet), IotconDestroyLiteResource();iotcon_query_destroy(hQuery));
        RUN_POLLING_LOOP;
 
index 9baef2e..92d510f 100755 (executable)
@@ -349,7 +349,7 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource,
                        iotcon_query_destroy(query);
                        return false;
                }
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY,
                                query, FoundResourceCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
@@ -375,16 +375,17 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource,
        if (g_found)
                return false;
 
+       g_found = true;
+
        char *host_address, *uri;
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        nRet = iotcon_remote_resource_clone(resource, &g_hRemoteResource);
        if (IOTCON_ERROR_NONE != nRet) {
@@ -468,7 +469,7 @@ static int CreateAndFindResource(int tc_index)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
 
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY,
                        hQuery, FoundResourceCB, NULL);
        if (IOTCON_ERROR_NONE != nRet)
        {
@@ -507,6 +508,8 @@ void ITs_iotcon_request_startup(void)
        g_bIotconConnect = true;
        g_bFeatureUnsupported = false;
 
+       icitc_get_client_ipv4_address();
+
        ic_get_svr_db_path(&svr_db_path);
    int nRet = iotcon_initialize(svr_db_path);
        free(svr_db_path);
@@ -546,6 +549,8 @@ void ITs_iotcon_request_startup(void)
  */
 void ITs_iotcon_request_cleanup(void)
 {
+       icitc_free_client_ipv4_address();
+
        if (g_hRemoteResource) {
                iotcon_remote_resource_destroy(g_hRemoteResource);
                g_hRemoteResource = NULL;
index 731009c..e238f36 100755 (executable)
@@ -741,7 +741,7 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource,iotcon_error_e err
                        iotcon_query_destroy(hquery);
                        return false;
                }
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY,
                                hquery, FoundResourceCB, user_data);
                if (IOTCON_ERROR_NONE != nRet) {
                        FPRINTF("iotcon_find_resource() Fail(%d)", nRet);
@@ -765,8 +765,8 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource,iotcon_error_e err
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                return true;
        }
 
@@ -846,7 +846,7 @@ static int CreateAndFindResource(int tc_index)
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
        
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY,
                        hQuery, FoundResourceCB, (void *)tc_index);
        if (IOTCON_ERROR_NONE != nRet) {
                FPRINTF("iotcon_find_resource() Fail(%d)", nRet);
@@ -1190,6 +1190,8 @@ void ITs_iotcon_resource_startup(void)
        g_bIotconConnect = true;
        g_bFeatureUnsupported = false;
 
+       icitc_get_client_ipv4_address();
+
        ic_get_svr_db_path(&svr_db_path);
    int nRet = iotcon_initialize(svr_db_path);
        free(svr_db_path);
@@ -1233,6 +1235,8 @@ void ITs_iotcon_resource_cleanup(void)
        FPRINTF("[Line : %d][%s] TEST SUIT clean-up: ITs_iotcon_resource_cleanup\\n", __LINE__, API_NAMESPACE);
 #endif
 
+       icitc_free_client_ipv4_address();
+
        if (g_bIotconConnect)
        {
                iotcon_deinitialize();
index af99586..a97c38e 100755 (executable)
@@ -157,7 +157,7 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource,
                        iotcon_query_destroy(hQuery);
                        return false;
                }
-               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP, hQuery, FoundResourceCB, NULL);
+               nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY, hQuery, FoundResourceCB, NULL);
                if (IOTCON_ERROR_NONE != nRet)
                {
                        FPRINTF("[Line : %d][%s] iotcon_find_resource fail in startup error returned : %s\\n", __LINE__, API_NAMESPACE, IotConGetError(nRet));
@@ -182,16 +182,17 @@ static bool FoundResourceCB(iotcon_remote_resource_h resource,
        if (g_found)
                return false;
 
+       g_found = true;
+
        char *host_address, *uri;
        iotcon_remote_resource_get_host_address(resource, &host_address);
        iotcon_remote_resource_get_uri_path(resource, &uri);
        dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] host_address[%s], uri[%s]", __FUNCTION__, __LINE__, host_address, uri);
-       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected uri[%s], found uri[%s]", __FUNCTION__, __LINE__, LIGHT_RESOURCE_URI, uri);
-       if (strncmp(uri, LIGHT_RESOURCE_URI, strlen(LIGHT_RESOURCE_URI)) != 0) {
+       dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] expected host_address[%s], found host_address[%s]", __FUNCTION__, __LINE__, g_ipv4_address, host_address);
+       if (strstr(host_address, g_ipv4_address) == NULL) { // targeted resource, BUT wrong device, so skip this resource and try again
                g_found = false;
                return true;
        }
-       g_found = true;
 
        nRet = iotcon_remote_resource_clone(resource, &g_hRemoteResourceResp);
        if (IOTCON_ERROR_NONE != nRet) {
@@ -232,7 +233,7 @@ static int CreateAndFindResource()
        nRet = iotcon_query_set_resource_type(hQuery, LIGHT_RESOURCE_TYPE);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_query_set_resource_type", IotConGetError(nRet),iotcon_query_destroy(hQuery));
 
-       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP |IOTCON_CONNECTIVITY_PREFER_UDP,
+       nRet = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP | IOTCON_CONNECTIVITY_IPV4_ONLY,
                        hQuery, FoundResourceCB, NULL);
        PRINT_RESULT_CLEANUP(IOTCON_ERROR_NONE, nRet, "iotcon_find_resource", IotConGetError(nRet),iotcon_query_destroy(hQuery));
 
@@ -530,6 +531,8 @@ void ITs_iotcon_response_startup(void)
        g_bIotconConnect = true;
        g_bFeatureUnsupported = false;
 
+       icitc_get_client_ipv4_address();
+
        ic_get_svr_db_path(&svr_db_path);
    int nRet = iotcon_initialize(svr_db_path);
        free(svr_db_path);
@@ -581,6 +584,8 @@ void ITs_iotcon_response_startup(void)
  */
 void ITs_iotcon_response_cleanup(void)
 {
+       icitc_free_client_ipv4_address();
+
        if (g_hRemoteResourceResp) {
                iotcon_remote_resource_destroy(g_hRemoteResourceResp);
                g_hRemoteResourceResp = NULL;