Modified to distinguish local and remote devices using IP information
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 11 Apr 2018 10:56:36 +0000 (19:56 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:49 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
capi/demo/comp-manager.c
capi/include/companion.h
capi/src/companion.c
capi/src/companion_dbus.c
src/companion-manager/include/comp_util.h [new file with mode: 0644]
src/companion-manager/src/comp_db.c [changed mode: 0755->0644]
src/companion-manager/src/comp_group.c [changed mode: 0755->0644]
src/companion-manager/src/comp_util.c [new file with mode: 0644]

index b4c5823..7d0392b 100644 (file)
@@ -45,15 +45,16 @@ static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
 static int run_group_find(MManager *mm, struct menu_data *menu);
 static int run_devices_find(MManager *mm, struct menu_data *menu);
 
-#define CASE_TO_STR(x) case x: return #x;
 static const char* __device_type_to_string(companion_device_type_e type)
 {
        switch (type) {
        /* CHECK: List all enum values here */
-       CASE_TO_STR(COMPANION_DEVICE_TYPE_LOCAL)
-       CASE_TO_STR(COMPANION_DEVICE_TYPE_REMOTE)
+       case COMPANION_DEVICE_TYPE_LOCAL:
+               return "Local";
+       case COMPANION_DEVICE_TYPE_REMOTE:
+               return "Remote";
        default :
-               return "COMPANION_DEVICE_TYPE_ERROR";
+               return "Unknown";
        }
 }
 
@@ -511,7 +512,7 @@ bool _device_found_cb(companion_device_h device, void *user_data)
 
        if (is_exist == FALSE) {
                found_device_list = g_list_append(found_device_list, device);
-               msgp("\r[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+               msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
                        __device_type_to_string(device_type));
        }
 
@@ -570,7 +571,7 @@ int run_device_show_my_device(MManager *mm, struct menu_data *menu)
                companion_device_information_get_ip(device, &ip);
                companion_device_information_get_device_type(device, &device_type);
 
-               msgb("\n[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
                        __device_type_to_string(device_type));
 
                if (device_id)
@@ -896,7 +897,7 @@ bool _mowned_device_found_cb(companion_device_h device, void *user_data)
        companion_device_information_get_ip(device, &ip);
        companion_device_information_get_device_type(device, &device_type);
 
-       msgp("\r[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+       msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
                __device_type_to_string(device_type));
 
        if (device_id)
@@ -960,7 +961,7 @@ int run_device_show_mowned_device(MManager *mm, struct menu_data *menu)
                companion_device_information_get_ip(devices[i], &ip);
                companion_device_information_get_device_type(devices[i], &device_type);
 
-               msgb("\n[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+               msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
                        __device_type_to_string(device_type));
 
                if (device_id)
index ba2d515..e533cb7 100644 (file)
@@ -655,6 +655,7 @@ int companion_request_delete_group(companion_h handle, companion_group_h group,
  * @brief Clones the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a dst should be released using companion_group_information_destroy().
  *
@@ -681,6 +682,7 @@ int companion_group_information_clone(companion_group_h dst,
  * @brief Destroys the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @param[in] group Group handle
  *
@@ -703,6 +705,7 @@ int companion_group_information_destroy(companion_group_h group);
  * @brief Gets group type of the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @param[in] group Group handle
  * @param[out] type Group type
@@ -727,6 +730,7 @@ int companion_group_information_get_type(companion_group_h group,
  * @brief Gets resource type of the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a resource_type should be released using free().
  *
@@ -753,6 +757,7 @@ int companion_group_information_get_resource_type(
  * @brief Gets URI path of the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a uri_path should be released using free().
  *
@@ -779,6 +784,7 @@ int companion_group_information_get_uri_path(companion_group_h group,
  * @brief Gets name of the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a name should be released using free().
  *
@@ -805,6 +811,7 @@ int companion_group_information_get_name(companion_group_h group,
  * @brief Gets host address of the group handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a host_addr should be released using free().
  *
@@ -1097,6 +1104,7 @@ int companion_device_information_get_my_device(companion_h handle,
  * @brief Clones the device handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a target should be released using companion_device_information_destroy().
  *
@@ -1121,6 +1129,7 @@ int companion_device_information_clone(companion_device_h target,
  * @brief Destroys the device handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @param[in] device Device handle
  *
@@ -1141,6 +1150,7 @@ int companion_device_information_destroy(companion_device_h device);
  * @brief Gets device ID of the device handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a device_id should be released using free().
  *
@@ -1165,6 +1175,7 @@ int companion_device_information_get_device_id(companion_device_h device,
  * @brief Gets IP of the device handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a ip should be released using free().
  *
@@ -1188,6 +1199,7 @@ int companion_device_information_get_ip(companion_device_h device, char **ip);
  * @brief Gets device type of the device handle.
  *
  * @since_tizen 5.0
+ * @privlevel public
  *
  * @remarks The @a device_type should be released using free().
  *
index adaf403..bc1c57b 100644 (file)
@@ -392,10 +392,8 @@ EXPORT_API int companion_device_get_found_devices(companion_h handle,
                                        deviceid = (char *)g_variant_get_string(key_value, NULL);
                                else if (g_strcmp0(key, "Address") == 0)
                                        addr = (char *)g_variant_get_string(key_value, NULL);
-/*
-                               else if (g_strcmp0(key, "SecVer") == 0)
-                                       ver = (char *)g_variant_get_string(key_value, NULL);
-*/
+                               else if (g_strcmp0(key, "DeviceType") == 0)
+                                       device_type = g_variant_get_uint16(key_value);
                                else if (g_strcmp0(key, "Port") == 0)
                                        port = g_variant_get_uint16(key_value);
                                else if (g_strcmp0(key, "SecurePort") == 0)
@@ -458,10 +456,8 @@ EXPORT_API int companion_device_get_found_mowned_devices(
                                        deviceid = (char *)g_variant_get_string(key_value, NULL);
                                else if (g_strcmp0(key, "Address") == 0)
                                        addr = (char *)g_variant_get_string(key_value, NULL);
-/*
-                               else if (g_strcmp0(key, "SecVer") == 0)
-                                       ver = (char *)g_variant_get_string(key_value, NULL);
-*/
+                               else if (g_strcmp0(key, "DeviceType") == 0)
+                                       device_type = g_variant_get_uint16(key_value);
                                else if (g_strcmp0(key, "Port") == 0)
                                        port = g_variant_get_uint16(key_value);
                                else if (g_strcmp0(key, "SecurePort") == 0)
@@ -525,10 +521,8 @@ EXPORT_API int companion_device_information_get_my_device(companion_h handle,
                        deviceid = (char *)g_variant_get_string(key_value, NULL);
                else if (g_strcmp0(key, "Address") == 0)
                        addr = (char *)g_variant_get_string(key_value, NULL);
-/*
-               else if (g_strcmp0(key, "SecVer") == 0)
-                       ver = (char *)g_variant_get_string(key_value, NULL);
-*/
+               else if (g_strcmp0(key, "DeviceType") == 0)
+                       device_type = g_variant_get_uint16(key_value);
                else if (g_strcmp0(key, "Port") == 0)
                        port = g_variant_get_uint16(key_value);
                else if (g_strcmp0(key, "SecurePort") == 0)
@@ -685,6 +679,14 @@ EXPORT_API int companion_group_information_clone(companion_group_h target,
        companion_group_s * src = (companion_group_s *)source;
        companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
 
+       ret  = companion_group_information_create(&target);
+       if (COMP_ERROR_NONE != ret) {
+               /* LCOV_EXCL_START */
+               _ERR("companion_group_information_create() Failed(%d)", ret);
+               return ret;
+               /* LCOV_EXCL_STOP */
+       }
+
        if (src->uri_path)
                dst->uri_path = g_strdup(src->uri_path);
 
@@ -831,6 +833,14 @@ EXPORT_API int companion_device_information_clone(companion_device_h target,
        companion_device_s * src = (companion_device_s *)source;
        companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
 
+       ret  = companion_device_information_create(&target);
+       if (COMP_ERROR_NONE != ret) {
+               /* LCOV_EXCL_START */
+               _ERR("companion_device_information_create() Failed(%d)", ret);
+               return ret;
+               /* LCOV_EXCL_STOP */
+       }
+
        if (src->device_id)
                dst->device_id = g_strdup(src->device_id);
        if (src->ip)
index ba5548b..0286cc4 100644 (file)
@@ -115,10 +115,8 @@ static void __device_found_cb(Group *object, gint count, GVariant *va,
                                device_id = (char *)g_variant_get_string(key_value, NULL);
                        else if (g_strcmp0(key, "Address") == 0)
                                ip = (char *)g_variant_get_string(key_value, NULL);
-/*
-                       else if (g_strcmp0(key, "SecVer") == 0)
-                               device_type = (char *)g_variant_get_string(key_value, NULL);
-*/
+                       else if (g_strcmp0(key, "DeviceType") == 0)
+                               device_type = g_variant_get_uint16(key_value);
                        else if (g_strcmp0(key, "Port") == 0)
                                port = g_variant_get_uint16(key_value);
                        else if (g_strcmp0(key, "SecurePort") == 0)
@@ -173,10 +171,8 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
                                device_id = (char *)g_variant_get_string(key_value, NULL);
                        else if (g_strcmp0(key, "Address") == 0)
                                ip = (char *)g_variant_get_string(key_value, NULL);
-/*
-                       else if (g_strcmp0(key, "SecVer") == 0)
-                               device_type = (char *)g_variant_get_string(key_value, NULL);
-*/
+                       else if (g_strcmp0(key, "DeviceType") == 0)
+                               device_type = g_variant_get_uint16(key_value);
                        else if (g_strcmp0(key, "Port") == 0)
                                port = g_variant_get_uint16(key_value);
                        else if (g_strcmp0(key, "SecurePort") == 0)
@@ -185,8 +181,7 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
                }
                g_variant_iter_free(iter_row);
 
-               device = create_device_handle(device_id, ip, device_type, port,
-                                                                         sec_port);
+               device = create_device_handle(device_id, ip, device_type, port, sec_port);
                if (handle->mowned_device_found_cb.found_cb)
                        handle->mowned_device_found_cb.found_cb(device,
                                handle->mowned_device_found_cb.user_data);
diff --git a/src/companion-manager/include/comp_util.h b/src/companion-manager/include/comp_util.h
new file mode 100644 (file)
index 0000000..3fe04c1
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __COMP_UTIL_H__
+#define __COMP_UTIL_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define LOCAL_IP 1 /**< Local IP */
+#define REMOTE_IP 2 /**< Remote IP */
+
+void comp_remove_ip_info(void);
+int comp_make_ip_info(void);
+int comp_compare_ip_and_ifname(char *ipdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __COMP_UTIL_H__ */
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index df6bbb8..088e635
@@ -20,6 +20,7 @@
 #include <comp_mot_agent.h>
 #include <comp_gdbus_group.h>
 #include <comp_db.h>
+#include <comp_util.h>
 
 GList *found_group_list;
 GList *mot_enb_dev_list = NULL;
@@ -319,12 +320,16 @@ int comp_group_add_new_mot_device(comp_mot_device_t *device)
        return is_exist;
 }
 
+
 GVariant *comp_group_get_remote_mot_enabled_devices()
 {
        GVariantBuilder builder;
        GVariant *group_data;
        GList *iter = NULL;
 
+       comp_remove_ip_info();
+       comp_make_ip_info();
+
        g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
 
        iter = mot_enb_dev_list;
@@ -342,6 +347,8 @@ GVariant *comp_group_get_remote_mot_enabled_devices()
                                                          g_variant_new_uint16(device->port));
                g_variant_builder_add(&builder, "{sv}", "Address",
                                                          g_variant_new_string(device->addr));
+               g_variant_builder_add(&builder, "{sv}", "DeviceType",
+                                               g_variant_new_uint16(comp_compare_ip_and_ifname(device->addr)));
                g_variant_builder_add(&builder, "{sv}", "Ifindex",
                                                          g_variant_new_int32(device->ifindex));
                g_variant_builder_add(&builder, "{sv}", "RouteData",
@@ -733,6 +740,9 @@ GVariant *comp_group_get_mowned_devices()
        GVariant *group_data;
        GList *iter = NULL;
 
+       comp_remove_ip_info();
+       comp_make_ip_info();
+
        g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
 
        iter = mowned_dev_list;
@@ -750,6 +760,8 @@ GVariant *comp_group_get_mowned_devices()
                                                          g_variant_new_uint16(device->port));
                g_variant_builder_add(&builder, "{sv}", "Address",
                                                          g_variant_new_string(device->addr));
+               g_variant_builder_add(&builder, "{sv}", "DeviceType",
+                                               g_variant_new_uint16(comp_compare_ip_and_ifname(device->addr)));
                g_variant_builder_add(&builder, "{sv}", "Ifindex",
                                                          g_variant_new_int32(device->ifindex));
                g_variant_builder_add(&builder, "{sv}", "RouteData",
@@ -802,6 +814,8 @@ GVariant *comp_group_get_my_mowned_devices()
                                                          g_variant_new_uint16(my_device->port));
                g_variant_builder_add(&builder, "{sv}", "Address",
                                                          g_variant_new_string(my_device->addr));
+               g_variant_builder_add(&builder, "{sv}", "DeviceType",
+                                               g_variant_new_uint16(comp_compare_ip_and_ifname(my_device->addr)));
                g_variant_builder_add(&builder, "{sv}", "Ifindex",
                                                          g_variant_new_int32(my_device->ifindex));
                g_variant_builder_add(&builder, "{sv}", "RouteData",
diff --git a/src/companion-manager/src/comp_util.c b/src/companion-manager/src/comp_util.c
new file mode 100644 (file)
index 0000000..491641c
--- /dev/null
@@ -0,0 +1,323 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <dirent.h>
+#include <glib.h>
+
+#include <comp_log.h>
+#include <comp_util.h>
+
+#define IPV6_ADDR_GLOBAL 0x0000U
+#define IPV6_ADDR_LOOPBACK 0x0010U
+#define IPV6_ADDR_LINKLOCAL 0x0020U
+#define IPV6_ADDR_SITELOCAL 0x0040U
+#define IPV6_ADDR_COMPATv4 0x0080U
+
+typedef struct _ipv4_info_s {
+       char *ifname; /**< Network interface name */
+       char *mac; /**< MAC address */
+       bool active; /**< interface active or not */
+       int mtu; /**< MTU size */
+       char *ip; /**< IPv4 address */
+       char *broadcast; /**< Broadcast address */
+       char *mask; /**< Net-mask */
+} ipv4_info_s;
+
+typedef struct _ipv6_info_s {
+       char *ifname; /**< Network interface name */
+       char *ip; /**< IPv6 address */
+       int prefix; /**< Prefix length  */
+       char *scope; /**< Scope */
+} ipv6_info_s;
+
+typedef struct _ip_info_s {
+       GList *ipv4_list; /**< IPv4 address list */
+       GList *ipv6_list; /**< IPv6 address list */
+} ip_info_s;
+
+ip_info_s g_ip_info; /**< Local IP address list */
+
+static void __free_ipv4_info(gpointer data)
+{
+       ipv4_info_s *ipv4info = (ipv4_info_s *)data;
+       if (NULL == data)
+               return;
+
+       if (ipv4info->ifname) {
+               free(ipv4info->ifname);
+               ipv4info->ifname = NULL;
+       }
+       if (ipv4info->mac) {
+               free(ipv4info->mac);
+               ipv4info->mac = NULL;
+       }
+       if (ipv4info->ip) {
+               free(ipv4info->ip);
+               ipv4info->ip = NULL;
+       }
+       if (ipv4info->broadcast) {
+               free(ipv4info->broadcast);
+               ipv4info->broadcast = NULL;
+       }
+       if (ipv4info->mask) {
+               free(ipv4info->mask);
+               ipv4info->mask = NULL;
+       }
+       free(ipv4info);
+       ipv4info = NULL;
+}
+
+static void __free_ipv6_info(gpointer data)
+{
+       ipv6_info_s *ipv6info = (ipv6_info_s *)data;
+       if (NULL == data)
+               return;
+
+       if (ipv6info->ifname) {
+               free(ipv6info->ifname);
+               ipv6info->ifname = NULL;
+       }
+       if (ipv6info->ip) {
+               free(ipv6info->ip);
+               ipv6info->ip = NULL;
+       }
+       if (ipv6info->scope) {
+               free(ipv6info->scope);
+               ipv6info->scope= NULL;
+       }
+       free(ipv6info);
+       ipv6info = NULL;
+}
+
+void comp_remove_ip_info(void)
+{
+       if (g_ip_info.ipv4_list) {
+               g_list_free_full(g_ip_info.ipv4_list, __free_ipv4_info);
+               g_ip_info.ipv4_list = NULL;
+       }
+       if (g_ip_info.ipv6_list) {
+               g_list_free_full(g_ip_info.ipv6_list, __free_ipv6_info);
+               g_ip_info.ipv6_list = NULL;
+       }
+}
+
+static void _parse_inet6(const char *ifname) {
+    FILE *f;
+    int scope, prefix;
+    unsigned char ipv6[16];
+    char dname[IFNAMSIZ];
+    char address[INET6_ADDRSTRLEN];
+    char *scopestr;
+
+    f = fopen("/proc/net/if_inet6", "r");
+    if (f == NULL) {
+               LOGE("Failed to access /proc/net/if_inet6");
+        return;
+    }
+
+    while (19 == fscanf(f," %2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" \
+               "%2hhx%2hhx%2hhx%2hhx%2hhx %*x %x %x %*x %s",
+               &ipv6[0], &ipv6[1], &ipv6[2], &ipv6[3], &ipv6[4], &ipv6[5], &ipv6[6], &ipv6[7],
+               &ipv6[8], &ipv6[9], &ipv6[10], &ipv6[11], &ipv6[12], &ipv6[13], &ipv6[14],
+               &ipv6[15], &prefix, &scope, dname)) {
+
+        if (strcmp(ifname, dname) != 0)
+            continue;
+
+        if (inet_ntop(AF_INET6, ipv6, address, sizeof(address)) == NULL)
+            continue;
+
+               ipv6_info_s *_ipv6 = calloc(1, sizeof(ipv6_info_s));
+               if (NULL == _ipv6) {
+                       LOGE("Memory allocation failed");
+                        goto FINISH_READING_IPV6;
+               }
+               _ipv6->ifname = g_strdup(ifname);
+
+        switch (scope) {
+        case IPV6_ADDR_GLOBAL:
+            scopestr = "Global";
+            break;
+        case IPV6_ADDR_LINKLOCAL:
+            scopestr = "Link";
+            break;
+        case IPV6_ADDR_SITELOCAL:
+            scopestr = "Site";
+            break;
+        case IPV6_ADDR_COMPATv4:
+            scopestr = "Compat";
+            break;
+        case IPV6_ADDR_LOOPBACK:
+            scopestr = "Host";
+            break;
+        default:
+            scopestr = "Unknown";
+        }
+               _ipv6->ip = g_strdup(address); /* ex) fe80::212:34ff:fe5a:ec0e */
+               _ipv6->prefix = prefix; /* ex) 64 */
+               _ipv6->scope = g_strdup(scopestr); /* Link */
+
+               g_ip_info.ipv6_list = g_list_append(g_ip_info.ipv6_list, _ipv6);
+    }
+FINISH_READING_IPV6:
+    fclose(f);
+}
+
+static void _parse_ioctl(const char *ifname)
+{
+    int sock;
+    struct ifreq ifr;
+    struct sockaddr_in *ipaddr;
+    char address[INET_ADDRSTRLEN];
+    size_t ifnamelen;
+
+    /* copy ifname to ifr object */
+    ifnamelen = strlen(ifname);
+    if (ifnamelen >= sizeof(ifr.ifr_name)) {
+        return ;
+    }
+    memcpy(ifr.ifr_name, ifname, ifnamelen);
+    ifr.ifr_name[ifnamelen] = '\0';
+
+    /* open socket */
+    sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+    if (sock < 0) {
+               LOGE("socket creation faild");
+        return;
+    }
+
+       ipv4_info_s *_ipv4 = calloc(1, sizeof(ipv4_info_s));
+       if (NULL == _ipv4) {
+               LOGE("Memory allocation failed");
+                goto FINISH_READING_IPV4;
+       }
+       _ipv4->ifname = g_strdup(ifname); /* ex) wlan0 */
+
+    /* process mac */
+    if (ioctl(sock, SIOCGIFHWADDR, &ifr) != -1) {
+               char buf[64] = {0,};
+               snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
+                       ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1],
+                       ifr.ifr_hwaddr.sa_data[2], ifr.ifr_hwaddr.sa_data[3],
+                       ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
+               _ipv4->mac = g_strdup(buf); /* ex) 00:12:34:5a:ec:0e */
+    }
+
+    /* process mtu */
+    if (ioctl(sock, SIOCGIFMTU, &ifr) != -1) {
+               _ipv4->mtu = ifr.ifr_mtu; /* ex) 1492 */
+    }
+
+    /* die if cannot get address */
+    if (ioctl(sock, SIOCGIFADDR, &ifr) == -1) {
+               _ipv4->active = false;
+        goto FINISH_READING_IPV4;
+    }
+
+    /* process ip */
+    ipaddr = (struct sockaddr_in *)&ifr.ifr_addr;
+    if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+               _ipv4->ip = g_strdup(address); /* ex) 192.168.86.111 */
+    }
+
+    /* try to get broadcast */
+    if (ioctl(sock, SIOCGIFBRDADDR, &ifr) != -1) {
+        ipaddr = (struct sockaddr_in *)&ifr.ifr_broadaddr;
+        if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+                       _ipv4->broadcast = g_strdup(address); /* ex) 192.168.86.255 */
+        }
+    }
+
+    /* try to get mask */
+    if (ioctl(sock, SIOCGIFNETMASK, &ifr) != -1) {
+        ipaddr = (struct sockaddr_in *)&ifr.ifr_netmask;
+        if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+                       _ipv4->mask = g_strdup(address); /* ex) 255.255.255.0 */
+        }
+    }
+FINISH_READING_IPV4:
+    close(sock);
+       g_ip_info.ipv4_list = g_list_append(g_ip_info.ipv4_list, _ipv4);
+}
+
+
+int comp_make_ip_info(void)
+{
+    DIR *d;
+    struct dirent *de;
+
+    d = opendir("/sys/class/net/");
+    if (d == NULL) {
+               LOGE("Failed to access /sys/class/net/");
+        return -1;
+    }
+
+    while (NULL != (de = readdir(d))) {
+        if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
+            continue;
+
+        _parse_ioctl(de->d_name);
+        _parse_inet6(de->d_name);
+    }
+    closedir(d);
+
+    return 0;
+}
+
+int comp_compare_ip_and_ifname(char *ipdata)
+{
+       char *ip = NULL;
+       char *ifname = NULL;
+       GList *iter = NULL;
+
+       ip = strtok_r(ipdata, "%", &ipdata);
+       ifname = strtok_r(ipdata, "%", &ipdata);
+
+       /* In case IPv4 ip = 192.168.86.90, ifname = (null) */
+       if (NULL == ifname) {
+               ipv4_info_s *ipv4info = NULL;
+               iter = g_list_first(g_ip_info.ipv4_list);
+               while (NULL != iter) {
+                       ipv4info = iter->data;
+                       if (ipv4info && ipv4info->ip && !strncmp(ipv4info->ip, ip, INET_ADDRSTRLEN)) {
+                               return LOCAL_IP;
+                       }
+                       iter = g_list_next(iter);
+               }
+       } else {
+               /* In case IPv4 ip = fe80::7edd:90ff:feb1:1b57, ifname = wlan0 */
+               ipv6_info_s *ipv6info = NULL;
+               iter = g_list_first(g_ip_info.ipv4_list);
+               while (NULL != iter) {
+                       ipv6info = iter->data;
+                       if (ipv6info && ipv6info->ip && !strncmp(ipv6info->ip, ip, INET6_ADDRSTRLEN)) {
+                               return LOCAL_IP;
+                       }
+                       iter = g_list_next(iter);
+               }
+       }
+
+       return REMOTE_IP;
+}
+