1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "net_handle.h"
17
18 #include "iservice_registry.h"
19 #include "net_conn_constants.h"
20 #include "net_manager_constants.h"
21 #include "system_ability_definition.h"
22
23 #include "net_conn_client.h"
24 #include "net_mgr_log_wrapper.h"
25
26 namespace OHOS {
27 namespace NetManagerStandard {
GetAddressesByName(const std::string & host,std::vector<INetAddr> & addrList)28 int32_t NetHandle::GetAddressesByName(const std::string &host, std::vector<INetAddr> &addrList)
29 {
30 if (host.empty()) {
31 NETMGR_LOG_E("host is empty");
32 return NETMANAGER_ERR_PARAMETER_ERROR;
33 }
34 return NetConnClient::GetInstance().GetAddressesByName(host, netId_, addrList);
35 }
36
GetAddressByName(const std::string & host,INetAddr & addr)37 int32_t NetHandle::GetAddressByName(const std::string &host, INetAddr &addr)
38 {
39 if (host.empty()) {
40 NETMGR_LOG_E("host is empty");
41 return NETMANAGER_ERR_PARAMETER_ERROR;
42 }
43 return NetConnClient::GetInstance().GetAddressByName(host, netId_, addr);
44 }
45
BindSocket(int32_t socketFd)46 int32_t NetHandle::BindSocket(int32_t socketFd)
47 {
48 if (socketFd < 0) {
49 NETMGR_LOG_E("socketFd is invalid");
50 return NETMANAGER_ERR_PARAMETER_ERROR;
51 }
52 return NetConnClient::GetInstance().BindSocket(socketFd, netId_);
53 }
54 } // namespace NetManagerStandard
55 } // namespace OHOS