Removing unnecessary use of IPV6 flags.
authorOmkar Hegde <omkar.m.hegde@intel.com>
Tue, 14 Jul 2015 21:59:41 +0000 (14:59 -0700)
committerErich Keane <erich.keane@intel.com>
Wed, 15 Jul 2015 18:19:12 +0000 (18:19 +0000)
Previously, default flags were interpreted as both
IPv4 and IPv6 and "[ ]" was added around the IP address
in presence uri. This was wrong for IPv4. Changing the
addition of brackets exclusive to IPv6 and removing IPv6
flag from caipserver since it is not supported yet.

Change-Id: Ic103f9f0f10dcda3252e95404bc6f1a19d56597b
Signed-off-by: Omkar Hegde <omkar.m.hegde@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1653
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/stack/src/ocstack.c

index b6a3e50..9c0712f 100644 (file)
@@ -266,7 +266,7 @@ static void CAReceiveHandler(void *data)
                 CAEndpoint_t ep;
                 strncpy(ep.addr, srcIPAddress, MAX_ADDR_STR_SIZE_CA);
                 ep.port = srcPort;
-                ep.flags = (CATransportFlags_t)CA_IPV4 | CA_IPV6;
+                ep.flags = (CATransportFlags_t)CA_IPV4;
                 ep.adapter = CA_ADAPTER_IP;
 
                 if (info->endpoint.flags & CA_SECURE)
index f051715..4106900 100644 (file)
@@ -733,7 +733,7 @@ static int FormCanonicalPresenceUri(const CAEndpoint_t *endpoint, char *resource
 
     const char *format;
 
-    if (endpoint->flags & CA_IPV6)
+    if ((endpoint->flags & CA_IPV6) && !(endpoint->flags & CA_IPV4))
     {
         format = "coap://[%s]:%u%s";
     }
@@ -784,8 +784,18 @@ OCStackResult HandlePresenceResponse(const CAEndpoint_t *endpoint,
     }
     else
     {
-        snprintf (presenceUri, MAX_URI_LENGTH, "coap://[%s]:%u%s", OC_MULTICAST_IP,
-                    OC_MULTICAST_PORT, OC_RSRVD_PRESENCE_URI);
+        CAEndpoint_t endpointMulticast;
+        endpointMulticast.flags = endpoint->flags;
+        OICStrcpy(endpointMulticast.addr, sizeof(endpointMulticast.addr), OC_MULTICAST_IP);
+        endpointMulticast.port = OC_MULTICAST_PORT;
+
+        uriLen = FormCanonicalPresenceUri(&endpointMulticast, OC_RSRVD_PRESENCE_URI, presenceUri);
+
+        if (uriLen < 0 || uriLen >= sizeof (presenceUri))
+        {
+            return OC_STACK_INVALID_URI;
+        }
+
         cbNode = GetClientCB(NULL, 0, NULL, presenceUri);
         if (cbNode)
         {