• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef NATIVE_NET_CONN_API_H
17 #define NATIVE_NET_CONN_API_H
18 
19 /**
20  * @addtogroup NetConnection
21  * @{
22  *
23  * @brief Provide C interface for the data network connection module of network management.
24  *
25  * @since 11
26  * @version 1.0
27  */
28 
29 /**
30  * @file net_connection.h
31  *
32  * @brief Provide C interface for the data network connection module of network management.
33  *
34  * @syscap SystemCapability.Communication.NetManager.Core
35  * @library libnet_connection.so
36  * @since 11
37  * @version 1.0
38  */
39 
40 #include <netdb.h>
41 
42 #include "net_connection_type.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @brief Checks whether a default activated data network is available.
50  *
51  * @param hasDefaultNet Pointer to the result that specifies whether a default activated data network is available.
52  * @return 0 - Success. 201 - Missing permissions.
53  *         401 - Parameter error. 2100002 - Unable to connect to service.
54  *         2100003 - Internal error.
55  * @permission ohos.permission.GET_NETWORK_INFO
56  * @syscap SystemCapability.Communication.NetManager.Core
57  * @since 11
58  * @version 1.0
59  */
60 int32_t OH_NetConn_HasDefaultNet(int32_t *hasDefaultNet);
61 
62 /**
63  * @brief Obtains the default activated data network.
64  *
65  * @param netHandle Pointer to the network handle that contains the network ID.
66  * @return 0 - Success. 201 - Missing permissions.
67  *         401 - Parameter error. 2100002 - Unable to connect to service.
68  *         2100003 - Internal error.
69  * @permission ohos.permission.GET_NETWORK_INFO
70  * @syscap SystemCapability.Communication.NetManager.Core
71  * @since 11
72  * @version 1.0
73  */
74 int32_t OH_NetConn_GetDefaultNet(NetConn_NetHandle *netHandle);
75 
76 /**
77  * @brief Checks whether metering is enabled for the default data network.
78  *
79  * @param isMetered Pointer to the result that specifies whether metering is enabled.
80  * @return 0 - Success. 201 - Missing permissions.
81  *         401 - Parameter error. 2100002 - Unable to connect to service.
82  *         2100003 - Internal error.
83  * @permission ohos.permission.GET_NETWORK_INFO
84  * @syscap SystemCapability.Communication.NetManager.Core
85  * @since 11
86  * @version 1.0
87  */
88 int32_t OH_NetConn_IsDefaultNetMetered(int32_t *isMetered);
89 
90 /**
91  * @brief Obtains the connection properties of a data network.
92  *
93  * @param netHandle Pointer to the network handle that contains the network ID.
94  * @param prop Pointer to the connection properties.
95  * @return 0 - Success. 201 - Missing permissions.
96  *         401 - Parameter error. 2100002 - Unable to connect to service.
97  *         2100003 - Internal error.
98  * @permission ohos.permission.GET_NETWORK_INFO
99  * @syscap SystemCapability.Communication.NetManager.Core
100  * @since 11
101  * @version 1.0
102  */
103 int32_t OH_NetConn_GetConnectionProperties(NetConn_NetHandle *netHandle, NetConn_ConnectionProperties *prop);
104 
105 /**
106  * @brief Obtains the capabilities of a data network.
107  *
108  * @param netHandle Pointer to the network handle that contains the network ID.
109  * @param netCapacities Pointer to the network capabilities.
110  * @return 0 - Success. 201 - Missing permissions.
111  *         401 - Parameter error. 2100002 - Unable to connect to service.
112  *         2100003 - Internal error.
113  * @permission ohos.permission.GET_NETWORK_INFO
114  * @syscap SystemCapability.Communication.NetManager.Core
115  * @since 11
116  * @version 1.0
117  */
118 int32_t OH_NetConn_GetNetCapabilities(NetConn_NetHandle *netHandle, NetConn_NetCapabilities *netCapabilities);
119 
120 /**
121  * @brief Obtains the default http proxy.
122  *
123  * @param httpProxy Pointer to the HTTP proxy.
124  * @return 0 - Success. 201 - Missing permissions.
125  *         401 - Parameter error. 2100002 - Unable to connect to service.
126  *         2100003 - Internal error.
127  * @syscap SystemCapability.Communication.NetManager.Core
128  * @since 11
129  * @version 1.0
130  */
131 int32_t OH_NetConn_GetDefaultHttpProxy(NetConn_HttpProxy *httpProxy);
132 
133 /**
134  * @brief Get DNS result with netId.
135  *
136  * @param host The host name to query.
137  * @param serv Service name.
138  * @param hint Pointer to the addrinfo structure.
139  * @param res Store DNS query results and return them in a linked list format.
140  * @param netId DNS query netId, 0 is used for default netid query.
141  * @return 0 - Success. 201 - Missing permissions.
142  *         401 - Parameter error. 2100002 - Unable to connect to service.
143  *         2100003 - Internal error.
144  * @permission ohos.permission.INTERNET
145  * @syscap SystemCapability.Communication.NetManager.Core
146  * @since 11
147  * @version 1.0
148  */
149 int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId);
150 
151 /**
152  * @brief Free DNS result.
153  *
154  * @param res DNS query result chain header.
155  * @return 0 - Success. 201 - Missing permissions.
156  *         401 - Parameter error. 2100002 - Unable to connect to service.
157  *         2100003 - Internal error.
158  * @permission ohos.permission.INTERNET
159  * @syscap SystemCapability.Communication.NetManager.Core
160  * @since 11
161  * @version 1.0
162  */
163 int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res);
164 
165 /**
166  * @brief Queries all activated data networks.
167  *
168  * @param netHandleList Network handle that stores the network ID list.
169  * @return 0 - Success. 201 - Missing permissions.
170  *         401 - Parameter error. 2100002 - Unable to connect to service.
171  *         2100003 - Internal error.
172  * @permission ohos.permission.GET_NETWORK_INFO
173  * @syscap SystemCapability.Communication.NetManager.Core
174  * @since 11
175  * @version 1.0
176  */
177 int32_t OH_NetConn_GetAllNets(NetConn_NetHandleList *netHandleList);
178 
179 /**
180  * @brief Registers a custom DNS resolver.
181  *
182  * @param resolver Pointer to the custom DNS resolver.
183  * @return 0 - Success. 201 - Missing permissions.
184  *         401 - Parameter error. 2100002 - Unable to connect to service.
185  *         2100003 - Internal error.
186  * @permission ohos.permission.INTERNET
187  * @syscap SystemCapability.Communication.NetManager.Core
188  * @since 11
189  * @version 1.0
190  */
191 int32_t OHOS_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver);
192 
193 /**
194  * @brief Unregisters a custom DNS resolver.
195  *
196  * @return 0 - Success. 201 - Missing permissions.
197  *         401 - Parameter error. 2100002 - Unable to connect to service.
198  *         2100003 - Internal error.
199  * @permission ohos.permission.INTERNET
200  * @syscap SystemCapability.Communication.NetManager.Core
201  * @since 11
202  * @version 1.0
203  */
204 int32_t OHOS_NetConn_UnregisterDnsResolver(void);
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 /** @} */
211 #endif /* NATIVE_NET_CONN_API_H */