QNetworkAddressEntry 类

QNetworkAddressEntry 类存储由网络接口支持的一个 IP 地址,及其关联的 Netmask (网络掩码) 和广播地址。 更多...

头: #include <QNetworkAddressEntry>
CMake: find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network

注意: 此类的所有函数 可重入 .

公共类型

enum DnsEligibilityStatus { DnsEligibilityUnknown, DnsEligible, DnsIneligible }

公共函数

QNetworkAddressEntry ()
QNetworkAddressEntry (const QNetworkAddressEntry & other )
~QNetworkAddressEntry ()
QHostAddress broadcast () const
void clearAddressLifetime ()
QNetworkAddressEntry::DnsEligibilityStatus dnsEligibility () const
QHostAddress ip () const
bool isLifetimeKnown () const
bool isPermanent () const
bool isTemporary () const
QHostAddress netmask () const
QDeadlineTimer preferredLifetime () const
int prefixLength () const
void setAddressLifetime (QDeadlineTimer preferred , QDeadlineTimer validity )
void setBroadcast (const QHostAddress & newBroadcast )
void setDnsEligibility (QNetworkAddressEntry::DnsEligibilityStatus status )
void setIp (const QHostAddress & newIp )
void setNetmask (const QHostAddress & newNetmask )
void setPrefixLength (int length )
void swap (QNetworkAddressEntry & other )
QDeadlineTimer validityLifetime () const
bool operator!= (const QNetworkAddressEntry & other ) const
QNetworkAddressEntry & operator= (const QNetworkAddressEntry & other )
bool operator== (const QNetworkAddressEntry & other ) const
(从 6.2 起) QDebug operator<< (QDebug debug , const QNetworkAddressEntry & entry )

详细描述

每个网络接口可以包含零个或多个 IP 地址,可以依次关联 Netmask (网络掩码) 和/或广播地址 (取决于操作系统是否支持)。

此类表示一个这样的组。

成员类型文档编制

enum QNetworkAddressEntry:: DnsEligibilityStatus

This enum indicates whether a given host address is eligible to be published in the Domain Name System (DNS) or other similar name resolution mechanisms. In general, an address is suitable for publication if it is an address this machine will be reached at for an indeterminate amount of time, though it need not be permanent. For example, addresses obtained via DHCP are often eligible, but cryptographically-generated temporary IPv6 addresses are not.

常量 描述
QNetworkAddressEntry::DnsEligibilityUnknown -1 Qt and the operating system could not determine whether this address should be published or not. The application may need to apply further heuristics if it cannot find any eligible addresses.
QNetworkAddressEntry::DnsEligible 1 This address is eligible for publication in DNS.
QNetworkAddressEntry::DnsIneligible 0 This address should not be published in DNS and should not be transmitted to other parties, except maybe as the source address of an outgoing packet.

另请参阅 dnsEligibility () 和 setDnsEligibility ().

成员函数文档编制

QNetworkAddressEntry:: QNetworkAddressEntry ()

构造空的 QNetworkAddressEntry 对象。

QNetworkAddressEntry:: QNetworkAddressEntry (const QNetworkAddressEntry & other )

构造 QNetworkAddressEntry 对象副本源于对象 other .

[noexcept] QNetworkAddressEntry:: ~QNetworkAddressEntry ()

销毁此 QNetworkAddressEntry 对象。

QHostAddress QNetworkAddressEntry:: broadcast () const

Returns the broadcast address associated with the IPv4 address and netmask. It can usually be derived from those two by setting to 1 the bits of the IP address where the netmask contains a 0. (In other words, by bitwise-OR'ing the IP address with the inverse of the netmask)

This member is always empty for IPv6 addresses, since the concept of broadcast has been abandoned in that system in favor of multicast. In particular, the group of hosts corresponding to all the nodes in the local network can be reached by the "all-nodes" special multicast group (address FF02::1).

另请参阅 setBroadcast ().

void QNetworkAddressEntry:: clearAddressLifetime ()

Resets both the preferred and valid lifetimes for this address. After this call, isLifetimeKnown () 会返回 false .

另请参阅 preferredLifetime (), validityLifetime (), isLifetimeKnown (),和 setAddressLifetime ().

QNetworkAddressEntry::DnsEligibilityStatus QNetworkAddressEntry:: dnsEligibility () const

Returns whether this address is eligible for publication in the Domain Name System (DNS) or similar name resolution mechanisms.

In general, an address is suitable for publication if it is an address this machine will be reached at for an indeterminate amount of time, though it need not be permanent. For example, addresses obtained via DHCP are often eligible, but cryptographically-generated temporary IPv6 addresses are not.

在某些系统, QNetworkInterface will need to heuristically determine which addresses are eligible.

另请参阅 isLifetimeKnown (), isPermanent (),和 setDnsEligibility ().

QHostAddress QNetworkAddressEntry:: ip () const

This function returns one IPv4 or IPv6 address found, that was found in a network interface.

另请参阅 setIp ().

bool QNetworkAddressEntry:: isLifetimeKnown () const

返回 true 若地址寿命已知, false 若不。若寿命未知, preferredLifetime () 和 validityLifetime () 会返回 QDeadlineTimer::Forever .

另请参阅 preferredLifetime (), validityLifetime (), setAddressLifetime (),和 clearAddressLifetime ().

bool QNetworkAddressEntry:: isPermanent () const

返回 true if this address is permanent on this interface, false if it's temporary. A permanent address is one which has no expiration time and is often static (manually configured).

If this information could not be determined, this function returns true .

注意: Depending on the operating system and the networking configuration tool, it is possible for a temporary address to be interpreted as permanent, if the tool did not inform the details correctly to the operating system.

另请参阅 isLifetimeKnown (), validityLifetime (),和 isTemporary ().

bool QNetworkAddressEntry:: isTemporary () const

返回 true 若此地址在该接口上是临时的, false 若它是永久性的。

另请参阅 isLifetimeKnown (), validityLifetime (),和 isPermanent ().

QHostAddress QNetworkAddressEntry:: netmask () const

Returns the netmask associated with the IP address. The netmask is expressed in the form of an IP address, such as 255.255.0.0.

For IPv6 addresses, the prefix length is converted to an address where the number of bits set to 1 is equal to the prefix length. For a prefix length of 64 bits (the most common value), the netmask will be expressed as a QHostAddress holding the address FFFF:FFFF:FFFF:FFFF::

另请参阅 setNetmask () 和 prefixLength ().

QDeadlineTimer QNetworkAddressEntry:: preferredLifetime () const

Returns the deadline when this address becomes deprecated (no longer preferred), if known. If the address lifetime is not known (see isLifetimeKnown ()), this function always returns QDeadlineTimer::Forever .

While an address is preferred, it may be used by the operating system as the source address for new, outgoing packets. After it becomes deprecated, it will remain valid for incoming packets for a while longer until finally removed (see validityLifetime ()).

另请参阅 validityLifetime (), isLifetimeKnown (), setAddressLifetime (),和 clearAddressLifetime ().

int QNetworkAddressEntry:: prefixLength () const

Returns the prefix length of this IP address. The prefix length matches the number of bits set to 1 in the netmask (see netmask ()). For IPv4 addresses, the value is between 0 and 32. For IPv6 addresses, it's contained between 0 and 128 and is the preferred form of representing addresses.

This function returns -1 if the prefix length could not be determined (i.e., netmask () returns a null QHostAddress()).

另请参阅 setPrefixLength () 和 netmask ().

void QNetworkAddressEntry:: setAddressLifetime ( QDeadlineTimer preferred , QDeadlineTimer validity )

Sets both the preferred and valid lifetimes for this address to the preferred and validity deadlines, respectively. After this call, isLifetimeKnown () 会返回 true , even if both parameters are QDeadlineTimer::Forever .

另请参阅 preferredLifetime (), validityLifetime (), isLifetimeKnown (),和 clearAddressLifetime ().

void QNetworkAddressEntry:: setBroadcast (const QHostAddress & newBroadcast )

Sets the broadcast IP address of this QNetworkAddressEntry 对象到 newBroadcast .

另请参阅 broadcast ().

void QNetworkAddressEntry:: setDnsEligibility ( QNetworkAddressEntry::DnsEligibilityStatus status )

Sets the DNS eligibility flag for this address to status .

另请参阅 dnsEligibility ().

void QNetworkAddressEntry:: setIp (const QHostAddress & newIp )

Sets the IP address the QNetworkAddressEntry object contains to newIp .

另请参阅 ip ().

void QNetworkAddressEntry:: setNetmask (const QHostAddress & newNetmask )

Sets the netmask that this QNetworkAddressEntry object contains to newNetmask . Setting the netmask also sets the prefix length to match the new netmask.

另请参阅 netmask () 和 setPrefixLength ().

void QNetworkAddressEntry:: setPrefixLength ( int length )

Sets the prefix length of this IP address to length . The value of length must be valid for this type of IP address: between 0 and 32 for IPv4 addresses, between 0 and 128 for IPv6 addresses. Setting to any invalid value is equivalent to setting to -1, which means "no prefix length".

Setting the prefix length also sets the netmask (see netmask ()).

另请参阅 prefixLength () 和 setNetmask ().

[noexcept] void QNetworkAddressEntry:: swap ( QNetworkAddressEntry & other )

Swaps this network address entry instance with other 。此函数非常快且从不失败。

QDeadlineTimer QNetworkAddressEntry:: validityLifetime () const

Returns the deadline when this address becomes invalid and will be removed from the networking stack, if known. If the address lifetime is not known (see isLifetimeKnown ()), this function always returns QDeadlineTimer::Forever .

While an address is valid, it will be accepted by the operating system as a valid destination address for this machine. Whether it is used as a source address for new, outgoing packets is controlled by, among other rules, the preferred lifetime (see preferredLifetime ()).

另请参阅 preferredLifetime (), isLifetimeKnown (), setAddressLifetime (),和 clearAddressLifetime ().

bool QNetworkAddressEntry:: operator!= (const QNetworkAddressEntry & other ) const

返回 true 若此网络地址条目不同于 other .

QNetworkAddressEntry &QNetworkAddressEntry:: operator= (const QNetworkAddressEntry & other )

Makes a copy of the QNetworkAddressEntry 对象 other .

bool QNetworkAddressEntry:: operator== (const QNetworkAddressEntry & other ) const

返回 true 若此网络地址条目等同 other .

相关非成员

[since 6.2] QDebug operator<< ( QDebug debug , const QNetworkAddressEntry & entry )

写入 QNetworkAddressEntry entry to the stream and returns a reference to the debug stream.

该函数在 Qt 6.2 引入。