Add function to get current IP from connman module 17/203917/3 accepted/tizen/unified/20190429.103804 submit/tizen/20190429.011734
authorYu <jiung.yu@samsung.com>
Thu, 18 Apr 2019 06:11:24 +0000 (15:11 +0900)
committerJiung Yu <jiung.yu@samsung.com>
Mon, 29 Apr 2019 01:13:47 +0000 (01:13 +0000)
Change-Id: I471cf503fbbb772f800ce00f6317cfdd13cd847d
Signed-off-by: Yu Jiung <jiung.yu@samsung.com>
include/inm-connman.h
src/inm-connman-service.c

index 91c8edf9a3f0f921799aaa6509df3a1dbfca6826..9a2a01eb7792695ac02b9e65f2122436dd3867b8 100644 (file)
@@ -85,6 +85,11 @@ typedef enum {
        CONNMAN_SERVICE_ERROR_INVALID_KEY,
 } connman_service_error_e;
 
+typedef enum {
+       CONNMAN_IP_TYPE_V4,
+       CONNMAN_IP_TYPE_V6,
+} connman_ip_type_e;
+
 int inm_connman_init();
 int inm_connman_deinit();
 
@@ -109,6 +114,7 @@ int inm_connman_get_current_connection(GVariant **current_conn);
 int inm_connman_get_connections(GVariant **connections);
 int inm_connman_get_current_service_type(connman_service_type_e *type);
 int inm_connman_get_current_service_iface(gchar **ifname);
+int inm_connman_get_current_service_ip(connman_ip_type_e type, gchar **ip);
 int inm_connman_get_current_service_gateway(gchar **gateway_ip);
 
 int inm_connman_tech_get_state(connman_service_type_e type,
index e91c410cb73c59b71c236358cd04e9b09133a6fd..4e2d3169fff5eed09fbfcfc28a7d1831aa5b11aa 100644 (file)
@@ -2917,6 +2917,35 @@ int inm_connman_get_current_service_iface(gchar **ifname)
        return ret;
 }
 
+int inm_connman_get_current_service_ip(connman_ip_type_e type, gchar **ip)
+{
+       connman_service_s *service = NULL;
+       char ip_str[INET6_ADDRSTRLEN] = {0,};
+       int ret = INM_CONNMAN_ERROR_NONE;
+
+       __INM_FUNC_ENTER__;
+
+       service = __get_current_service();
+       if (service == NULL) {
+               INM_LOGW("No current connections");
+               __INM_FUNC_EXIT__;
+               return INM_CONNMAN_ERROR_NO_CONNECTION;
+       }
+
+       if (type == CONNMAN_IP_TYPE_V4)
+               inet_ntop(AF_INET, &(service->ip.address), ip_str, INET_ADDRSTRLEN);
+       else if (type == CONNMAN_IP_TYPE_V6)
+               inet_ntop(AF_INET6, &(service->ipv6.address), ip_str, INET6_ADDRSTRLEN);
+
+       if (strlen(ip_str) != 0)
+               *ip = g_strdup(ip_str);
+       else
+               ret = INM_CONNMAN_ERROR_OPERATION_FAILED;
+
+       __INM_FUNC_EXIT__;
+       return ret;
+}
+
 int inm_connman_get_current_service_gateway(gchar **gateway_ip)
 {
        connman_service_s *service = NULL;