From de9ab2061bc498c0479553c2a4f151eccbd89b4e Mon Sep 17 00:00:00 2001 From: liuxiyao Date: Tue, 31 Oct 2023 16:09:45 +0800 Subject: [PATCH 1/8] add dns capi Signed-off-by: liuxiyao --- .../netmanager_base/netconnclient/BUILD.gn | 51 +++++++++++ .../include/native_net_conn_api.h | 86 +++++++++++++++++++ .../netconnclient/libnet_connection.ndk.json | 4 + .../netconnclient/src/native_net_conn_api.cpp | 56 ++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 communication/netmanager_base/netconnclient/BUILD.gn create mode 100644 communication/netmanager_base/netconnclient/include/native_net_conn_api.h create mode 100644 communication/netmanager_base/netconnclient/libnet_connection.ndk.json create mode 100644 communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp diff --git a/communication/netmanager_base/netconnclient/BUILD.gn b/communication/netmanager_base/netconnclient/BUILD.gn new file mode 100644 index 000000000..5834a1ac3 --- /dev/null +++ b/communication/netmanager_base/netconnclient/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos.gni") +import("//foundation/communication/netmanager_base/netmanager_base_config.gni") + +ohos_ndk_library("libnet_connection") { + output_name = "net_connection" + output_extension = "so" + ndk_description_file = "./libnet_connection.ndk.json" + min_compact_version = "1" + system_capability = "SystemCapability.Communication.NetManager.Core" + system_capability_headers = [ "./include/native_net_conn_api.h" ] +} + +ohos_ndk_headers("netconn_header") { + dest_dir = "$ndk_headers_out_dir/netconn" + sources = [ "./include/native_net_conn_api.h" ] +} + +ohos_shared_library("net_connection") { + output_extension = "so" + include_dirs = + [ "$NETMANAGER_BASE_ROOT/interfaces/kits/c/netconnclient/include" ] + + sources = [ "$NETMANAGER_BASE_ROOT/interfaces/kits/c/netconnclient/src/native_net_conn_api.cpp" ] + + deps = [ + "$INNERKITS_ROOT/netconnclient:net_conn_manager_if", + "$NETMANAGER_BASE_ROOT/utils:net_manager_common", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + part_name = "netmanager_base" + subsystem_name = "communication" + relative_install_dir = "ndk" +} diff --git a/communication/netmanager_base/netconnclient/include/native_net_conn_api.h b/communication/netmanager_base/netconnclient/include/native_net_conn_api.h new file mode 100644 index 000000000..3777b6374 --- /dev/null +++ b/communication/netmanager_base/netconnclient/include/native_net_conn_api.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 NATIVE_NET_CONN_API_H +#define NATIVE_NET_CONN_API_H + +/** + * @addtogroup NetConn + * @{ + * + * @brief Provide C interface for the data network connection module of network management. + * + * @since 11 + * @version 1.0 + */ + +/** + * @file native_net_conn_api.h + * + * @brief Provide C interface for the data network connection module of network management. + * + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get DNS result with netId. + * + * @param host The host name to query. + * @param serv Service name. + * @param hint Pointer to the addrinfo structure. + * @param res Store DNS query results and return them in a linked list format. + * @param netId DNS query netId, 0 is used for default netid query. + * @return 0 - Success. + * @return 201 - Missing permissions. + * @return 401 - Parameter error. + * @return 2100002 - Unable to connect to service. + * @return 2100003 - Internal error. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 +*/ +int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId); + +/** + * @brief Free DNS result. + * + * @param res DNS query result chain header. + * @return 0 - Success. + * @return 201 - Missing permissions. + * @return 401 - Parameter error. + * @return 2100002 - Unable to connect to service. + * @return 2100003 - Internal error. + * @permission ohos.permission.INTERNET + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 +*/ +int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* NATIVE_NET_CONN_API_H */ diff --git a/communication/netmanager_base/netconnclient/libnet_connection.ndk.json b/communication/netmanager_base/netconnclient/libnet_connection.ndk.json new file mode 100644 index 000000000..4717b9bd7 --- /dev/null +++ b/communication/netmanager_base/netconnclient/libnet_connection.ndk.json @@ -0,0 +1,4 @@ +[ + {"name": "OH_NetConn_GetAddrInfo"}, + {"name": "OH_NetConn_FreeDnsResult"} +] \ No newline at end of file diff --git a/communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp b/communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp new file mode 100644 index 000000000..e5896d25f --- /dev/null +++ b/communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 "native_net_conn_api.h" +#include "net_conn_client.h" +#include "net_manager_constants.h" +#include "net_mgr_log_wrapper.h" + +using namespace OHOS::NetManagerStandard; + +int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId) +{ + int32_t ret = NETMANAGER_SUCCESS; + int status = 0; + struct queryparam qp_param; + if (host == nullptr || res == nullptr) { + NETMGR_LOG_E("OH_NetConn_GetAddrInfo received invalid parameters"); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + + memset(&qp_param, 0, sizeof(struct queryparam)); + qp_param.qp_netid = netId; + qp_param.qp_type = 0; + + status = getaddrinfo_ext(host, serv, hint, res, &qp_param); + if (status < 0) { + ret = NETMANAGER_ERR_PARAMETER_ERROR; + } + + return ret; +} + + +int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res) +{ + if (res == nullptr) { + NETMGR_LOG_E("OH_NetConn_FreeDnsResult received invalid parameters"); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + + freeaddrinfo(res); + + return NETMANAGER_SUCCESS; +} -- Gitee From 4ed3bfaf65115282cfffd4f15be84b84f08d9152 Mon Sep 17 00:00:00 2001 From: liuxiyao Date: Tue, 31 Oct 2023 20:08:56 +0800 Subject: [PATCH 2/8] add dns api Signed-off-by: liuxiyao --- .../netconnclient/src/native_net_conn_api.cpp | 56 ------------------- .../netmanager}/BUILD.gn | 24 +------- .../netmanager}/include/native_net_conn_api.h | 0 .../netmanager}/libnet_connection.ndk.json | 0 4 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp rename {communication/netmanager_base/netconnclient => network/netmanager}/BUILD.gn (64%) rename {communication/netmanager_base/netconnclient => network/netmanager}/include/native_net_conn_api.h (100%) rename {communication/netmanager_base/netconnclient => network/netmanager}/libnet_connection.ndk.json (100%) diff --git a/communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp b/communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp deleted file mode 100644 index e5896d25f..000000000 --- a/communication/netmanager_base/netconnclient/src/native_net_conn_api.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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 "native_net_conn_api.h" -#include "net_conn_client.h" -#include "net_manager_constants.h" -#include "net_mgr_log_wrapper.h" - -using namespace OHOS::NetManagerStandard; - -int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId) -{ - int32_t ret = NETMANAGER_SUCCESS; - int status = 0; - struct queryparam qp_param; - if (host == nullptr || res == nullptr) { - NETMGR_LOG_E("OH_NetConn_GetAddrInfo received invalid parameters"); - return NETMANAGER_ERR_PARAMETER_ERROR; - } - - memset(&qp_param, 0, sizeof(struct queryparam)); - qp_param.qp_netid = netId; - qp_param.qp_type = 0; - - status = getaddrinfo_ext(host, serv, hint, res, &qp_param); - if (status < 0) { - ret = NETMANAGER_ERR_PARAMETER_ERROR; - } - - return ret; -} - - -int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res) -{ - if (res == nullptr) { - NETMGR_LOG_E("OH_NetConn_FreeDnsResult received invalid parameters"); - return NETMANAGER_ERR_PARAMETER_ERROR; - } - - freeaddrinfo(res); - - return NETMANAGER_SUCCESS; -} diff --git a/communication/netmanager_base/netconnclient/BUILD.gn b/network/netmanager/BUILD.gn similarity index 64% rename from communication/netmanager_base/netconnclient/BUILD.gn rename to network/netmanager/BUILD.gn index 5834a1ac3..79dbf1533 100644 --- a/communication/netmanager_base/netconnclient/BUILD.gn +++ b/network/netmanager/BUILD.gn @@ -24,28 +24,6 @@ ohos_ndk_library("libnet_connection") { } ohos_ndk_headers("netconn_header") { - dest_dir = "$ndk_headers_out_dir/netconn" + dest_dir = "$ndk_headers_out_dir/network/netmanager" sources = [ "./include/native_net_conn_api.h" ] } - -ohos_shared_library("net_connection") { - output_extension = "so" - include_dirs = - [ "$NETMANAGER_BASE_ROOT/interfaces/kits/c/netconnclient/include" ] - - sources = [ "$NETMANAGER_BASE_ROOT/interfaces/kits/c/netconnclient/src/native_net_conn_api.cpp" ] - - deps = [ - "$INNERKITS_ROOT/netconnclient:net_conn_manager_if", - "$NETMANAGER_BASE_ROOT/utils:net_manager_common", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] - - part_name = "netmanager_base" - subsystem_name = "communication" - relative_install_dir = "ndk" -} diff --git a/communication/netmanager_base/netconnclient/include/native_net_conn_api.h b/network/netmanager/include/native_net_conn_api.h similarity index 100% rename from communication/netmanager_base/netconnclient/include/native_net_conn_api.h rename to network/netmanager/include/native_net_conn_api.h diff --git a/communication/netmanager_base/netconnclient/libnet_connection.ndk.json b/network/netmanager/libnet_connection.ndk.json similarity index 100% rename from communication/netmanager_base/netconnclient/libnet_connection.ndk.json rename to network/netmanager/libnet_connection.ndk.json -- Gitee From 9b3ecb62169f24ec69cdc0c18337e6721f4a0930 Mon Sep 17 00:00:00 2001 From: hw_yys Date: Fri, 3 Nov 2023 20:38:41 +0800 Subject: [PATCH 3/8] update net_connection.h Signed-off-by: hw_yys --- .../{native_net_conn_api.h => net_connection.h} | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) rename network/netmanager/include/{native_net_conn_api.h => net_connection.h} (82%) diff --git a/network/netmanager/include/native_net_conn_api.h b/network/netmanager/include/net_connection.h similarity index 82% rename from network/netmanager/include/native_net_conn_api.h rename to network/netmanager/include/net_connection.h index 3777b6374..6bdddcbdb 100644 --- a/network/netmanager/include/native_net_conn_api.h +++ b/network/netmanager/include/net_connection.h @@ -17,7 +17,7 @@ #define NATIVE_NET_CONN_API_H /** - * @addtogroup NetConn + * @addtogroup NetConnection * @{ * * @brief Provide C interface for the data network connection module of network management. @@ -27,11 +27,12 @@ */ /** - * @file native_net_conn_api.h + * @file net_connection.h * * @brief Provide C interface for the data network connection module of network management. * * @syscap SystemCapability.Communication.NetManager.Core + * @library libnet_connection.so * @since 11 * @version 1.0 */ @@ -50,11 +51,7 @@ extern "C" { * @param hint Pointer to the addrinfo structure. * @param res Store DNS query results and return them in a linked list format. * @param netId DNS query netId, 0 is used for default netid query. - * @return 0 - Success. - * @return 201 - Missing permissions. - * @return 401 - Parameter error. - * @return 2100002 - Unable to connect to service. - * @return 2100003 - Internal error. + * @return 0 - Success. 201 - Missing permissions. 401 - Parameter error. 2100002 - Unable to connect to service. 2100003 - Internal error. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetManager.Core * @since 11 @@ -66,11 +63,7 @@ int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, st * @brief Free DNS result. * * @param res DNS query result chain header. - * @return 0 - Success. - * @return 201 - Missing permissions. - * @return 401 - Parameter error. - * @return 2100002 - Unable to connect to service. - * @return 2100003 - Internal error. + * @return 0 - Success. 201 - Missing permissions. 401 - Parameter error. 2100002 - Unable to connect to service. 2100003 - Internal error. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetManager.Core * @since 11 -- Gitee From c3122b7cc1d6e0bc6ca6eca02ae61fb513506d14 Mon Sep 17 00:00:00 2001 From: SubmarinePhantom Date: Mon, 6 Nov 2023 10:10:13 +0800 Subject: [PATCH 4/8] update @return Signed-off-by: SubmarinePhantom --- network/netmanager/include/net_connection.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/network/netmanager/include/net_connection.h b/network/netmanager/include/net_connection.h index 6bdddcbdb..9d91e4aff 100644 --- a/network/netmanager/include/net_connection.h +++ b/network/netmanager/include/net_connection.h @@ -51,7 +51,9 @@ extern "C" { * @param hint Pointer to the addrinfo structure. * @param res Store DNS query results and return them in a linked list format. * @param netId DNS query netId, 0 is used for default netid query. - * @return 0 - Success. 201 - Missing permissions. 401 - Parameter error. 2100002 - Unable to connect to service. 2100003 - Internal error. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetManager.Core * @since 11 @@ -63,7 +65,9 @@ int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, st * @brief Free DNS result. * * @param res DNS query result chain header. - * @return 0 - Success. 201 - Missing permissions. 401 - Parameter error. 2100002 - Unable to connect to service. 2100003 - Internal error. + * @return 0 - Success. + * 201 - Missing permissions. 401 - Parameter error. + * 2100002 - Unable to connect to service. 2100003 - Internal error. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetManager.Core * @since 11 -- Gitee From f705f909ba7e06557e6374dd50cf13c60078dc5d Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 6 Nov 2023 03:12:13 +0000 Subject: [PATCH 5/8] update network/netmanager/include/net_connection.h. Signed-off-by: Aurora --- network/netmanager/include/net_connection.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/network/netmanager/include/net_connection.h b/network/netmanager/include/net_connection.h index 9d91e4aff..1c1dde4e1 100644 --- a/network/netmanager/include/net_connection.h +++ b/network/netmanager/include/net_connection.h @@ -65,9 +65,9 @@ int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, st * @brief Free DNS result. * * @param res DNS query result chain header. - * @return 0 - Success. - * 201 - Missing permissions. 401 - Parameter error. - * 2100002 - Unable to connect to service. 2100003 - Internal error. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetManager.Core * @since 11 -- Gitee From e1194a251fb995d6bb6142e1df332bc9b42e85e3 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 6 Nov 2023 03:29:23 +0000 Subject: [PATCH 6/8] update network/netmanager/include/net_connection.h. Signed-off-by: Aurora --- network/netmanager/include/net_connection.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/netmanager/include/net_connection.h b/network/netmanager/include/net_connection.h index 1c1dde4e1..a1b069d78 100644 --- a/network/netmanager/include/net_connection.h +++ b/network/netmanager/include/net_connection.h @@ -51,8 +51,8 @@ extern "C" { * @param hint Pointer to the addrinfo structure. * @param res Store DNS query results and return them in a linked list format. * @param netId DNS query netId, 0 is used for default netid query. - * @return 0 - Success. 201 - Missing permissions. - * 401 - Parameter error. 2100002 - Unable to connect to service. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. * 2100003 - Internal error. * @permission ohos.permission.INTERNET * @syscap SystemCapability.Communication.NetManager.Core -- Gitee From 892d4520e1e151d72f7c711cacc9bcd1b7f723f7 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 6 Nov 2023 07:25:07 +0000 Subject: [PATCH 7/8] update network/netmanager/libnet_connection.ndk.json. Signed-off-by: Aurora --- network/netmanager/libnet_connection.ndk.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/network/netmanager/libnet_connection.ndk.json b/network/netmanager/libnet_connection.ndk.json index 4717b9bd7..2c5ac35b0 100644 --- a/network/netmanager/libnet_connection.ndk.json +++ b/network/netmanager/libnet_connection.ndk.json @@ -1,4 +1,10 @@ [ - {"name": "OH_NetConn_GetAddrInfo"}, - {"name": "OH_NetConn_FreeDnsResult"} + { + "first_introdeced":"11", + "name": "OH_NetConn_GetAddrInfo" + }, + { + "first_introdeced":"11", + "name": "OH_NetConn_FreeDnsResult" + } ] \ No newline at end of file -- Gitee From 6f7d243ea6141354e62fdf9a0c4a9bf5f2753a93 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 6 Nov 2023 08:20:14 +0000 Subject: [PATCH 8/8] update network/netmanager/BUILD.gn. Signed-off-by: Aurora --- network/netmanager/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/netmanager/BUILD.gn b/network/netmanager/BUILD.gn index 79dbf1533..339128a89 100644 --- a/network/netmanager/BUILD.gn +++ b/network/netmanager/BUILD.gn @@ -20,10 +20,10 @@ ohos_ndk_library("libnet_connection") { ndk_description_file = "./libnet_connection.ndk.json" min_compact_version = "1" system_capability = "SystemCapability.Communication.NetManager.Core" - system_capability_headers = [ "./include/native_net_conn_api.h" ] + system_capability_headers = [ "./include/net_connection.h" ] } ohos_ndk_headers("netconn_header") { dest_dir = "$ndk_headers_out_dir/network/netmanager" - sources = [ "./include/native_net_conn_api.h" ] + sources = [ "./include/net_connection.h" ] } -- Gitee