From ef1bc028fa1fb0c0a7eab20254a727bdfcd82c30 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Mon, 20 Mar 2017 14:30:03 +0900 Subject: [PATCH] Implement API to get IPv6 addresses Change-Id: I87838ac2ad0a8672f462122bb0c2f89f7175d57f Signed-off-by: Seonah Moon --- packaging/capi-network-connection.spec | 2 +- src/connection.c | 57 ++++++++++++++++++++++++++++++++++ test/connection_test.c | 40 ++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 8402876..0df7a00 100755 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 1.0.97 +Version: 1.0.98 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/connection.c b/src/connection.c index caf6259..d09cb00 100755 --- a/src/connection.c +++ b/src/connection.c @@ -1380,3 +1380,60 @@ EXPORT_API int connection_reset_statistics(connection_h connection, return __reset_statistic(connection_type, statistics_type); } +EXPORT_API int connection_foreach_ipv6_address(connection_h connection, + connection_type_e connection_type, connection_ipv6_address_cb callback, + void *user_data) +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, + TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + GSList *ipv6_address_list = NULL; + + if (!(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + int rv = CONNECTION_ERROR_NONE; + + switch (connection_type) { + case CONNECTION_TYPE_WIFI: + rv = net_foreach_ipv6_address(NET_DEVICE_WIFI, + &ipv6_address_list); + break; + case CONNECTION_TYPE_CELLULAR: + rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR, + &ipv6_address_list); + break; + case CONNECTION_TYPE_ETHERNET: + rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET, + &ipv6_address_list); + break; + case CONNECTION_TYPE_BT: + rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH, + &ipv6_address_list); + break; + default: + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address" + " Failed = %d\n", rv); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + GSList *list; + for (list = ipv6_address_list; list; list = list->next) { + rv = callback((char *)list->data, user_data); + if (rv == false) + break; + } + + g_slist_free_full(ipv6_address_list, g_free); + ipv6_address_list = NULL; + + return CONNECTION_ERROR_NONE; +} + diff --git a/test/connection_test.c b/test/connection_test.c index 38ab325..7181144 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -1916,6 +1916,42 @@ int test_reset_profile(void) return 1; } +static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data) +{ + printf("IPv6 Address : %s\n", ipv6_address); + return true; +} + +int test_foreach_ipv6_address(void) +{ + int rv = 0; + int type; + connection_type_e conn_type; + + test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type); + + switch (type) { + case 1: + conn_type = CONNECTION_TYPE_WIFI; + break; + case 2: + conn_type = CONNECTION_TYPE_ETHERNET; + break; + default: + printf("Wrong number!!\n"); + return -1; + } + + rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL); + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get IPv6 address\n"); + return -1; + } + + return 1; +} + + int main(int argc, char **argv) { GMainLoop *mainloop; @@ -1986,6 +2022,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("x - Get ethernet cable state\n"); printf("B - Add IPv6 new route\n"); printf("C - Remove IPv6 route\n"); + printf("D - Get IPv6 address\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); } @@ -2096,6 +2133,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'C': rv = test_remove_route_ipv6(); break; + case 'D': + rv = test_foreach_ipv6_address(); + break; } if (rv == 1) -- 2.7.4