From 75359691b029c4f4fea977daeed5edc11627f1a9 Mon Sep 17 00:00:00 2001 From: Abhishek Sansanwal Date: Tue, 6 Jun 2017 12:31:42 +0530 Subject: [PATCH] Added function to get address from connection CAPI Description: Added function to get ip, dns, gateway and subnet mask from connection CAPI. Signed-off-by: Abhishek Sansanwal Change-Id: I36777a9ad27328a1bdcb1c9ca82b20ae84f9d502 --- include/data/system/data_wired.h | 18 ++++++++++++++++++ src/data/system/data_wired.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/data/system/data_wired.h b/include/data/system/data_wired.h index 8fa8acf..e2b9f68 100644 --- a/include/data/system/data_wired.h +++ b/include/data/system/data_wired.h @@ -28,6 +28,13 @@ enum wired_status_type { WIRED_STATUS_COMPLETE, }; +enum address_type { + IP_ADDRESS = 0, + DNS_ADDRESS, + SUBNET_MASK, + GATEWAY_ADDRESS, +}; + enum wired_network_type { WIRED_TYPE_DEFAULT = 0, WIRED_TYPE_MANUAL, @@ -63,6 +70,17 @@ int get_wired_network_status(struct _connection_data *data); * @brief * * @param data +* @param type +* @param address +* +* @return +*/ +bool get_address(struct _connection_data *data, int type, char **address); + +/** +* @brief +* +* @param data * * @return */ diff --git a/src/data/system/data_wired.c b/src/data/system/data_wired.c index bab2903..b436ddb 100755 --- a/src/data/system/data_wired.c +++ b/src/data/system/data_wired.c @@ -51,6 +51,46 @@ int get_wired_network_status(struct _connection_data *data) return result; } +bool get_address(struct _connection_data *data, int type, char **address) +{ + int rv = 0; + connection_profile_h profile; + + if (!data || !data->profile) + return false; + + profile = data->profile; + switch (type) { + case IP_ADDRESS: + rv = connection_profile_get_ip_address(profile, + CONNECTION_ADDRESS_FAMILY_IPV4, address); + break; + case DNS_ADDRESS: + rv = connection_profile_get_dns_address(profile, 1, + CONNECTION_ADDRESS_FAMILY_IPV4, address); + break; + case SUBNET_MASK: + rv = connection_profile_get_subnet_mask(profile, + CONNECTION_ADDRESS_FAMILY_IPV4, address); + break; + case GATEWAY_ADDRESS: + rv = connection_profile_get_gateway_address(profile, + CONNECTION_ADDRESS_FAMILY_IPV4, address); + break; + default: + _ERR("Unknown address type"); + return false; + } + + if (rv != CONNECTION_ERROR_NONE) { + _ERR("Failed to get address [%d]", rv); + return false; + } + + return true; + +} + bool get_ethernet_profile(struct _connection_data *data) { int rv = 0; -- 2.7.4