From: Sakthivel Samidurai Date: Wed, 5 Aug 2015 16:36:21 +0000 (-0700) Subject: Use CAConvertAddrToName helper method instead of inet_ntoa X-Git-Tag: 1.0.0-RC1~166 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=177a11f74b29ddf013cab7bccd637835e6ef9746;p=contrib%2Fiotivity.git Use CAConvertAddrToName helper method instead of inet_ntoa Use CAConvertAddrToName to provide protocol-independent translation for DTLS. Change-Id: If9e80aba1151ecbdb9af4cfa204ec88dc6f94001 Signed-off-by: Sakthivel Samidurai Reviewed-on: https://gerrit.iotivity.org/gerrit/2121 Tested-by: jenkins-iotivity Reviewed-by: Sachin Agrawal --- diff --git a/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c b/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c index 90c1ae6..8439896 100644 --- a/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c +++ b/resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c @@ -81,7 +81,7 @@ static CAEndpoint_t *GetPeerInfo(const CAEndpoint_t *peer) } static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port, - const unsigned char *id, uint16_t id_length) + const unsigned char *id, uint16_t id_length, CATransportFlags_t flag) { if(NULL == peerAddr || NULL == id @@ -102,6 +102,9 @@ static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port, OICStrcpy(peer->addr, sizeof(peer->addr), peerAddr); peer->port = port; + peer->flags = flag; + peer->flags |= CA_SECURE; + peer->adapter = CA_ADAPTER_IP; memcpy(peer->identity.id, id, id_length); peer->identity.id_length = id_length; @@ -480,9 +483,9 @@ static int32_t CAHandleSecureEvent(dtls_context_t *context, OIC_LOG(INFO, NET_DTLS_TAG, "Peer closing connection"); stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session; - char *peerAddr = inet_ntoa(addrInfo->addr.sin.sin_addr); - uint32_t port = ntohs(addrInfo->addr.sin.sin_port); - + char *peerAddr = NULL; + uint32_t port = 0; + CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, port); CARemovePeerFromPeerInfoList(peerAddr, port); } @@ -547,10 +550,15 @@ static int32_t CAGetPskCredentials(dtls_context_t *ctx, // data structure when handshake completes. Therefore, currently this is a // workaround to cache remote end-point identity when tinyDTLS asks for PSK. stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session; - char *peerAddress = inet_ntoa(addrInfo->addr.sin.sin_addr); - uint32_t port = ntohs(addrInfo->addr.sin.sin_port); + char *peerAddress = NULL; + uint32_t port = 0; + CAConvertAddrToName(&(addrInfo->addr.st), peerAddress, port); + + CATransportFlags_t flag = + addrInfo->addr.st.ss_family == AF_INET ? CA_IPV4 : CA_IPV6; - CAResult_t result = CAAddIdToPeerInfoList(peerAddress, port, desc, descLen); + CAResult_t result = CAAddIdToPeerInfoList(peerAddress, + port, desc, descLen, flag); if(CA_STATUS_OK != result ) { OIC_LOG(ERROR, NET_DTLS_TAG, "Fail to add peer id to gDtlsPeerInfoList");