openharmony 鸿蒙 capi-net-connection-type-h

2026-08-25 浏览 (1)

net_connection_type.h

Overview

Provides the C APIs of the network connection module for network management.

File to include: <network/netmanager/net_connection_type.h>

Library: libnet_connection.so

System capability: SystemCapability.Communication.NetManager.Core

Since: 11

Related module: NetConnection

Summary

Structs

Nametypedef KeywordDescription
NetConn_NetHandleNetConn_NetHandleNetwork ID.
NetConn_NetCapabilitiesNetConn_NetCapabilitiesNetwork capability set.
NetConn_NetAddrNetConn_NetAddrNetwork address.
NetConn_RouteNetConn_RouteRoute configuration.
NetConn_HttpProxyNetConn_HttpProxyProxy configuration.
NetConn_ConnectionPropertiesNetConn_ConnectionPropertiesNetwork connection properties.
NetConn_NetHandleListNetConn_NetHandleListNetwork list.
NetConn_NetSpecifierNetConn_NetSpecifierNetwork feature sets.
NetConn_NetConnCallbackNetConn_NetConnCallbackNetwork status callback.
NetConn_ProbeResultInfoNetConn_ProbeResultInfoProbe result.
NetConn_TraceRouteOptionNetConn_TraceRouteOptionNetwork trace route options.
NetConn_TraceRouteInfoNetConn_TraceRouteInfoTrace route information.

Enums

Nametypedef KeywordDescription
NetConn_NetCapNetConn_NetCapNetwork capability set.
NetConn_NetBearerTypeNetConn_NetBearerTypeNetwork carrier type.
NetConn_ErrorCodeNetConn_ErrorCodeNetwork connection error code.
NetConn_PacketsTypeNetConn_PacketsTypeTrace route packet type.

Macros

NameDescription
NETCONN_MAX_RTT_NUM 4Length of the rtt array of the NetConn_ProbeResultInfo member variable.
Since: 11
NETCONN_MAX_NET_SIZE 32Length of the netHandles array of the NetConn_NetHandleList member variable.
Since: 11
NETCONN_MAX_BEARER_TYPE_SIZE 32Length of the bearerTypes array of the NetConn_NetCapabilities member variable.
Since: 11
NETCONN_MAX_CAP_SIZE 32Length of the netCaps array of the NetConn_NetCapabilities member variable.
Since: 11
NETCONN_MAX_ADDR_SIZE 32Length of the netAddrList and dnsList arrays of the NetConn_ConnectionProperties member variable.
Since: 11
NETCONN_MAX_ROUTE_SIZE 64Length of routeList array of NetConn_ConnectionProperties member variable.
Since: 11
NETCONN_MAX_EXCLUSION_SIZE 256Length of the exclusionList array of NetConn_HttpProxy member variable.
Since: 11
NETCONN_MAX_STR_LEN 256Length of the host array of NetConn_HttpProxy member variable.
Since: 11

Functions

Nametypedef KeywordDescription
typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv,const struct addrinfo *hint, struct addrinfo **res)OH_NetConn_CustomDnsResolverPointer to the custom DNS resolver.
typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy)OH_NetConn_AppHttpProxyChangeCallback invoked when the HTTP proxy information of the application changes.
typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle)OH_NetConn_NetworkAvailableCallback invoked when the network is available.
typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle,NetConn_NetCapabilities *netCapabilities)OH_NetConn_NetCapabilitiesChangeCallback invoked when the network capabilities change.
typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle,NetConn_ConnectionProperties *connConnetionProperties)OH_NetConn_NetConnectionPropertiesChangeCallback invoked when network connection properties change.
typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle)OH_NetConn_NetLostCallback invoked when the network is disconnected.
typedef void (*OH_NetConn_NetUnavailable)(void)OH_NetConn_NetUnavailableCallback invoked when the network is unavailable. This callback is triggered when the network is not activated within the specified timeout interval. If the timeout interval is not set, this callback is not triggered.
typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked)OH_NetConn_NetBlockStatusChangeCallback invoked when the network blocking status changes.

Enum Description

NetConn_NetCap

enum NetConn_NetCap

Description

Enumerates the network capabilities.

Since: 11

Enum ItemDescription
NETCONN_NET_CAPABILITY_MMS = 0MMS.
NETCONN_NET_CAPABILITY_NOT_METERED = 11Non-metered network.
NETCONN_NET_CAPABILITY_INTERNET = 12Internet.
NETCONN_NET_CAPABILITY_NOT_VPN = 15Non-VPN.
NETCONN_NET_CAPABILITY_VALIDATED = 16Verified.
NETCONN_NET_CAPABILITY_PORTAL = 17Portal.
Since: 12
NETCONN_NET_CAPABILITY_CHECKING_CONNECTIVITY = 31Connectivity check.
Since: 12

NetConn_NetBearerType

enum NetConn_NetBearerType

Description

Enumerates the network carrier types.

Since: 11

Enum ItemDescription
NETCONN_BEARER_CELLULAR = 0Cellular network.
NETCONN_BEARER_WIFI = 1Wi-Fi.
NETCONN_BEARER_BLUETOOTH = 2Bluetooth.
Since: 12
NETCONN_BEARER_ETHERNET = 3Ethernet.
NETCONN_BEARER_VPN = 4VPN.
Since: 12

NetConn_ErrorCode

enum NetConn_ErrorCode

Description

Enumerates network connection error codes.

Since: 15

Enum ItemDescription
NETCONN_SUCCESS = 0Success.
NETCONN_PERMISSION_DENIED = 201Missing permissions.
NETCONN_PARAMETER_ERROR = 401Invalid parameter.
NETCONN_OPERATION_FAILED = 2100002Service connection failure.
NETCONN_INTERNAL_ERROR = 2100003Internal error.1. Memory-related error, for example, insufficient memory, memory data copy failure, or memory request failure.2. Null pointer, for example, access to a released memory pointer.

NetConn_PacketsType

enum NetConn_PacketsType

Description

Enumerates trace route packet types.

Since: 20

Enum ItemDescription
NETCONN_PACKETS_ICMP = 0Internet Control Message Protocol.
NETCONN_PACKETS_UDP = 1User Datagram Protocol.

Function Description

OH_NetConn_CustomDnsResolver()

typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv,const struct addrinfo *hint, struct addrinfo **res)

Description

Defines the pointer to the custom DNS resolver.

Since: 11

Parameters

NameDescription
const char *hostHost name.
const char *servService name.
const struct addrinfo *hintPointer to the addrinfo structure.
struct addrinfo **resDNS query result, which is in the format of linked lists.

OH_NetConn_AppHttpProxyChange()

typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy)

Description

Defines the callback invoked when the HTTP proxy information of the application changes.

Since: 12

Parameters

NameDescription
NetConn_HttpProxy *proxyProxy configuration information (probably a null pointer).

OH_NetConn_NetworkAvailable()

typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle)

Description

Defines the callback invoked when the network is available.

Since: 12

Parameters

NameDescription
NetConn_NetHandle *netHandleNetwork handle.

OH_NetConn_NetCapabilitiesChange()

typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle,NetConn_NetCapabilities *netCapabilities)

Description

Defines the callback invoked when the network capabilities change.

Since: 12

Parameters

NameDescription
NetConn_NetHandle *netHandleNetwork handle.
NetConn_NetCapabilities *netCapabilitiesNetwork capability set.

OH_NetConn_NetConnectionPropertiesChange()

typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle,NetConn_ConnectionProperties *connConnetionProperties)

Description

Defines the callback invoked when network connection properties change.

Since: 12

Parameters

NameDescription
NetConn_NetHandle *netHandleNetwork handle.
NetConn_ConnectionProperties *connConnetionPropertiesNetwork connection properties.

OH_NetConn_NetLost()

typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle)

Description

Defines the callback invoked when the network is disconnected.

Since: 12

Parameters

NameDescription
NetConn_NetHandle *netHandleNetwork handle.

OH_NetConn_NetUnavailable()

typedef void (*OH_NetConn_NetUnavailable)(void)

Description

Defines the callback invoked when the network is unavailable. This callback is triggered when the network is not activated within the specified timeout interval. If the timeout interval is not set, this callback is not triggered.

Since: 12

OH_NetConn_NetBlockStatusChange()

typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked)

Description

Defines the callback invoked when the network blocking status changes.

Since: 12

Parameters

NameDescription
NetConn_NetHandle *netHandleNetwork handle.
bool blockedWhether the network is blocked. The value true indicates that the network is blocked, and the value false indicates the opposite.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-netconnection-netconn-connectionproperties

openharmony 鸿蒙 errorcode-net-mdns

openharmony 鸿蒙 js-apis-net-ethernet-sys

openharmony 鸿蒙 errorcode-net-http

openharmony 鸿蒙 capi-netstack-http-proxy

openharmony 鸿蒙 js-apis-system-fetch

openharmony 鸿蒙 errorcode-kernel

openharmony 鸿蒙 capi-netstack-netstack-certblob

openharmony 鸿蒙 js-apis-net-mdns

openharmony 鸿蒙 capi-netstack-websocket-closeoption

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/xHgHefL3