From: Piotr Kosko Date: Fri, 6 Nov 2020 08:44:38 +0000 (+0100) Subject: [NBS] partial fix for accessing network IPv6 X-Git-Tag: submit/tizen/20220516.114229^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F275063%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [NBS] partial fix for accessing network IPv6 Change-Id: Ief4f4d38f43aac6667d20e24a3c50d58c844ffe8 --- diff --git a/src/networkbearerselection/networkbearerselection_manager.cc b/src/networkbearerselection/networkbearerselection_manager.cc index 33ec396f..e8840552 100644 --- a/src/networkbearerselection/networkbearerselection_manager.cc +++ b/src/networkbearerselection/networkbearerselection_manager.cc @@ -18,6 +18,7 @@ #include "common/logger.h" #include "common/scope_exit.h" #include "common/task-queue.h" +#include "common/tools.h" #include #include @@ -379,6 +380,8 @@ bool NetworkBearerSelectionManager::registerStateChangeListener(const std::strin } struct in_addr* addr = nullptr; + size_t addr_len = INET_ADDRSTRLEN; + connection_address_family_e address_family = CONNECTION_ADDRESS_FAMILY_IPV4; if (AF_INET == serv_info->ai_family) { LoggerD("IPv4 address"); struct sockaddr_in* ipv = (struct sockaddr_in*)serv_info->ai_addr; @@ -387,17 +390,19 @@ bool NetworkBearerSelectionManager::registerStateChangeListener(const std::strin LoggerD("IPv6 address"); struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)serv_info->ai_addr; addr = (struct in_addr*)&ipv6->sin6_addr; + addr_len = INET6_ADDRSTRLEN; + address_family = CONNECTION_ADDRESS_FAMILY_IPV6; } else { LoggerE("Unknown ai_family address"); return false; } - std::unique_ptr host_addr_ptr(new char[serv_info->ai_addrlen + 1], - &std::free); + std::unique_ptr host_addr_ptr(new char[addr_len], &std::free); - if (nullptr == - inet_ntop(serv_info->ai_family, addr, host_addr_ptr.get(), serv_info->ai_addrlen)) { - LoggerE("Failed to convert address"); + if (nullptr == inet_ntop(serv_info->ai_family, addr, host_addr_ptr.get(), addr_len)) { + int error = errno; + LoggerE("Failed to convert address: (%d) %s", error, + common::tools::GetErrorString(error).c_str()); return false; } @@ -410,29 +415,21 @@ bool NetworkBearerSelectionManager::registerStateChangeListener(const std::strin return false; } - connection_address_family_e address_family = CONNECTION_ADDRESS_FAMILY_IPV4; - - if (AF_INET == serv_info->ai_family) { - LoggerD("IPv4 address"); - } else if (AF_INET6 == serv_info->ai_family) { - LoggerD("IPv6 address"); - address_family = CONNECTION_ADDRESS_FAMILY_IPV6; - } else { - LoggerE("Incorrect family address"); - return false; - } - ret = connection_profile_get_gateway_address(m_profile_handle_, address_family, &gateway); if (CONNECTION_ERROR_NONE != ret) { - LoggerE("Failed to get gateway"); + LoggerE("Failed to get gateway: (%d) %s", ret, common::tools::GetErrorString(ret).c_str()); return false; } + LoggerD( + "connection_add_route_entry for address_family: %d interface_name: %s host_addr: %s, " + "gateway: %s", + address_family, interface_name, host_addr_ptr.get(), gateway); ret = connection_add_route_entry(m_connection_handle_, address_family, interface_name, host_addr_ptr.get(), gateway); if (CONNECTION_ERROR_NONE != ret) { - LoggerE("Adding route failed"); + LoggerE("Adding route failed: (%d) %s", ret, common::tools::GetErrorString(ret).c_str()); return false; } else { LoggerD("Adding route success");