Use CAConvertAddrToName helper method instead of inet_ntoa
authorSakthivel Samidurai <sakthivel.samidurai@intel.com>
Wed, 5 Aug 2015 16:36:21 +0000 (09:36 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Thu, 6 Aug 2015 17:15:16 +0000 (17:15 +0000)
Use CAConvertAddrToName to provide protocol-independent translation
for DTLS.

Change-Id: If9e80aba1151ecbdb9af4cfa204ec88dc6f94001
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2121
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c

index 90c1ae6..8439896 100644 (file)
@@ -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");