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");
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)
}
*info = eps;
- *size = length;
+ *size = totalEndpoints;
u_arraylist_destroy(iflist);
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();