comp-manager: Set host address correctly when sending unicast discovery
authorSaurav Babu <saurav.babu@samsung.com>
Thu, 25 Jan 2018 06:29:19 +0000 (11:59 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:47 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/companion-manager/src/comp_group.c

index 920dadd..4e9f813 100644 (file)
@@ -591,12 +591,26 @@ int comp_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2)
 int comp_group_send_data(gchar *uuid_dev, gchar *addr, int port, gchar *data, int len)
 {
        int ret;
+       char ip[50];
+       char *percent;
 
        LOG_BEGIN();
 
+       g_strlcpy(ip, addr, strlen(addr) + 1);
+
+       /* Remove % from address */
+       percent = strchr(ip, '%');
+       if (percent)
+               percent[0] = '\0';
+
        iot_discovery_t *iot = g_new0(iot_discovery_t, 1);
        iot->uuid = g_strdup(uuid_dev);
-       iot->host = g_strdup_printf("coap://[%s]:%d", addr, port);
+
+       if (strchr(ip, ':'))
+               iot->host = g_strdup_printf("coap://[%s]:%d", ip, port);
+       else
+               iot->host = g_strdup_printf("coap://%s:%d", ip, port);
+
        iot->data = g_malloc0(len);
        if (NULL == iot->data) {
                ret = COMP_ERROR_OUT_OF_MEMORY;