From: hyuna0213.jo Date: Thu, 27 Apr 2017 07:25:34 +0000 (+0900) Subject: [IOT-2063] provide available endpoints in CAGetNetworkInformation X-Git-Tag: 1.3.0~257 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d0363182899ac8e4b7c630fbe874a8f06ec6899;p=platform%2Fupstream%2Fiotivity.git [IOT-2063] provide available endpoints in CAGetNetworkInformation Current IoTivity is sending response including all available endpoints, which is not desired. Change-Id: Ib0f20bebc92e0fd8a443ba2a98594381746061fa Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/19355 Tested-by: jenkins-iotivity Reviewed-by: Ashok Babu Channa --- diff --git a/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c index 3dfbc6d..030fd31 100644 --- a/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c @@ -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)) { diff --git a/resource/csdk/connectivity/src/ip_adapter/caipserver.c b/resource/csdk/connectivity/src/ip_adapter/caipserver.c index 82b5012..e88715c 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipserver.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipserver.c @@ -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); diff --git a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c index 596b4a7..b870216 100644 --- a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c @@ -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) { diff --git a/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c index 7f37f78..60bdc4c 100644 --- a/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c @@ -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)) { diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index 85a7df9..3f7c6f6 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -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();