1# NetConnection 2 3 4## Overview 5 6Provides the C APIs of the network connection module for network management. 7 8**Since**: 11 9 10 11## Summary 12 13 14### File 15 16| Name| Description| 17| -------- | -------- | 18| [net_connection.h](net__connection_8h.md) | Provides the C APIs of the network connection module for network management.| 19| [net_connection_type.h](net__connection__type_8h.md) | Declares the structs for the C APIs of the network connection module.| 20 21 22### Structs 23 24| Name| Description| 25| -------- | -------- | 26| [NetConn_NetHandle](_net_conn___net_handle.md) | Network ID.| 27| [NetConn_NetCapabilities](_net_conn___net_capabilities.md) | Network capability set.| 28| [NetConn_NetAddr](_net_conn___net_addr.md) | Network address.| 29| [NetConn_Route](_net_conn___route.md) | Route configuration.| 30| [NetConn_HttpProxy](_net_conn___http_proxy.md) | Proxy configuration.| 31| [NetConn_ConnectionProperties](_net_conn___connection_properties.md) | Network connection information.| 32| [NetConn_NetHandleList](_net_conn___net_handle_list.md) | Network list.| 33| [NetConn_NetConnCallback](_net_conn___net_conn_callback.md) | Defines network status callbacks.| 34| [NetConn_NetSpecifier](_net_conn___net_specifier.md) | Defines the network feature set, including a network capability set and a network ID.| 35 36 37### Macros 38 39| Name| Description| 40| -------- | -------- | 41| **NETCONN_MAX_NET_SIZE** | 32 | 42| **NETCONN_MAX_BEARER_TYPE_SIZE** | 32 | 43| **NETCONN_MAX_CAP_SIZE** | 32 | 44| **NETCONN_MAX_ADDR_SIZE** | 32 | 45| **NETCONN_MAX_ROUTE_SIZE** | 64 | 46| **NETCONN_MAX_EXCLUSION_SIZE** | 256 | 47| **NETCONN_MAX_STR_LEN** | 256 | 48 49 50### Types 51 52| Name| Description| 53| -------- | -------- | 54| [NetConn_NetCap](#netconn_netcap) | Network capability set.| 55| [NetConn_NetBearerType](#netconn_netbearertype) | Network carrier type.| 56| [NetConn_NetHandle](#netconn_nethandle) | Network ID.| 57| [NetConn_NetCapabilities](#netconn_netcapabilities) | Network capability set.| 58| [NetConn_NetAddr](#netconn_netaddr) | Network address.| 59| [NetConn_Route](#netconn_route) | Route configuration.| 60| [NetConn_HttpProxy](#netconn_httpproxy) | Proxy configuration.| 61| [NetConn_ConnectionProperties](#netconn_connectionproperties) | Network connection information.| 62| [NetConn_NetHandleList](#netconn_nethandlelist) | Network list.| 63| (\*[OH_NetConn_CustomDnsResolver](#oh_netconn_customdnsresolver)) (const char \*host, const char \*serv, const struct addrinfo \*hint, struct addrinfo \*\*res) | Pointer to the custom DNS resolver.| 64| [NetConn_NetConnCallback](#netconn_netconncallback) | Defines network status callbacks.| 65| [NetConn_NetSpecifier](#netconn_netspecifier) | Defines the network feature set, including a network capability set and a network ID.| 66 67### Enums 68 69| Name| Description| 70| -------- | -------- | 71| [NetConn_NetCap](#netconn_netcap) {<br>NETCONN_NET_CAPABILITY_MMS = 0,<br>NETCONN_NET_CAPABILITY_NOT_METERED = 11,<br>NETCONN_NET_CAPABILITY_INTERNET = 12,<br>NETCONN_NET_CAPABILITY_NOT_VPN = 15,<br>NETCONN_NET_CAPABILITY_VALIDATED = 16<br>} | Network capability set.| 72| [NetConn_NetBearerType](#netconn_netbearertype) {<br>NETCONN_BEARER_CELLULAR = 0,<br>NETCONN_BEARER_WIFI = 1,<br>NETCONN_BEARER_ETHERNET = 3<br>NETCONN_BEARER_VPN = 4<br>} | Network carrier type.| 73 74 75### Functions 76 77| Name| Description| 78| -------- | -------- | 79| [OH_NetConn_HasDefaultNet](#oh_netconn_hasdefaultnet) (int32_t \*hasDefaultNet) | Checks whether a default activated data network is available.| 80| [OH_NetConn_GetDefaultNet](#oh_netconn_getdefaultnet) ([NetConn_NetHandle](_net_conn___net_handle.md) \*netHandle) | Obtains the default activated data network.| 81| [OH_NetConn_IsDefaultNetMetered](#oh_netconn_isdefaultnetmetered) (int32_t \*isMetered) | Checks whether data traffic usage on the current network is metered.| 82| [OH_NetConn_GetConnectionProperties](#oh_netconn_getconnectionproperties) ([NetConn_NetHandle](_net_conn___net_handle.md) \*netHandle, [NetConn_ConnectionProperties](_net_conn___connection_properties.md) \*prop) | Obtains the link information of a data network.| 83| [OH_NetConn_GetNetCapabilities](#oh_netconn_getnetcapabilities) ([NetConn_NetHandle](_net_conn___net_handle.md) \*netHandle, [NetConn_NetCapabilities](_net_conn___net_capabilities.md) \*netCapacities) | Obtains the capabilities of a data network.| 84| [OH_NetConn_GetDefaultHttpProxy](#oh_netconn_getdefaulthttpproxy) ([NetConn_HttpProxy](_net_conn___http_proxy.md) \*httpProxy) | Obtains the default network proxy.| 85| [OH_NetConn_GetAddrInfo](#oh_netconn_getaddrinfo) (char \*host, char \*serv, struct addrinfo \*hint, struct addrinfo \*\*res, int32_t netId) | Obtains the DNS result using **netId**.| 86| [OH_NetConn_FreeDnsResult](#oh_netconn_freednsresult) (struct addrinfo \*res) | Releases the DNS query result.| 87| [OH_NetConn_GetAllNets](#oh_netconn_getallnets) ([NetConn_NetHandleList](_net_conn___net_handle_list.md) \*netHandleList) | Obtains all activated data networks.| 88| [OHOS_NetConn_RegisterDnsResolver](#ohos_netconn_registerdnsresolver) ([OH_NetConn_CustomDnsResolver](#oh_netconn_customdnsresolver) resolver) | Registers a custom DNS resolver.| 89| [OHOS_NetConn_UnregisterDnsResolver](#ohos_netconn_unregisterdnsresolver) (void) | Unregisters a custom DNS resolver.| 90| [OH_NetConn_BindSocket](#oh_netconn_bindsocket) (int32_t socketFd, [NetConn_NetHandle](_net_conn___net_handle.md) \*netHandle) | Binds a socket to the specified network.| 91| [OH_NetConn_SetAppHttpProxy](#oh_netconn_setapphttpproxy) ([NetConn_HttpProxy](_net_conn___http_proxy.md) \*httpProxy) | Sets the application-level HTTP proxy information.| 92| [OH_NetConn_RegisterAppHttpProxyCallback](#oh_netconn_registerapphttpproxycallback) ([OH_NetConn_AppHttpProxyChange](#oh_netconn_apphttpproxychange) appHttpProxyChange, uint32_t \*callbackId) | Registers a listener for application-level proxy changes.| 93| [OH_NetConn_UnregisterAppHttpProxyCallback](#oh_netconn_unregisterapphttpproxycallback) (uint32_t callbackId) | Unregisters the listener for application-level proxy changes.| 94| [OH_NetConn_RegisterNetConnCallback](#oh_netconn_registernetconncallback) ([NetConn_NetSpecifier](_net_conn___net_specifier.md) \*specifier, [NetConn_NetConnCallback](_net_conn___net_conn_callback.md) \*netConnCallback, uint32_t timeoutMS, uint32_t \*callbackId) | Registers a callback for network status changes.| 95| [OH_NetConn_RegisterDefaultNetConnCallback](#oh_netconn_registerdefaultnetconncallback) ([NetConn_NetConnCallback](_net_conn___net_conn_callback.md) \*netConnCallback, uint32_t \*callbackId) | Registers a callback for status changes of the default network.| 96| [OH_NetConn_UnregisterNetConnCallback](#oh_netconn_unregisternetconncallback) (uint32_t callbackId) | Unregisters the callback for network status changes.| 97 98 99## Type Description 100 101 102### NetConn_ConnectionProperties 103 104``` 105typedef struct NetConn_ConnectionProperties NetConn_ConnectionProperties 106``` 107 108**Description** 109 110Network connection information. 111 112**Since**: 11 113 114 115### NetConn_HttpProxy 116 117``` 118typedef struct NetConn_HttpProxy NetConn_HttpProxy 119``` 120 121**Description** 122 123Proxy configuration. 124 125**Since**: 11 126 127 128### NetConn_NetAddr 129 130``` 131typedef struct NetConn_NetAddr NetConn_NetAddr 132``` 133 134**Description** 135 136Network address. 137 138**Since**: 11 139 140 141### NetConn_NetBearerType 142 143``` 144typedef enum NetConn_NetBearerType NetConn_NetBearerType 145``` 146 147**Description** 148 149Network carrier type. 150 151**Since**: 11 152 153 154### NetConn_NetCap 155 156``` 157typedef enum NetConn_NetCap NetConn_NetCap 158``` 159 160**Description** 161 162Network capability set. 163 164**Since**: 11 165 166 167### NetConn_NetCapabilities 168 169``` 170typedef struct NetConn_NetCapabilities NetConn_NetCapabilities 171``` 172 173**Description** 174 175Network capability set. 176 177**Since**: 11 178 179 180### NetConn_NetHandle 181 182``` 183typedef struct NetConn_NetHandle NetConn_NetHandle 184``` 185 186**Description** 187 188Network ID. 189 190**Since**: 11 191 192 193### NetConn_NetHandleList 194 195``` 196typedef struct NetConn_NetHandleList NetConn_NetHandleList 197``` 198 199**Description** 200 201Network list. 202 203**Since**: 11 204 205 206### NetConn_Route 207 208``` 209typedef struct NetConn_Route NetConn_Route 210``` 211 212**Description** 213 214Route configuration. 215 216**Since**: 11 217 218 219### OH_NetConn_CustomDnsResolver 220 221``` 222typedef int(* OH_NetConn_CustomDnsResolver) (const char *host, const char *serv, const struct addrinfo *hint, struct addrinfo **res) 223``` 224 225**Description** 226 227Pointer to the custom DNS resolver. 228 229**Since**: 11 230 231**Parameters** 232 233| Name| Description| 234| -------- | -------- | 235| host | Host name.| 236| serv | Service name.| 237| hint | Pointer to the addrinfo structure.| 238| res | DNS query result, which is in the format of linked lists.| 239 240 241### OH_NetConn_AppHttpProxyChange 242 243``` 244typedef void(* OH_NetConn_AppHttpProxyChange) (NetConn_HttpProxy *proxy) 245``` 246 247**Description** 248 249Defines the callback for application-level proxy changes. 250 251**Since**: 12 252 253**Parameters** 254 255| Name| Description| 256| -------- | -------- | 257| proxy | Proxy configuration information (probably a null pointer).| 258 259 260### NetConn_NetConnCallback 261 262``` 263typedef struct NetConn_NetConnCallback NetConn_NetConnCallback 264``` 265 266**Description** 267 268Defines network status callbacks. 269 270**Since**: 12 271 272 273### NetConn_NetSpecifier 274 275``` 276typedef struct NetConn_NetSpecifier NetConn_NetSpecifier 277``` 278 279**Description** 280 281Defines the network feature set, including a network capability set and a network ID. 282 283**Since**: 12 284 285 286## Enum Description 287 288 289### NetConn_NetBearerType 290 291``` 292enum NetConn_NetBearerType 293``` 294 295**Description** 296 297Network carrier type. 298 299**Since**: 11 300 301| Value | Description | 302| ------------------------| ----------------------- | 303| NETCONN_BEARER_CELLULAR | Cellular network. | 304| NETCONN_BEARER_WIFI | Wi-Fi. | 305| NETCONN_BEARER_BLUETOOTH | Bluetooth.<br>**Since**: 12| 306| NETCONN_BEARER_ETHERNET | Ethernet. | 307| NETCONN_BEARER_VPN | Virtual private network.<br>**Since**: 12| 308 309 310### NetConn_NetCap 311 312``` 313enum NetConn_NetCap 314``` 315 316**Description** 317 318Network capability set. 319 320**Since**: 11 321 322| Value| Description| 323| -------- | -------- | 324| NETCONN_NET_CAPABILITY_MMS | MMS.| 325| NETCONN_NET_CAPABILITY_NOT_METERED | Non-metered network.| 326| NETCONN_NET_CAPABILITY_INTERNET | Internet.| 327| NETCONN_NET_CAPABILITY_NOT_VPN | Non-VPN.| 328| NETCONN_NET_CAPABILITY_VALIDATED | Verified.| 329| NETCONN_NET_CAPABILITY_CHECKING_CONNECTIVITY | Connectivity check.<br>**Since**: 12| 330 331 332## Function Description 333 334 335### OH_NetConn_FreeDnsResult() 336 337``` 338int32_t OH_NetConn_FreeDnsResult (struct addrinfo * res) 339``` 340 341**Description** 342 343Releases the DNS query result. 344 345**System capability**: SystemCapability.Communication.NetManager.Core 346 347**Since**: 11 348 349**Parameters** 350 351| Name| Description| 352| -------- | -------- | 353| res | Header of the DNS query result, which is in the format of linked lists.| 354 355**Returns** 356 357**0**: success. 358 359**201**: no permission. 360 361**401**: parameter error. 362 363**2100002**: failed to connect to the service. 364 365**2100003**: internal error. 366 367**Required permissions**: 368 369ohos.permission.INTERNET 370 371 372### OH_NetConn_GetAddrInfo() 373 374``` 375int32_t OH_NetConn_GetAddrInfo (char * host, char * serv, struct addrinfo * hint, struct addrinfo ** res, int32_t netId ) 376``` 377 378**Description** 379 380Obtains the DNS result using **netId**. 381 382**System capability**: SystemCapability.Communication.NetManager.Core 383 384**Since**: 11 385 386**Parameters** 387 388| Name| Description| 389| -------- | -------- | 390| host | Host name.| 391| serv | Service name.| 392| hint | Pointer to the addrinfo structure.| 393| res | DNS query result, which is in the format of linked lists.| 394| netId | If **netId** is set to **0**, the default **netid** is used for query.| 395 396**Returns** 397 398**0**: success. 399 400**201**: no permission. 401 402**401**: parameter error. 403 404**2100002**: failed to connect to the service. 405 406**2100003**: internal error. 407 408**Required permissions**: 409 410ohos.permission.INTERNET 411 412 413### OH_NetConn_GetAllNets() 414 415``` 416int32_t OH_NetConn_GetAllNets (NetConn_NetHandleList * netHandleList) 417``` 418 419**Description** 420 421Obtains all activated data networks. 422 423**System capability**: SystemCapability.Communication.NetManager.Core 424 425**Since**: 11 426 427**Parameters** 428 429| Name| Description| 430| -------- | -------- | 431| netHandleList | Network information list.| 432 433**Returns** 434 435**0**: success. 436 437**201**: no permission. 438 439**401**: parameter error. 440 441**2100002**: failed to connect to the service. 442 443**2100003**: internal error. 444 445**Required permissions**: 446 447ohos.permission.GET_NETWORK_INFO 448 449 450### OH_NetConn_GetConnectionProperties() 451 452``` 453int32_t OH_NetConn_GetConnectionProperties (NetConn_NetHandle * netHandle, NetConn_ConnectionProperties * prop ) 454``` 455 456**Description** 457 458Obtains the link information of a data network. 459 460**System capability**: SystemCapability.Communication.NetManager.Core 461 462**Since**: 11 463 464**Parameters** 465 466| Name| Description| 467| -------- | -------- | 468| nethandle | Network ID.| 469| prop | Link information.| 470 471**Returns** 472 473**0**: success. 474 475**201**: no permission. 476 477**401**: parameter error. 478 479**2100002**: failed to connect to the service. 480 481**2100003**: internal error. 482 483**Required permissions**: 484 485ohos.permission.GET_NETWORK_INFO 486 487 488### OH_NetConn_GetDefaultHttpProxy() 489 490``` 491int32_t OH_NetConn_GetDefaultHttpProxy (NetConn_HttpProxy * httpProxy) 492``` 493 494**Description** 495 496Obtains the default network proxy. 497 498**System capability**: SystemCapability.Communication.NetManager.Core 499 500**Since**: 11 501 502**Parameters** 503 504| Name| Description| 505| -------- | -------- | 506| httpProxy | Proxy configuration.| 507 508**Returns** 509 510**0**: success. 511 512**201**: no permission. 513 514**401**: parameter error. 515 516**2100002**: failed to connect to the service. 517 518**2100003**: internal error. 519 520 521### OH_NetConn_GetDefaultNet() 522 523``` 524int32_t OH_NetConn_GetDefaultNet (NetConn_NetHandle * netHandle) 525``` 526 527**Description** 528 529Obtains the default activated data network. 530 531**System capability**: SystemCapability.Communication.NetManager.Core 532 533**Since**: 11 534 535**Parameters** 536 537| Name| Description| 538| -------- | -------- | 539| netHandle | Network ID.| 540 541**Returns** 542 543**0**: success. 544 545**201**: no permission. 546 547**401**: parameter error. 548 549**2100002**: failed to connect to the service. 550 551**2100003**: internal error. 552 553**Required permissions**: 554 555ohos.permission.GET_NETWORK_INFO 556 557 558### OH_NetConn_GetNetCapabilities() 559 560``` 561int32_t OH_NetConn_GetNetCapabilities (NetConn_NetHandle * netHandle, NetConn_NetCapabilities * netCapacities ) 562``` 563 564**Description** 565 566Obtains the capabilities of a data network. 567 568**System capability**: SystemCapability.Communication.NetManager.Core 569 570**Since**: 11 571 572**Parameters** 573 574| Name| Description| 575| -------- | -------- | 576| netHandle | Network ID.| 577| netCapacities | Capability set.| 578 579**Returns** 580 581**0**: success. 582 583**201**: no permission. 584 585**401**: parameter error. 586 587**2100002**: failed to connect to the service. 588 589**2100003**: internal error. 590 591**Required permissions**: 592 593ohos.permission.GET_NETWORK_INFO 594 595 596### OH_NetConn_HasDefaultNet() 597 598``` 599int32_t OH_NetConn_HasDefaultNet (int32_t * hasDefaultNet) 600``` 601 602**Description** 603 604Checks whether a default activated data network is available. 605 606**System capability**: SystemCapability.Communication.NetManager.Core 607 608**Since**: 11 609 610**Parameters** 611 612| Name| Description| 613| -------- | -------- | 614| hasDefaultNet | Whether there is a default network.| 615 616**Returns** 617 618**0**: success. 619 620**201**: no permission. 621 622**401**: parameter error. 623 624**2100002**: failed to connect to the service. 625 626**2100003**: internal error. 627 628**Required permissions**: 629 630ohos.permission.GET_NETWORK_INFO 631 632 633### OH_NetConn_IsDefaultNetMetered() 634 635``` 636int32_t OH_NetConn_IsDefaultNetMetered (int32_t * isMetered) 637``` 638 639**Description** 640 641Checks whether metering is enabled for the default data network. 642 643**System capability**: SystemCapability.Communication.NetManager.Core 644 645**Since**: 11 646 647**Parameters** 648 649| Name| Description| 650| -------- | -------- | 651| isMetered | Whether metering is enabled.| 652 653**Returns** 654 655**0**: success. 656 657**201**: no permission. 658 659**401**: parameter error. 660 661**2100002**: failed to connect to the service. 662 663**2100003**: internal error. 664 665**Required permissions**: 666 667ohos.permission.GET_NETWORK_INFO 668 669 670### OHOS_NetConn_RegisterDnsResolver() 671 672``` 673int32_t OHOS_NetConn_RegisterDnsResolver (OH_NetConn_CustomDnsResolver resolver) 674``` 675 676**Description** 677 678Registers a custom DNS resolver. 679 680**System capability**: SystemCapability.Communication.NetManager.Core 681 682**Since**: 11 683 684**Parameters** 685 686| Name| Description| 687| -------- | -------- | 688| resolver | Pointer to the custom DNS resolver.| 689 690**Returns** 691 692**0**: success. 693 694**201**: no permission. 695 696**401**: parameter error. 697 698**2100002**: failed to connect to the service. 699 700**2100003**: internal error. 701 702**Required permissions**: 703 704ohos.permission.INTERNET 705 706 707### OHOS_NetConn_UnregisterDnsResolver() 708 709``` 710int32_t OHOS_NetConn_UnregisterDnsResolver (void ) 711``` 712 713**Description** 714 715Unregisters a custom DNS resolver. 716 717**System capability**: SystemCapability.Communication.NetManager.Core 718 719**Since**: 11 720 721**Returns** 722 723**0**: success. 724 725**201**: no permission. 726 727**401**: parameter error. 728 729**2100002**: failed to connect to the service. 730 731**2100003**: internal error. 732 733**Required permissions**: 734 735ohos.permission.INTERNET 736 737 738### OH_NetConn_BindSocket() 739 740``` 741int32_t OH_NetConn_BindSocket (int32_t socketFd, NetConn_NetHandle * netHandle) 742``` 743 744**Description** 745 746Binds a socket to the specified network. 747 748**System capability**: SystemCapability.Communication.NetManager.Core 749 750**Since**: 12 751 752**Parameters** 753 754| Name| Description| 755| -------- | -------- | 756| socketFd | File descriptor of the socket created by the user.| 757| netHandle | Network ID.| 758 759**Returns** 760 761**0**: success. 762 763**401**: parameter error. 764 765**2100002**: failed to connect to the service. 766 767**2100003**: internal error. 768 769 770### OH_NetConn_SetAppHttpProxy() 771 772``` 773int32_t OH_NetConn_SetAppHttpProxy(NetConn_HttpProxy *httpProxy) 774``` 775 776**Description** 777 778Sets the application-level proxy configuration. 779 780**System capability**: SystemCapability.Communication.NetManager.Core 781 782**Since**: 12 783 784**Parameters** 785 786| Name| Description| 787| -------- | -------- | 788| httpProxy | Application-level proxy configuration.| 789 790**Returns** 791 792**0**: success. 793 794**401**: parameter error. 795 796 797### OH_NetConn_RegisterAppHttpProxyCallback() 798 799``` 800int32_t OH_NetConn_RegisterAppHttpProxyCallback(OH_NetConn_AppHttpProxyChange appHttpProxyChange, uint32_t *callbackId) 801``` 802 803**Description** 804 805Registers a callback for application-level proxy changes. 806 807**System capability**: SystemCapability.Communication.NetManager.Core 808 809**Since**: 12 810 811**Parameters** 812 813| Name| Description| 814| -------- | -------- | 815| appHttpProxyChange | Pointer to the callback for application-level proxy changes.| 816| callbackId | Callback ID.| 817 818**Returns** 819 820**0**: success. 821 822**401**: parameter error. 823 824 825### OH_NetConn_UnregisterAppHttpProxyCallback() 826 827``` 828void OH_NetConn_UnregisterAppHttpProxyCallback(uint32_t callbackId) 829``` 830 831**Description** 832 833Unregisters the callback for application-level proxy changes. 834 835**System capability**: SystemCapability.Communication.NetManager.Core 836 837**Since**: 12 838 839**Parameters** 840 841| Name| Description| 842| -------- | -------- | 843| callbackId | Callback ID, which is obtained during registration.| 844 845 846### OH_NetConn_RegisterNetConnCallback() 847 848``` 849int32_t OH_NetConn_RegisterNetConnCallback(NetConn_NetSpecifier *specifier, NetConn_NetConnCallback *netConnCallback, uint32_t timeout, uint32_t *callbackId) 850``` 851 852**Description** 853 854Registers a callback to for status changes of the specified network. 855 856**System capability**: SystemCapability.Communication.NetManager.Core 857 858**Since**: 12 859 860**Parameters** 861 862| Name| Description| 863| -------- | -------- | 864| specifier | Network feature set.| 865| netConnCallback | Registered callbacks.| 866| timeout | Waiting time, in milliseconds. The value **0** indicates infinite waiting.| 867| callbackId | Callback IDs.| 868 869**Returns** 870 871**0**: success. 872 873**201**: no permission. 874 875**401**: parameter error. 876 877**2100002**: failed to connect to the service. 878 879**2100003**: internal error. 880 881**2101008**: The callback has been registered. 882 883**2101022**: The maximum number of requests is exceeded. 884 885**Required permissions**: 886 887ohos.permission.GET_NETWORK_INFO 888 889 890### OH_NetConn_RegisterDefaultNetConnCallback() 891 892``` 893int32_t OH_NetConn_RegisterDefaultNetConnCallback(NetConn_NetConnCallback *netConnCallback, uint32_t *callbackId) 894``` 895 896**Description** 897 898Registers a callback to for status changes of the default network. 899 900**System capability**: SystemCapability.Communication.NetManager.Core 901 902**Since**: 12 903 904**Parameters** 905 906| Name| Description| 907| -------- | -------- | 908| netConnCallback | Registered callbacks.| 909| callbackId | Callback IDs.| 910 911**Returns** 912 913**0**: success. 914 915**201**: no permission. 916 917**401**: parameter error. 918 919**2100002**: failed to connect to the service. 920 921**2100003**: internal error. 922 923**2101008**: The callback has been registered. 924 925**2101022**: The maximum number of requests is exceeded. 926 927**Required permissions**: 928 929ohos.permission.GET_NETWORK_INFO 930 931 932### OH_NetConn_UnregisterNetConnCallback() 933 934``` 935int32_t OH_NetConn_UnregisterNetConnCallback(uint32_t callBackId) 936``` 937 938**Description** 939 940Unregisters the callback for network status changes. 941 942**System capability**: SystemCapability.Communication.NetManager.Core 943 944**Since**: 12 945 946**Parameters** 947 948| Name| Description| 949| -------- | -------- | 950| callBackId | Callback ID.| 951 952**Returns** 953 954**0**: success. 955 956**201**: no permission. 957 958**401**: parameter error. 959 960**2100002**: failed to connect to the service. 961 962**2100003**: internal error. 963 964**2101007**: The corresponding callback is not found. 965 966**Required permissions**: 967 968ohos.permission.GET_NETWORK_INFO 969