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 #include <netdb.h>
17
18 #include "net_probe.h"
19 #include "net_connection.h"
20 #include "net_conn_client.h"
21 #include "net_connection_adapter.h"
22 #include "net_connection_type.h"
23 #include "net_manager_constants.h"
24 #include "net_mgr_log_wrapper.h"
25
26 using namespace OHOS::NetManagerStandard;
27
28 constexpr int32_t VALID_NETID_START = 100;
29 constexpr int32_t PAC_URL_MAX_LEN = 1024;
30
ErrorCodeTrans(int status)31 static int32_t ErrorCodeTrans(int status)
32 {
33 int32_t ret;
34 switch (status) {
35 case EAI_BADFLAGS:
36 if (errno == EPERM || errno == EACCES) {
37 ret = NETMANAGER_ERR_PERMISSION_DENIED;
38 } else {
39 ret = NETMANAGER_ERR_PARAMETER_ERROR;
40 }
41 break;
42 case EAI_SERVICE:
43 ret = NETMANAGER_ERR_OPERATION_FAILED;
44 break;
45 default:
46 ret = NETMANAGER_ERR_INTERNAL;
47 break;
48 }
49 return ret;
50 }
51
OH_NetConn_GetAddrInfo(char * host,char * serv,struct addrinfo * hint,struct addrinfo ** res,int32_t netId)52 int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId)
53 {
54 int32_t ret = NETMANAGER_SUCCESS;
55 int status = 0;
56 struct queryparam qp_param;
57 if (host == nullptr || res == nullptr) {
58 NETMGR_LOG_E("OH_NetConn_GetAddrInfo received invalid parameters");
59 return NETMANAGER_ERR_PARAMETER_ERROR;
60 }
61
62 if (strlen(host) == 0) {
63 NETMGR_LOG_E("OH_NetConn_GetAddrInfo received invalid host");
64 return NETMANAGER_ERR_PARAMETER_ERROR;
65 }
66
67 if (netId > 0 && netId < VALID_NETID_START) {
68 NETMGR_LOG_E("OH_NetConn_GetAddrInfo received invalid netId");
69 return NETMANAGER_ERR_PARAMETER_ERROR;
70 }
71
72 if (memset_s(&qp_param, sizeof(struct queryparam), 0, sizeof(struct queryparam)) != EOK) {
73 NETMGR_LOG_E("OH_NetConn_GetAddrInfo memset_s failed!");
74 return NETMANAGER_ERR_MEMSET_FAIL;
75 }
76 qp_param.qp_netid = netId;
77 qp_param.qp_type = 0;
78
79 status = getaddrinfo_ext(host, serv, hint, res, &qp_param);
80 if (status < 0) {
81 NETMGR_LOG_E("OH_NetConn_GetAddrInfo fail status:%{public}d", status);
82 ret = ErrorCodeTrans(status);
83 }
84
85 return ret;
86 }
87
OH_NetConn_FreeDnsResult(struct addrinfo * res)88 int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res)
89 {
90 if (res == nullptr) {
91 NETMGR_LOG_E("OH_NetConn_FreeDnsResult received invalid parameters");
92 return NETMANAGER_ERR_PARAMETER_ERROR;
93 }
94
95 freeaddrinfo(res);
96
97 return NETMANAGER_SUCCESS;
98 }
99
OH_NetConn_GetAllNets(NetConn_NetHandleList * netHandleList)100 int32_t OH_NetConn_GetAllNets(NetConn_NetHandleList *netHandleList)
101 {
102 if (netHandleList == nullptr) {
103 NETMGR_LOG_E("OH_NetConn_GetAllNets received invalid parameters");
104 return NETMANAGER_ERR_PARAMETER_ERROR;
105 }
106
107 std::list<OHOS::sptr<NetHandle>> netHandleObjList;
108 int32_t ret = NetConnClient::GetInstance().GetAllNets(netHandleObjList);
109 int32_t retConv = Conv2NetHandleList(netHandleObjList, netHandleList);
110 if (retConv != NETMANAGER_SUCCESS) {
111 return retConv;
112 }
113 return ret;
114 }
115
OH_NetConn_HasDefaultNet(int32_t * hasDefaultNet)116 int32_t OH_NetConn_HasDefaultNet(int32_t *hasDefaultNet)
117 {
118 if (hasDefaultNet == nullptr) {
119 NETMGR_LOG_E("OH_NetConn_HasDefaultNet received invalid parameters");
120 return NETMANAGER_ERR_PARAMETER_ERROR;
121 }
122
123 bool flagBool = false;
124 int32_t ret = NetConnClient::GetInstance().HasDefaultNet(flagBool);
125 *hasDefaultNet = flagBool;
126 return ret;
127 }
128
OH_NetConn_GetDefaultNet(NetConn_NetHandle * netHandle)129 int32_t OH_NetConn_GetDefaultNet(NetConn_NetHandle *netHandle)
130 {
131 if (netHandle == nullptr) {
132 NETMGR_LOG_E("OH_NetConn_GetDefaultNet received invalid parameters");
133 return NETMANAGER_ERR_PARAMETER_ERROR;
134 }
135
136 NetHandle netHandleObj = NetHandle();
137 int32_t ret = NetConnClient::GetInstance().GetDefaultNet(netHandleObj);
138 int32_t retConv = Conv2NetHandle(netHandleObj, netHandle);
139 if (retConv != NETMANAGER_SUCCESS) {
140 return retConv;
141 }
142 return ret;
143 }
144
OH_NetConn_IsDefaultNetMetered(int32_t * isMetered)145 int32_t OH_NetConn_IsDefaultNetMetered(int32_t *isMetered)
146 {
147 if (isMetered == nullptr) {
148 NETMGR_LOG_E("OH_NetConn_IsDefaultNetMetered received invalid parameters");
149 return NETMANAGER_ERR_PARAMETER_ERROR;
150 }
151
152 bool flagBool = false;
153 int32_t ret = NetConnClient::GetInstance().IsDefaultNetMetered(flagBool);
154 *isMetered = flagBool;
155 return ret;
156 }
157
OH_NetConn_GetConnectionProperties(NetConn_NetHandle * netHandle,NetConn_ConnectionProperties * prop)158 int32_t OH_NetConn_GetConnectionProperties(NetConn_NetHandle *netHandle, NetConn_ConnectionProperties *prop)
159 {
160 if (netHandle == nullptr || prop == nullptr) {
161 NETMGR_LOG_E("OH_NetConn_GetConnectionProperties received invalid parameters");
162 return NETMANAGER_ERR_PARAMETER_ERROR;
163 }
164
165 NetHandle netHandleObj = NetHandle();
166 int32_t retConv = Conv2NetHandleObj(netHandle, netHandleObj);
167 if (retConv != NETMANAGER_SUCCESS) {
168 return retConv;
169 }
170 NetLinkInfo infoObj = NetLinkInfo();
171 int32_t ret = NetConnClient::GetInstance().GetConnectionProperties(netHandleObj, infoObj);
172 retConv = Conv2NetLinkInfo(infoObj, prop);
173 if (retConv != NETMANAGER_SUCCESS) {
174 return retConv;
175 }
176 return ret;
177 }
178
OH_NetConn_GetNetCapabilities(NetConn_NetHandle * netHandle,NetConn_NetCapabilities * netAllCapabilities)179 int32_t OH_NetConn_GetNetCapabilities(NetConn_NetHandle *netHandle, NetConn_NetCapabilities *netAllCapabilities)
180 {
181 if (netHandle == nullptr || netAllCapabilities == nullptr) {
182 NETMGR_LOG_E("OH_NetConn_GetNetCapabilities received invalid parameters");
183 return NETMANAGER_ERR_PARAMETER_ERROR;
184 }
185
186 NetHandle netHandleObj = NetHandle();
187 int32_t retConv = Conv2NetHandleObj(netHandle, netHandleObj);
188 if (retConv != NETMANAGER_SUCCESS) {
189 return retConv;
190 }
191 NetAllCapabilities netAllCapsObj = NetAllCapabilities();
192 int32_t ret = NetConnClient::GetInstance().GetNetCapabilities(netHandleObj, netAllCapsObj);
193 retConv = Conv2NetAllCapabilities(netAllCapsObj, netAllCapabilities);
194 if (retConv != NETMANAGER_SUCCESS) {
195 return retConv;
196 }
197 return ret;
198 }
199
OH_NetConn_GetDefaultHttpProxy(NetConn_HttpProxy * httpProxy)200 int32_t OH_NetConn_GetDefaultHttpProxy(NetConn_HttpProxy *httpProxy)
201 {
202 if (httpProxy == nullptr) {
203 NETMGR_LOG_E("OH_NetConn_GetDefaultHttpProxy received invalid parameters");
204 return NETMANAGER_ERR_PARAMETER_ERROR;
205 }
206
207 HttpProxy httpProxyObj = HttpProxy();
208 int32_t ret = NetConnClient::GetInstance().GetDefaultHttpProxy(httpProxyObj);
209 int32_t retConv = Conv2HttpProxy(httpProxyObj, httpProxy);
210 if (retConv != NETMANAGER_SUCCESS) {
211 return retConv;
212 }
213 return ret;
214 }
215
OHOS_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver)216 int32_t OHOS_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver)
217 {
218 if (resolver == nullptr) {
219 NETMGR_LOG_E("OHOS_NetConn_RegisterDnsResolver received invalid parameters");
220 return NETMANAGER_ERR_PARAMETER_ERROR;
221 }
222
223 int32_t ret = setdnsresolvehook(resolver);
224 if (ret < 0) {
225 ret = NETMANAGER_ERR_PARAMETER_ERROR;
226 }
227 return ret;
228 }
229
OHOS_NetConn_UnregisterDnsResolver()230 int32_t OHOS_NetConn_UnregisterDnsResolver()
231 {
232 int32_t ret = removednsresolvehook();
233 return ret;
234 }
235
OH_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver)236 int32_t OH_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver)
237 {
238 if (resolver == nullptr) {
239 NETMGR_LOG_E("OH_NetConn_RegisterDnsResolver received invalid parameters");
240 return NETMANAGER_ERR_PARAMETER_ERROR;
241 }
242
243 int32_t ret = setdnsresolvehook(resolver);
244 if (ret < 0) {
245 ret = NETMANAGER_ERR_PARAMETER_ERROR;
246 }
247 return ret;
248 }
249
OH_NetConn_UnregisterDnsResolver()250 int32_t OH_NetConn_UnregisterDnsResolver()
251 {
252 int32_t ret = removednsresolvehook();
253 return ret;
254 }
255
OH_NetConn_BindSocket(int32_t socketFd,NetConn_NetHandle * netHandle)256 int32_t OH_NetConn_BindSocket(int32_t socketFd, NetConn_NetHandle *netHandle)
257 {
258 if (netHandle == nullptr) {
259 NETMGR_LOG_E("OH_NetConn_BindSocket netHandle is NULL");
260 return NETMANAGER_ERR_PARAMETER_ERROR;
261 }
262 if (socketFd < 0) {
263 NETMGR_LOG_E("OH_NetConn_BindSocket socketFd is invalid");
264 return NETMANAGER_ERR_PARAMETER_ERROR;
265 }
266 if (netHandle->netId < VALID_NETID_START) {
267 NETMGR_LOG_E("OH_NetConn_BindSocket netId is invalid");
268 return NETMANAGER_ERR_PARAMETER_ERROR;
269 }
270
271 int32_t ret = NetConnClient::GetInstance().BindSocket(socketFd, netHandle->netId);
272 return ret;
273 }
274
RegisterErrorCodeTrans(int32_t err)275 static int32_t RegisterErrorCodeTrans(int32_t err)
276 {
277 switch (err) {
278 case NETMANAGER_SUCCESS: // fall through
279 case NETMANAGER_ERR_PERMISSION_DENIED: // fall through
280 case NETMANAGER_ERR_PARAMETER_ERROR: // fall through
281 case NETMANAGER_ERR_OPERATION_FAILED: // fall through
282 case NET_CONN_ERR_CALLBACK_NOT_FOUND: // fall through
283 case NET_CONN_ERR_SAME_CALLBACK: // fall through
284 case NET_CONN_ERR_NET_OVER_MAX_REQUEST_NUM:
285 return err;
286 default:
287 return NETMANAGER_ERR_INTERNAL;
288 }
289 }
290
OH_NetConn_RegisterNetConnCallback(NetConn_NetSpecifier * specifier,NetConn_NetConnCallback * netConnCallback,uint32_t timeout,uint32_t * callbackId)291 int32_t OH_NetConn_RegisterNetConnCallback(NetConn_NetSpecifier *specifier, NetConn_NetConnCallback *netConnCallback,
292 uint32_t timeout, uint32_t *callbackId)
293 {
294 if (specifier == nullptr) {
295 NETMGR_LOG_E("OH_NetConn_RegisterNetConnCallback specifier is NULL");
296 return NETMANAGER_ERR_PARAMETER_ERROR;
297 }
298
299 if (netConnCallback == nullptr) {
300 NETMGR_LOG_E("OH_NetConn_RegisterNetConnCallback netConnCallback is NULL");
301 return NETMANAGER_ERR_PARAMETER_ERROR;
302 }
303 if (callbackId == nullptr) {
304 NETMGR_LOG_E("OH_NetConn_RegisterNetConnCallback callbackId is NULL");
305 return NETMANAGER_ERR_PARAMETER_ERROR;
306 }
307
308 int32_t ret = NetConnCallbackManager::GetInstance().RegisterNetConnCallback(specifier, netConnCallback, timeout,
309 callbackId);
310 return RegisterErrorCodeTrans(ret);
311 }
312
OH_NetConn_RegisterDefaultNetConnCallback(NetConn_NetConnCallback * netConnCallback,uint32_t * callbackId)313 int32_t OH_NetConn_RegisterDefaultNetConnCallback(NetConn_NetConnCallback *netConnCallback, uint32_t *callbackId)
314 {
315 if (netConnCallback == nullptr) {
316 NETMGR_LOG_E("OH_NetConn_RegisterNetConnCallback netConnCallback is NULL");
317 return NETMANAGER_ERR_PARAMETER_ERROR;
318 }
319 if (callbackId == nullptr) {
320 NETMGR_LOG_E("OH_NetConn_RegisterNetConnCallback callbackId is NULL");
321 return NETMANAGER_ERR_PARAMETER_ERROR;
322 }
323 int32_t ret = NetConnCallbackManager::GetInstance().RegisterNetConnCallback(nullptr, netConnCallback, 0,
324 callbackId);
325 return RegisterErrorCodeTrans(ret);
326 }
327
OH_NetConn_UnregisterNetConnCallback(uint32_t callBackId)328 int32_t OH_NetConn_UnregisterNetConnCallback(uint32_t callBackId)
329 {
330 int32_t ret = NetConnCallbackManager::GetInstance().UnregisterNetConnCallback(callBackId);
331 return RegisterErrorCodeTrans(ret);
332 }
333
OH_NetConn_SetAppHttpProxy(NetConn_HttpProxy * httpProxy)334 int32_t OH_NetConn_SetAppHttpProxy(NetConn_HttpProxy *httpProxy)
335 {
336 if (httpProxy == nullptr) {
337 NETMGR_LOG_E("OH_NetConn_SetAppHttpProxy received invalid parameters");
338 return NETMANAGER_ERR_PARAMETER_ERROR;
339 }
340 HttpProxy httpProxyObj;
341 ConvertNetConn2HttpProxy(*httpProxy, httpProxyObj);
342 int32_t ret = NetConnClient::GetInstance().SetAppHttpProxy(httpProxyObj);
343 return ret;
344 }
345
OH_NetConn_RegisterAppHttpProxyCallback(OH_NetConn_AppHttpProxyChange appHttpProxyChange,uint32_t * callbackId)346 int32_t OH_NetConn_RegisterAppHttpProxyCallback(OH_NetConn_AppHttpProxyChange appHttpProxyChange, uint32_t *callbackId)
347 {
348 if (appHttpProxyChange == nullptr) {
349 NETMGR_LOG_E("OH_NetConn_RegisterAppHttpProxyCallback received invalid parameters");
350 return NETMANAGER_ERR_PARAMETER_ERROR;
351 }
352 if (callbackId == nullptr) {
353 NETMGR_LOG_E("OH_NetConn_RegisterAppHttpProxyCallback received invalid parameters");
354 return NETMANAGER_ERR_PARAMETER_ERROR;
355 }
356 auto opration = [appHttpProxyChange](const HttpProxy& httpProxy) {
357 NetConn_HttpProxy netHttpProxy;
358 int32_t retConv = Conv2HttpProxy(httpProxy, &netHttpProxy);
359 if (retConv != NETMANAGER_SUCCESS) {
360 appHttpProxyChange(nullptr);
361 } else {
362 appHttpProxyChange(&netHttpProxy);
363 }
364 };
365 uint32_t id;
366 NetConnClient::GetInstance().RegisterAppHttpProxyCallback(opration, id);
367 *callbackId = id;
368 return NETMANAGER_SUCCESS;
369 }
370
OH_NetConn_UnregisterAppHttpProxyCallback(uint32_t callbackId)371 void OH_NetConn_UnregisterAppHttpProxyCallback(uint32_t callbackId)
372 {
373 NetConnClient::GetInstance().UnregisterAppHttpProxyCallback(callbackId);
374 }
375
OH_NetConn_SetPacUrl(const char * pacUrl)376 int32_t OH_NetConn_SetPacUrl(const char *pacUrl)
377 {
378 if (pacUrl == nullptr) {
379 NETMGR_LOG_E("OH_NetConn_SetPacUrl received invalid parameters");
380 return NETMANAGER_ERR_PARAMETER_ERROR;
381 }
382 int32_t ret = NetConnClient::GetInstance().SetPacUrl(std::string(pacUrl));
383 return ret;
384 }
385
OH_NetConn_GetPacUrl(char * pacUrl)386 int32_t OH_NetConn_GetPacUrl(char *pacUrl)
387 {
388 if (pacUrl == nullptr) {
389 NETMGR_LOG_E("OH_NetConn_GetPacUrl received invalid parameters");
390 return NETMANAGER_ERR_PARAMETER_ERROR;
391 }
392 std::string pacUrlstr = "";
393 int32_t ret = NetConnClient::GetInstance().GetPacUrl(pacUrlstr);
394 if (strcpy_s(pacUrl, PAC_URL_MAX_LEN, pacUrlstr.c_str()) != 0) {
395 NETMGR_LOG_E("OH_NetConn_GetPacUrl string copy failed");
396 return NETMANAGER_ERR_INTERNAL;
397 }
398 return ret;
399 }
400
OH_NetConn_SetProxyMode(const OHOS::NetManagerStandard::ProxyModeType mode)401 int32_t OH_NetConn_SetProxyMode(const OHOS::NetManagerStandard::ProxyModeType mode)
402 {
403 int32_t ret = NetConnClient::GetInstance().SetProxyMode(mode);
404 return ret;
405 }
406
OH_NetConn_GetProxyMode(OHOS::NetManagerStandard::ProxyModeType * mode)407 int32_t OH_NetConn_GetProxyMode(OHOS::NetManagerStandard::ProxyModeType *mode)
408 {
409 if (mode == nullptr) {
410 NETMGR_LOG_E("OH_NetConn_GetProxyMode received invalid parameters");
411 return NETMANAGER_ERR_PARAMETER_ERROR;
412 }
413 OHOS::NetManagerStandard::ProxyModeType temp;
414 int32_t ret = NetConnClient::GetInstance().GetProxyMode(temp);
415 if (ret) {
416 NETMGR_LOG_E("OH_NetConn_GetProxyMode string copy failed");
417 return RegisterErrorCodeTrans(ret);
418 }
419 *mode = temp;
420 return ret;
421 }
422
OH_NetConn_SetPacFileUrl(const char * pacUrl)423 int32_t OH_NetConn_SetPacFileUrl(const char *pacUrl)
424 {
425 if (pacUrl == nullptr) {
426 NETMGR_LOG_E("OH_NetConn_SetPacUrl received invalid parameters");
427 return NETMANAGER_ERR_PARAMETER_ERROR;
428 }
429 int32_t ret = NetConnClient::GetInstance().SetPacFileUrl(std::string(pacUrl));
430 return ret;
431 }
432
OH_NetConn_GetPacFileUrl(char * pacUrl)433 int32_t OH_NetConn_GetPacFileUrl(char *pacUrl)
434 {
435 if (pacUrl == nullptr) {
436 NETMGR_LOG_E("OH_NetConn_GetPacUrl received invalid parameters");
437 return NETMANAGER_ERR_PARAMETER_ERROR;
438 }
439 std::string pacUrlstr = "";
440 int32_t ret = NetConnClient::GetInstance().GetPacFileUrl(pacUrlstr);
441 if (strcpy_s(pacUrl, PAC_URL_MAX_LEN, pacUrlstr.c_str()) != 0) {
442 NETMGR_LOG_E("OH_NetConn_GetPacUrl string copy failed");
443 return NETMANAGER_ERR_INTERNAL;
444 }
445 return ret;
446 }
447
OH_NetConn_FindProxyForURL(const char * url,const char * host,char * proxy)448 int32_t OH_NetConn_FindProxyForURL(const char *url, const char *host, char *proxy)
449 {
450 if (url == nullptr) {
451 NETMGR_LOG_E("OH_NetConn_GetPacUrl received invalid parameters");
452 return NETMANAGER_ERR_PARAMETER_ERROR;
453 }
454 std::string pacProxyStr = "";
455 std::string hostStr;
456 if (host && strlen(host) > 0) {
457 hostStr.append(host);
458 }
459 int32_t ret = NetConnClient::GetInstance().FindProxyForURL(url, pacProxyStr, hostStr);
460 if (strcpy_s(proxy, PAC_URL_MAX_LEN, pacProxyStr.c_str()) != 0) {
461 NETMGR_LOG_E("OH_NetConn_GetPacUrl string copy failed");
462 return NETMANAGER_ERR_INTERNAL;
463 }
464 return ret;
465 }
466
OH_NetConn_QueryProbeResult(const char * destination,int32_t duration,struct NetConn_ProbeResultInfo * result)467 int32_t OH_NetConn_QueryProbeResult(const char *destination, int32_t duration,
468 struct NetConn_ProbeResultInfo *result)
469 {
470 if (destination == nullptr || result == nullptr) {
471 NETMGR_LOG_E("OH_NetConn_QueryProbeResult received invalid parameters");
472 return NETMANAGER_ERR_PARAMETER_ERROR;
473 }
474
475 std::string dest(destination);
476 NetProbe np;
477 int ret = np.QueryProbeResult(dest, duration, *result);
478 if (ret != 0) {
479 NETMGR_LOG_E("Query probe result failed.");
480 }
481 return ret;
482 }
483
OH_NetConn_QueryTraceRoute(const char * destination,NetConn_TraceRouteOption * option,NetConn_TraceRouteInfo * traceRouteInfo)484 int32_t OH_NetConn_QueryTraceRoute(
485 const char *destination, NetConn_TraceRouteOption *option, NetConn_TraceRouteInfo *traceRouteInfo)
486 {
487 if (destination == nullptr || traceRouteInfo == nullptr) {
488 NETMGR_LOG_E("OH_NetConn_QueryTraceRoute received invalid parameters");
489 return NETMANAGER_ERR_PARAMETER_ERROR;
490 }
491 int32_t packetsType = NetConn_PacketsType::NETCONN_PACKETS_ICMP;
492 int32_t maxJumpNumber = NETCONN_MAX_JUMP_NUM;
493 if (option != nullptr) {
494 maxJumpNumber = static_cast<int32_t>(option->maxJumpNumber);
495 if (maxJumpNumber > NETCONN_MAX_JUMP_NUM) {
496 return NETMANAGER_ERR_PARAMETER_ERROR;
497 }
498 packetsType = static_cast<int32_t>(option->packetsType);
499 }
500 std::string traceRouteInfoStr = "";
501 int32_t ret = NetConnClient::GetInstance().QueryTraceRoute(std::string(destination), maxJumpNumber, packetsType,
502 traceRouteInfoStr);
503 if (ret != NETMANAGER_SUCCESS) {
504 NETMGR_LOG_E("OH_NetConn_QueryTraceRoute query failed with error code: %d", ret);
505 return ret;
506 }
507 if (Conv2TraceRouteInfo(traceRouteInfoStr, traceRouteInfo, maxJumpNumber) != NETMANAGER_SUCCESS) {
508 NETMGR_LOG_E("OH_NetConn_QueryTraceRoute conv2 routeinfo failed");
509 }
510 return ret;
511 }
512