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.<br>**File to include**: \<network\/netmanager\/net_connection.h\>| 19| [net_connection_type.h](net__connection__type_8h.md) | Declares the structs for the C APIs of the network connection module.<br>**File to include**: \<network\/netmanager\/net_connection_type.h\>| 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| [NetConn_ErrorCode](#netconn_errorcode) | Network connection error code.| 67 68### Enums 69 70| Name| Description| 71| -------- | -------- | 72| [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.| 73| [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.| 74| [NetConn_ErrorCode](#netconn_errorcode) {<br>NETCONN_SUCCESS = 0,<br>NETCONN_PERMISSION_DENIED = 201,<br>NETCONN_PARAMETER_ERROR = 401,<br>NETCONN_OPERATION_FAILED = 2100002,<br>NETCONN_INTERNAL_ERROR= 2100003<br>} | Network connection error code.| 75 76 77### Functions 78 79| Name| Description| 80| -------- | -------- | 81| [OH_NetConn_HasDefaultNet](#oh_netconn_hasdefaultnet) (int32_t \*hasDefaultNet) | Checks whether a default activated data network is available.| 82| [OH_NetConn_GetDefaultNet](#oh_netconn_getdefaultnet) ([NetConn_NetHandle](_net_conn___net_handle.md) \*netHandle) | Obtains the default activated data network.| 83| [OH_NetConn_IsDefaultNetMetered](#oh_netconn_isdefaultnetmetered) (int32_t \*isMetered) | Checks whether data traffic usage on the current network is metered.| 84| [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.| 85| [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.| 86| [OH_NetConn_GetDefaultHttpProxy](#oh_netconn_getdefaulthttpproxy) ([NetConn_HttpProxy](_net_conn___http_proxy.md) \*httpProxy) | Obtains the default network proxy.| 87| [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**.| 88| [OH_NetConn_FreeDnsResult](#oh_netconn_freednsresult) (struct addrinfo \*res) | Releases the DNS query result.| 89| [OH_NetConn_GetAllNets](#oh_netconn_getallnets) ([NetConn_NetHandleList](_net_conn___net_handle_list.md) \*netHandleList) | Obtains all activated data networks.| 90| [OHOS_NetConn_RegisterDnsResolver](#ohos_netconn_registerdnsresolver-deprecated) ([OH_NetConn_CustomDnsResolver](#oh_netconn_customdnsresolver) resolver) | Registers a custom DNS resolver.| 91| [OHOS_NetConn_UnregisterDnsResolver](#ohos_netconn_unregisterdnsresolver-deprecated) (void) | Unregisters a custom DNS resolver.| 92| [OH_NetConn_RegisterDnsResolver](#oh_netconn_registerdnsresolver) ([OH_NetConn_CustomDnsResolver](#oh_netconn_customdnsresolver) resolver) | Registers a custom DNS resolver.| 93| [OH_NetConn_UnregisterDnsResolver](#oh_netconn_unregisterdnsresolver) (void) | Unregisters a custom DNS resolver.| 94| [OH_NetConn_BindSocket](#oh_netconn_bindsocket) (int32_t socketFd, [NetConn_NetHandle](_net_conn___net_handle.md) \*netHandle) | Binds a socket to the specified network.| 95| [OH_NetConn_SetAppHttpProxy](#oh_netconn_setapphttpproxy) ([NetConn_HttpProxy](_net_conn___http_proxy.md) \*httpProxy) | Sets the application-level HTTP proxy information.| 96| [OH_NetConn_RegisterAppHttpProxyCallback](#oh_netconn_registerapphttpproxycallback) ([OH_NetConn_AppHttpProxyChange](#oh_netconn_apphttpproxychange) appHttpProxyChange, uint32_t \*callbackId) | Registers a listener for application-level proxy changes.| 97| [OH_NetConn_UnregisterAppHttpProxyCallback](#oh_netconn_unregisterapphttpproxycallback) (uint32_t callbackId) | Unregisters the listener for application-level proxy changes.| 98| [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.| 99| [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.| 100| [OH_NetConn_UnregisterNetConnCallback](#oh_netconn_unregisternetconncallback) (uint32_t callbackId) | Unregisters the callback for network status changes.| 101| [OH_NetConn_SetPacUrl](#oh_netconn_setpacurl) (const char \*pacUrl) | Sets the URL of the system-level proxy auto-config (PAC) script.| 102| [OH_NetConn_GetPacUrl](#oh_netconn_getpacurl) (char \*pacUrl) | Obtains the URL of the system-level PAC script.| 103 104 105## Type Description 106 107 108### NetConn_ConnectionProperties 109 110``` 111typedef struct NetConn_ConnectionProperties NetConn_ConnectionProperties 112``` 113 114**Description** 115 116Network connection information. 117 118**Since**: 11 119 120 121### NetConn_HttpProxy 122 123``` 124typedef struct NetConn_HttpProxy NetConn_HttpProxy 125``` 126 127**Description** 128 129Proxy configuration. 130 131**Since**: 11 132 133 134### NetConn_NetAddr 135 136``` 137typedef struct NetConn_NetAddr NetConn_NetAddr 138``` 139 140**Description** 141 142Network address. 143 144**Since**: 11 145 146 147### NetConn_NetBearerType 148 149``` 150typedef enum NetConn_NetBearerType NetConn_NetBearerType 151``` 152 153**Description** 154 155Network carrier type. 156 157**Since**: 11 158 159 160### NetConn_NetCap 161 162``` 163typedef enum NetConn_NetCap NetConn_NetCap 164``` 165 166**Description** 167 168Network capability set. 169 170**Since**: 11 171 172 173### NetConn_NetCapabilities 174 175``` 176typedef struct NetConn_NetCapabilities NetConn_NetCapabilities 177``` 178 179**Description** 180 181Network capability set. 182 183**Since**: 11 184 185 186### NetConn_NetHandle 187 188``` 189typedef struct NetConn_NetHandle NetConn_NetHandle 190``` 191 192**Description** 193 194Network ID. 195 196**Since**: 11 197 198 199### NetConn_NetHandleList 200 201``` 202typedef struct NetConn_NetHandleList NetConn_NetHandleList 203``` 204 205**Description** 206 207Network list. 208 209**Since**: 11 210 211 212### NetConn_Route 213 214``` 215typedef struct NetConn_Route NetConn_Route 216``` 217 218**Description** 219 220Route configuration. 221 222**Since**: 11 223 224 225### OH_NetConn_CustomDnsResolver 226 227``` 228typedef int(* OH_NetConn_CustomDnsResolver) (const char *host, const char *serv, const struct addrinfo *hint, struct addrinfo **res) 229``` 230 231**Description** 232 233Pointer to the custom DNS resolver. 234 235**Since**: 11 236 237**Parameters** 238 239| Name| Description| 240| -------- | -------- | 241| host | Host name.| 242| serv | Service name.| 243| hint | Pointer to the addrinfo structure.| 244| res | DNS query result, which is in the format of linked lists.| 245 246 247### OH_NetConn_AppHttpProxyChange 248 249``` 250typedef void(* OH_NetConn_AppHttpProxyChange) (NetConn_HttpProxy *proxy) 251``` 252 253**Description** 254 255Defines the callback for application-level proxy changes. 256 257**Since**: 12 258 259**Parameters** 260 261| Name| Description| 262| -------- | -------- | 263| proxy | Proxy configuration information (probably a null pointer).| 264 265 266### NetConn_NetConnCallback 267 268``` 269typedef struct NetConn_NetConnCallback NetConn_NetConnCallback 270``` 271 272**Description** 273 274Defines network status callbacks. 275 276**Since**: 12 277 278 279### NetConn_NetSpecifier 280 281``` 282typedef struct NetConn_NetSpecifier NetConn_NetSpecifier 283``` 284 285**Description** 286 287Defines the network feature set, including a network capability set and a network ID. 288 289**Since**: 12 290 291 292### NetConn_ErrorCode 293 294``` 295typedef enum NetConn_ErrorCode NetConn_ErrorCode 296``` 297 298**Description** 299 300Enumerates network connection error codes. 301 302**Since**: 15 303 304 305## Enum Description 306 307 308### NetConn_NetBearerType 309 310``` 311enum NetConn_NetBearerType 312``` 313 314**Description** 315 316Network carrier type. 317 318**Since**: 11 319 320| Value | Description | 321| ------------------------| ----------------------- | 322| NETCONN_BEARER_CELLULAR | Cellular network. | 323| NETCONN_BEARER_WIFI | Wi-Fi. | 324| NETCONN_BEARER_BLUETOOTH | Bluetooth.<br>**Since**: 12| 325| NETCONN_BEARER_ETHERNET | Ethernet. | 326| NETCONN_BEARER_VPN | Virtual private network.<br>**Since**: 12| 327 328 329### NetConn_NetCap 330 331``` 332enum NetConn_NetCap 333``` 334 335**Description** 336 337Network capability set. 338 339**Since**: 11 340 341| Value| Description| 342| -------- | -------- | 343| NETCONN_NET_CAPABILITY_MMS | MMS.| 344| NETCONN_NET_CAPABILITY_NOT_METERED | Non-metered network.| 345| NETCONN_NET_CAPABILITY_INTERNET | Internet.| 346| NETCONN_NET_CAPABILITY_NOT_VPN | Non-VPN.| 347| NETCONN_NET_CAPABILITY_VALIDATED | Verified.| 348| NETCONN_NET_CAPABILITY_CHECKING_CONNECTIVITY | Connectivity check.<br>**Since**: 12| 349 350 351### NetConn_ErrorCode 352 353``` 354enum NetConn_ErrorCode 355``` 356 357**Description** 358 359Enumerates network connection error codes. 360 361**Since**: 15 362 363| Value | Description | 364| ------------------------ | ----------------------- | 365| NETCONN_SUCCESS | Success. | 366| NETCONN_PERMISSION_DENIED| Permission verification failed. | 367| NETCONN_PARAMETER_ERROR | Parameter check failed. | 368| NETCONN_OPERATION_FAILED | Service connection failed. | 369| NETCONN_INTERNAL_ERROR | Internal server error. | 370 371 372## Function Description 373 374 375### OH_NetConn_FreeDnsResult() 376 377``` 378int32_t OH_NetConn_FreeDnsResult (struct addrinfo * res) 379``` 380 381**Description** 382 383Releases the DNS query result. 384 385**System capability**: SystemCapability.Communication.NetManager.Core 386 387**Since**: 11 388 389**Parameters** 390 391| Name| Description| 392| -------- | -------- | 393| res | Header of the DNS query result, which is in the format of linked lists.| 394 395**Returns** 396 397**0**: success. 398 399**201**: no permission. 400 401**401**: invalid parameter. 402 403**2100002**: failed to connect to the service. 404 4052100003 - Internal error. 406 407**Required permissions**: 408 409ohos.permission.INTERNET 410 411 412### OH_NetConn_GetAddrInfo() 413 414``` 415int32_t OH_NetConn_GetAddrInfo (char * host, char * serv, struct addrinfo * hint, struct addrinfo ** res, int32_t netId ) 416``` 417 418**Description** 419 420Obtains the DNS result using **netId**. 421 422**System capability**: SystemCapability.Communication.NetManager.Core 423 424**Since**: 11 425 426**Parameters** 427 428| Name| Description| 429| -------- | -------- | 430| host | Host name.| 431| serv | Service name.| 432| hint | Pointer to the addrinfo structure.| 433| res | DNS query result, which is in the format of linked lists.| 434| netId | If **netId** is set to **0**, the default **netid** is used for query.| 435 436**Returns** 437 438**0**: success. 439 440**201**: no permission. 441 442**401**: invalid parameter. 443 444**2100002**: failed to connect to the service. 445 4462100003 - Internal error. 447 448**Required permissions**: 449 450ohos.permission.INTERNET 451 452 453### OH_NetConn_GetAllNets() 454 455``` 456int32_t OH_NetConn_GetAllNets (NetConn_NetHandleList * netHandleList) 457``` 458 459**Description** 460 461Obtains all activated data networks. 462 463**System capability**: SystemCapability.Communication.NetManager.Core 464 465**Since**: 11 466 467**Parameters** 468 469| Name| Description| 470| -------- | -------- | 471| netHandleList | Network information list.| 472 473**Returns** 474 475**0**: success. 476 477**201**: no permission. 478 479**401**: invalid parameter. 480 481**2100002**: failed to connect to the service. 482 4832100003 - Internal error. 484 485**Required permissions**: 486 487ohos.permission.GET_NETWORK_INFO 488 489 490### OH_NetConn_GetConnectionProperties() 491 492``` 493int32_t OH_NetConn_GetConnectionProperties (NetConn_NetHandle * netHandle, NetConn_ConnectionProperties * prop ) 494``` 495 496**Description** 497 498Obtains the link information of a data network. 499 500**System capability**: SystemCapability.Communication.NetManager.Core 501 502**Since**: 11 503 504**Parameters** 505 506| Name| Description| 507| -------- | -------- | 508| nethandle | Network ID.| 509| prop | Link information.| 510 511**Returns** 512 513**0**: success. 514 515**201**: no permission. 516 517**401**: invalid parameter. 518 519**2100002**: failed to connect to the service. 520 5212100003 - Internal error. 522 523**Required permissions**: 524 525ohos.permission.GET_NETWORK_INFO 526 527 528### OH_NetConn_GetDefaultHttpProxy() 529 530``` 531int32_t OH_NetConn_GetDefaultHttpProxy (NetConn_HttpProxy * httpProxy) 532``` 533 534**Description** 535 536Obtains the default network proxy. 537 538**System capability**: SystemCapability.Communication.NetManager.Core 539 540**Since**: 11 541 542**Parameters** 543 544| Name| Description| 545| -------- | -------- | 546| httpProxy | Proxy configuration.| 547 548**Returns** 549 550**0**: success. 551 552**201**: no permission. 553 554**401**: invalid parameter. 555 556**2100002**: failed to connect to the service. 557 5582100003 - Internal error. 559 560 561### OH_NetConn_GetDefaultNet() 562 563``` 564int32_t OH_NetConn_GetDefaultNet (NetConn_NetHandle * netHandle) 565``` 566 567**Description** 568 569Obtains the default activated data network. 570 571**System capability**: SystemCapability.Communication.NetManager.Core 572 573**Since**: 11 574 575**Parameters** 576 577| Name| Description| 578| -------- | -------- | 579| netHandle | Network ID.| 580 581**Returns** 582 583**0**: success. 584 585**201**: no permission. 586 587**401**: invalid parameter. 588 589**2100002**: failed to connect to the service. 590 5912100003 - Internal error. 592 593**Required permissions**: 594 595ohos.permission.GET_NETWORK_INFO 596 597 598### OH_NetConn_GetNetCapabilities() 599 600``` 601int32_t OH_NetConn_GetNetCapabilities (NetConn_NetHandle * netHandle, NetConn_NetCapabilities * netCapacities ) 602``` 603 604**Description** 605 606Obtains the capabilities of a data network. 607 608**System capability**: SystemCapability.Communication.NetManager.Core 609 610**Since**: 11 611 612**Parameters** 613 614| Name| Description| 615| -------- | -------- | 616| netHandle | Network ID.| 617| netCapacities | Capability set.| 618 619**Returns** 620 621**0**: success. 622 623**201**: no permission. 624 625**401**: invalid parameter. 626 627**2100002**: failed to connect to the service. 628 6292100003 - Internal error. 630 631**Required permissions**: 632 633ohos.permission.GET_NETWORK_INFO 634 635 636### OH_NetConn_HasDefaultNet() 637 638``` 639int32_t OH_NetConn_HasDefaultNet (int32_t * hasDefaultNet) 640``` 641 642**Description** 643 644Checks whether a default activated data network is available. 645 646**System capability**: SystemCapability.Communication.NetManager.Core 647 648**Since**: 11 649 650**Parameters** 651 652| Name| Description| 653| -------- | -------- | 654| hasDefaultNet | Whether there is a default network.| 655 656**Returns** 657 658**0**: success. 659 660**201**: no permission. 661 662**401**: invalid parameter. 663 664**2100002**: failed to connect to the service. 665 6662100003 - Internal error. 667 668**Required permissions**: 669 670ohos.permission.GET_NETWORK_INFO 671 672 673### OH_NetConn_IsDefaultNetMetered() 674 675``` 676int32_t OH_NetConn_IsDefaultNetMetered (int32_t * isMetered) 677``` 678 679**Description** 680 681Checks whether metering is enabled for the default data network. 682 683**System capability**: SystemCapability.Communication.NetManager.Core 684 685**Since**: 11 686 687**Parameters** 688 689| Name| Description| 690| -------- | -------- | 691| isMetered | Whether metering is enabled.| 692 693**Returns** 694 695**0**: success. 696 697**201**: no permission. 698 699**401**: invalid parameter. 700 701**2100002**: failed to connect to the service. 702 7032100003 - Internal error. 704 705**Required permissions**: 706 707ohos.permission.GET_NETWORK_INFO 708 709 710### OHOS_NetConn_RegisterDnsResolver() <sup>(deprecated)</sup> 711 712``` 713int32_t OHOS_NetConn_RegisterDnsResolver (OH_NetConn_CustomDnsResolver resolver) 714``` 715 716**Description** 717 718Registers a custom DNS resolver. 719 720**System capability**: SystemCapability.Communication.NetManager.Core 721 722**Since**: 11 723 724**Deprecated from**: 13 725 726**Substitute API**: [OH_NetConn_RegisterDnsResolver](#oh_netconn_registerdnsresolver) 727 728**Parameters** 729 730| Name| Description| 731| -------- | -------- | 732| resolver | Pointer to the custom DNS resolver.| 733 734**Returns** 735 736**0**: success. 737 738**201**: no permission. 739 740**401**: invalid parameter. 741 742**2100002**: failed to connect to the service. 743 7442100003 - Internal error. 745 746**Required permissions**: 747 748ohos.permission.INTERNET 749 750 751### OHOS_NetConn_UnregisterDnsResolver() <sup>(deprecated)</sup> 752 753``` 754int32_t OHOS_NetConn_UnregisterDnsResolver (void ) 755``` 756 757**Description** 758 759Unregisters a custom DNS resolver. 760 761**System capability**: SystemCapability.Communication.NetManager.Core 762 763**Since**: 11 764 765**Deprecated from**: 13 766 767**Substitute API**: [OH_NetConn_UnregisterDnsResolver](#oh_netconn_unregisterdnsresolver) 768 769**Returns** 770 771**0**: success. 772 773**201**: no permission. 774 775**401**: invalid parameter. 776 777**2100002**: failed to connect to the service. 778 7792100003 - Internal error. 780 781**Required permissions**: 782 783ohos.permission.INTERNET 784 785 786### OH_NetConn_RegisterDnsResolver() 787 788``` 789int32_t OH_NetConn_RegisterDnsResolver (OH_NetConn_CustomDnsResolver resolver) 790``` 791 792**Description** 793 794Registers a custom DNS resolver. 795 796**System capability**: SystemCapability.Communication.NetManager.Core 797 798**Since**: 13 799 800**Parameters** 801 802| Name| Description| 803| -------- | -------- | 804| resolver | Pointer to the custom DNS resolver.| 805 806**Returns** 807 808**0**: success. 809 810**201**: no permission. 811 812**401**: invalid parameter. 813 814**2100002**: failed to connect to the service. 815 8162100003 - Internal error. 817 818**Required permissions**: 819 820ohos.permission.INTERNET 821 822 823### OH_NetConn_UnregisterDnsResolver() 824 825``` 826int32_t OH_NetConn_UnregisterDnsResolver (void ) 827``` 828 829**Description** 830 831Unregisters a custom DNS resolver. 832 833**System capability**: SystemCapability.Communication.NetManager.Core 834 835**Since**: 13 836 837**Returns** 838 839**0**: success. 840 841**201**: no permission. 842 843**401**: invalid parameter. 844 845**2100002**: failed to connect to the service. 846 8472100003 - Internal error. 848 849**Required permissions**: 850 851ohos.permission.INTERNET 852 853 854### OH_NetConn_BindSocket() 855 856``` 857int32_t OH_NetConn_BindSocket (int32_t socketFd, NetConn_NetHandle * netHandle) 858``` 859 860**Description** 861 862Binds a socket to the specified network. 863 864**System capability**: SystemCapability.Communication.NetManager.Core 865 866**Since**: 12 867 868**Parameters** 869 870| Name| Description| 871| -------- | -------- | 872| socketFd | File descriptor of the socket created by the user.| 873| netHandle | Network ID.| 874 875**Returns** 876 877**0**: success. 878 879**401**: invalid parameter. 880 881**2100002**: failed to connect to the service. 882 8832100003 - Internal error. 884 885 886### OH_NetConn_SetAppHttpProxy() 887 888``` 889int32_t OH_NetConn_SetAppHttpProxy(NetConn_HttpProxy *httpProxy) 890``` 891 892**Description** 893 894Sets the application-level proxy configuration. 895 896**System capability**: SystemCapability.Communication.NetManager.Core 897 898**Since**: 12 899 900**Parameters** 901 902| Name| Description| 903| -------- | -------- | 904| httpProxy | Application-level proxy configuration.| 905 906**Returns** 907 908**0**: success. 909 910**401**: invalid parameter. 911 912 913### OH_NetConn_RegisterAppHttpProxyCallback() 914 915``` 916int32_t OH_NetConn_RegisterAppHttpProxyCallback(OH_NetConn_AppHttpProxyChange appHttpProxyChange, uint32_t *callbackId) 917``` 918 919**Description** 920 921Registers a callback for application-level proxy changes. 922 923**System capability**: SystemCapability.Communication.NetManager.Core 924 925**Since**: 12 926 927**Parameters** 928 929| Name| Description| 930| -------- | -------- | 931| appHttpProxyChange | Pointer to the callback for application-level proxy changes.| 932| callbackId | Callback ID.| 933 934**Returns** 935 936**0**: success. 937 938**401**: invalid parameter. 939 940 941### OH_NetConn_UnregisterAppHttpProxyCallback() 942 943``` 944void OH_NetConn_UnregisterAppHttpProxyCallback(uint32_t callbackId) 945``` 946 947**Description** 948 949Unregisters the callback for application-level proxy changes. 950 951**System capability**: SystemCapability.Communication.NetManager.Core 952 953**Since**: 12 954 955**Parameters** 956 957| Name| Description| 958| -------- | -------- | 959| callbackId | Callback ID, which is obtained during registration.| 960 961 962### OH_NetConn_RegisterNetConnCallback() 963 964``` 965int32_t OH_NetConn_RegisterNetConnCallback(NetConn_NetSpecifier *specifier, NetConn_NetConnCallback *netConnCallback, uint32_t timeout, uint32_t *callbackId) 966``` 967 968**Description** 969 970Registers a callback to for status changes of the specified network. 971 972**System capability**: SystemCapability.Communication.NetManager.Core 973 974**Since**: 12 975 976**Parameters** 977 978| Name| Description| 979| -------- | -------- | 980| specifier | Network feature set.| 981| netConnCallback | Registered callbacks.| 982| timeout | Waiting time, in milliseconds. The value **0** indicates infinite waiting.| 983| callbackId | Callback IDs.| 984 985**Returns** 986 987**0**: success. 988 989**201**: no permission. 990 991**401**: invalid parameter. 992 993**2100002**: failed to connect to the service. 994 9952100003 - Internal error. 996 997**2101008**: The callback has been registered. 998 999**2101022**: The maximum number of requests is exceeded. 1000 1001**Required permissions**: 1002 1003ohos.permission.GET_NETWORK_INFO 1004 1005 1006### OH_NetConn_RegisterDefaultNetConnCallback() 1007 1008``` 1009int32_t OH_NetConn_RegisterDefaultNetConnCallback(NetConn_NetConnCallback *netConnCallback, uint32_t *callbackId) 1010``` 1011 1012**Description** 1013 1014Registers a callback to for status changes of the default network. 1015 1016**System capability**: SystemCapability.Communication.NetManager.Core 1017 1018**Since**: 12 1019 1020**Parameters** 1021 1022| Name| Description| 1023| -------- | -------- | 1024| netConnCallback | Registered callbacks.| 1025| callbackId | Callback IDs.| 1026 1027**Returns** 1028 1029**0**: success. 1030 1031**201**: no permission. 1032 1033**401**: invalid parameter. 1034 1035**2100002**: failed to connect to the service. 1036 10372100003 - Internal error. 1038 1039**2101008**: The callback has been registered. 1040 1041**2101022**: The maximum number of requests is exceeded. 1042 1043**Required permissions**: 1044 1045ohos.permission.GET_NETWORK_INFO 1046 1047 1048### OH_NetConn_UnregisterNetConnCallback() 1049 1050``` 1051int32_t OH_NetConn_UnregisterNetConnCallback(uint32_t callBackId) 1052``` 1053 1054**Description** 1055 1056Unregisters the callback for network status changes. 1057 1058**System capability**: SystemCapability.Communication.NetManager.Core 1059 1060**Since**: 12 1061 1062**Parameters** 1063 1064| Name| Description| 1065| -------- | -------- | 1066| callBackId | Callback ID.| 1067 1068**Returns** 1069 1070**0**: success. 1071 1072**201**: no permission. 1073 1074**401**: invalid parameter. 1075 1076**2100002**: failed to connect to the service. 1077 10782100003 - Internal error. 1079 1080**2101007**: The corresponding callback is not found. 1081 1082**Required permissions**: 1083 1084ohos.permission.GET_NETWORK_INFO 1085 1086 1087### OH_NetConn_SetPacUrl() 1088 1089``` 1090NetConn_ErrorCode OH_NetConn_SetPacUrl(const char *pacUrl) 1091``` 1092 1093**Description** 1094 1095Sets the URL of the system-level proxy auto-config (PAC) script. 1096 1097**System capability**: SystemCapability.Communication.NetManager.Core 1098 1099**Since**: 15 1100 1101**Parameters** 1102 1103| Name| Description| 1104| -------- | -------- | 1105| pacUrl | URL of the PAC script. Note that this URL will not be verified by the API.| 1106 1107**Returns** 1108 1109**NETCONN_SUCCESS**: success. 1110 1111**NETCONN_PERMISSION_DENIED**: no permission. 1112 1113**NETCONN_PARAMETER_ERROR**: invalid parameter. 1114 1115**NETCONN_OPERATION_FAILED**: service connection failed. 1116 1117**NETCONN_INTERNAL_ERROR**: internal error. 1118 1119**Required permissions**: 1120 1121ohos.permission.SET_PAC_URL 1122 1123 1124### OH_NetConn_GetPacUrl() 1125 1126``` 1127NetConn_ErrorCode OH_NetConn_GetPacUrl(char *pacUrl) 1128``` 1129 1130**Description** 1131 1132Obtains the URL of the system-level PAC script. 1133 1134**System capability**: SystemCapability.Communication.NetManager.Core 1135 1136**Since**: 15 1137 1138**Parameters** 1139 1140| Name| Description| 1141| -------- | -------- | 1142| pacUrl | URL of the PAC script.| 1143 1144**Returns** 1145 1146**NETCONN_SUCCESS**: success. 1147 1148**NETCONN_PERMISSION_DENIED**: no permission. 1149 1150**NETCONN_OPERATION_FAILED**: service connection failed. 1151 1152**NETCONN_INTERNAL_ERROR**: internal error. 1153