1 /* 2 * Copyright (c) 2023-2024 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 * @kit NetworkKit 35 * @syscap SystemCapability.Communication.NetManager.Core 36 * @library libnet_connection.so 37 * @since 11 38 * @version 1.0 39 */ 40 41 #include <netdb.h> 42 43 #include "net_all_capabilities.h" 44 #include "net_connection_type.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Checks whether a default activated data network is available. 52 * 53 * @param hasDefaultNet Pointer to the result that specifies whether a default activated data network is available. 54 * @return 0 - Success. 201 - Missing permissions. 55 * 401 - Parameter error. 2100002 - Unable to connect to service. 56 * 2100003 - Internal error. 57 * @permission ohos.permission.GET_NETWORK_INFO 58 * @syscap SystemCapability.Communication.NetManager.Core 59 * @since 11 60 * @version 1.0 61 */ 62 int32_t OH_NetConn_HasDefaultNet(int32_t *hasDefaultNet); 63 64 /** 65 * @brief Obtains the default activated data network. 66 * 67 * @param netHandle Pointer to the network handle that contains the network ID. 68 * @return 0 - Success. 201 - Missing permissions. 69 * 401 - Parameter error. 2100002 - Unable to connect to service. 70 * 2100003 - Internal error. 71 * @permission ohos.permission.GET_NETWORK_INFO 72 * @syscap SystemCapability.Communication.NetManager.Core 73 * @since 11 74 * @version 1.0 75 */ 76 int32_t OH_NetConn_GetDefaultNet(NetConn_NetHandle *netHandle); 77 78 /** 79 * @brief Checks whether metering is enabled for the default data network. 80 * 81 * @param isMetered Pointer to the result that specifies whether metering is enabled. 82 * @return 0 - Success. 201 - Missing permissions. 83 * 401 - Parameter error. 2100002 - Unable to connect to service. 84 * 2100003 - Internal error. 85 * @permission ohos.permission.GET_NETWORK_INFO 86 * @syscap SystemCapability.Communication.NetManager.Core 87 * @since 11 88 * @version 1.0 89 */ 90 int32_t OH_NetConn_IsDefaultNetMetered(int32_t *isMetered); 91 92 /** 93 * @brief Obtains the connection properties of a data network. 94 * 95 * @param netHandle Pointer to the network handle that contains the network ID. 96 * @param prop Pointer to the connection properties. 97 * @return 0 - Success. 201 - Missing permissions. 98 * 401 - Parameter error. 2100002 - Unable to connect to service. 99 * 2100003 - Internal error. 100 * @permission ohos.permission.GET_NETWORK_INFO 101 * @syscap SystemCapability.Communication.NetManager.Core 102 * @since 11 103 * @version 1.0 104 */ 105 int32_t OH_NetConn_GetConnectionProperties(NetConn_NetHandle *netHandle, NetConn_ConnectionProperties *prop); 106 107 /** 108 * @brief Obtains the capabilities of a data network. 109 * 110 * @param netHandle Pointer to the network handle that contains the network ID. 111 * @param netCapacities Pointer to the network capabilities. 112 * @return 0 - Success. 201 - Missing permissions. 113 * 401 - Parameter error. 2100002 - Unable to connect to service. 114 * 2100003 - Internal error. 115 * @permission ohos.permission.GET_NETWORK_INFO 116 * @syscap SystemCapability.Communication.NetManager.Core 117 * @since 11 118 * @version 1.0 119 */ 120 int32_t OH_NetConn_GetNetCapabilities(NetConn_NetHandle *netHandle, NetConn_NetCapabilities *netCapabilities); 121 122 /** 123 * @brief Obtains the default http proxy. 124 * 125 * @param httpProxy Pointer to the HTTP proxy. 126 * @return 0 - Success. 201 - Missing permissions. 127 * 401 - Parameter error. 2100002 - Unable to connect to service. 128 * 2100003 - Internal error. 129 * @syscap SystemCapability.Communication.NetManager.Core 130 * @since 11 131 * @version 1.0 132 */ 133 int32_t OH_NetConn_GetDefaultHttpProxy(NetConn_HttpProxy *httpProxy); 134 135 /** 136 * @brief Get DNS result with netId. 137 * 138 * @param host The host name to query. 139 * @param serv Service name. 140 * @param hint Pointer to the addrinfo structure. 141 * @param res Store DNS query results and return them in a linked list format. 142 * @param netId DNS query netId, 0 is used for default netid query. 143 * @return 0 - Success. 201 - Missing permissions. 144 * 401 - Parameter error. 2100002 - Unable to connect to service. 145 * 2100003 - Internal error. 146 * @permission ohos.permission.INTERNET 147 * @syscap SystemCapability.Communication.NetManager.Core 148 * @since 11 149 * @version 1.0 150 */ 151 int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId); 152 153 /** 154 * @brief Free DNS result. 155 * 156 * @param res DNS query result chain header. 157 * @return 0 - Success. 201 - Missing permissions. 158 * 401 - Parameter error. 2100002 - Unable to connect to service. 159 * 2100003 - Internal error. 160 * @permission ohos.permission.INTERNET 161 * @syscap SystemCapability.Communication.NetManager.Core 162 * @since 11 163 * @version 1.0 164 */ 165 int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res); 166 167 /** 168 * @brief Queries all activated data networks. 169 * 170 * @param netHandleList Network handle that stores the network ID list. 171 * @return 0 - Success. 201 - Missing permissions. 172 * 401 - Parameter error. 2100002 - Unable to connect to service. 173 * 2100003 - Internal error. 174 * @permission ohos.permission.GET_NETWORK_INFO 175 * @syscap SystemCapability.Communication.NetManager.Core 176 * @since 11 177 * @version 1.0 178 */ 179 int32_t OH_NetConn_GetAllNets(NetConn_NetHandleList *netHandleList); 180 181 /** 182 * @brief Registers a custom DNS resolver. 183 * 184 * @param resolver Pointer to the custom DNS resolver. 185 * @return 0 - Success. 201 - Missing permissions. 186 * 401 - Parameter error. 2100002 - Unable to connect to service. 187 * 2100003 - Internal error. 188 * @permission ohos.permission.INTERNET 189 * @syscap SystemCapability.Communication.NetManager.Core 190 * @deprecated since 13 191 * @useinstead OH_NetConn_RegisterDnsResolver 192 * @since 11 193 * @version 1.0 194 */ 195 int32_t OHOS_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver); 196 197 /** 198 * @brief Unregisters a custom DNS resolver. 199 * 200 * @return 0 - Success. 201 - Missing permissions. 201 * 401 - Parameter error. 2100002 - Unable to connect to service. 202 * 2100003 - Internal error. 203 * @permission ohos.permission.INTERNET 204 * @syscap SystemCapability.Communication.NetManager.Core 205 * @deprecated since 13 206 * @useinstead OH_NetConn_UnregisterDnsResolver 207 * @since 11 208 * @version 1.0 209 */ 210 int32_t OHOS_NetConn_UnregisterDnsResolver(void); 211 212 /** 213 * @brief Registers a custom DNS resolver. 214 * 215 * @param resolver Pointer to the custom DNS resolver. 216 * @return Returns the result code. 217 * {@link NETMANAGER_EXT_SUCCESS} if the operation is successful. 218 * {@link NETMANAGER_ERR_PERMISSION_DENIED} Missing permissions, add permission. 219 * {@link NETMANAGER_ERR_PARAMETER_ERROR} Parameter error. Please enter a correct parameter. 220 * @permission ohos.permission.INTERNET 221 * @syscap SystemCapability.Communication.NetManager.Core 222 * @since 13 223 * @version 1.0 224 */ 225 int32_t OH_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver); 226 227 /** 228 * @brief Unregisters a custom DNS resolver. 229 * 230 * @return 0 - Success. 201 - Missing permissions. 231 * 401 - Parameter error. 2100002 - Unable to connect to service. 232 * 2100003 - Internal error. 233 * @permission ohos.permission.INTERNET 234 * @syscap SystemCapability.Communication.NetManager.Core 235 * @since 13 236 * @version 1.0 237 */ 238 int32_t OH_NetConn_UnregisterDnsResolver(void); 239 240 /** 241 * @brief Binds a socket to the specific network. 242 * 243 * @param socketFd Socket constructed by user. 244 * @param netHandle Pointer to the network handle that contains the network ID. 245 * @return 0 - Success. 246 * 401 - Parameter error. 247 * 2100002 - Unable to connect to service. 248 * 2100003 - Internal error. 249 * @syscap SystemCapability.Communication.NetManager.Core 250 * @since 12 251 * @version 1.0 252 */ 253 int32_t OH_NetConn_BindSocket(int32_t socketFd, NetConn_NetHandle *netHandle); 254 255 int32_t OH_NetConn_RegisterNetConnCallback(NetConn_NetSpecifier *specifier, NetConn_NetConnCallback *netConnCallback, 256 uint32_t timeout, uint32_t *callbackId); 257 258 int32_t OH_NetConn_RegisterDefaultNetConnCallback(NetConn_NetConnCallback *netConnCallback, uint32_t *callbackId); 259 260 int32_t OH_NetConn_UnregisterNetConnCallback(uint32_t callBackId); 261 262 int32_t OH_NetConn_SetAppHttpProxy(NetConn_HttpProxy *httpProxy); 263 264 int32_t OH_NetConn_RegisterAppHttpProxyCallback(OH_NetConn_AppHttpProxyChange appHttpProxyChange, uint32_t *callbackId); 265 266 void OH_NetConn_UnregisterAppHttpProxyCallback(uint32_t callbackId); 267 268 int32_t OH_NetConn_SetPacUrl(const char *pacUrl); 269 270 int32_t OH_NetConn_GetPacUrl(char *pacUrl); 271 272 int32_t OH_NetConn_QueryProbeResult(const char *destination, int32_t duration, struct NetConn_ProbeResultInfo *result); 273 274 int32_t OH_NetConn_QueryTraceRoute( 275 const char *destination, NetConn_TraceRouteOption *option, NetConn_TraceRouteInfo *traceRouteInfo); 276 277 int32_t OH_NetConn_SetPacFileUrl(const char *pacUrl); 278 279 int32_t OH_NetConn_SetProxyMode(const OHOS::NetManagerStandard::ProxyModeType mode); 280 281 int32_t OH_NetConn_GetProxyMode(OHOS::NetManagerStandard::ProxyModeType *mode); 282 283 int32_t OH_NetConn_GetPacFileUrl(char *pacUrl); 284 285 int32_t OH_NetConn_FindProxyForURL(const char *url, const char *host, char *proxy); 286 287 #ifdef __cplusplus 288 } 289 #endif 290 291 /** @} */ 292 #endif /* NATIVE_NET_CONN_API_H */ 293