Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QNetworkAddressEntry Class Reference

The QNetworkAddressEntry class stores one IP address supported by a network interface, along with its associated netmask and broadcast address. More...

#include <qnetworkinterface.h>

+ Collaboration diagram for QNetworkAddressEntry:

Public Types

enum  DnsEligibilityStatus : qint8 { DnsEligibilityUnknown = -1 , DnsIneligible = 0 , DnsEligible = 1 }
 

Public Member Functions

 QNetworkAddressEntry ()
 Constructs an empty QNetworkAddressEntry object.
 
 QNetworkAddressEntry (const QNetworkAddressEntry &other)
 Constructs a QNetworkAddressEntry object that is a copy of the object other.
 
QNetworkAddressEntryoperator= (QNetworkAddressEntry &&other) noexcept
 
QNetworkAddressEntryoperator= (const QNetworkAddressEntry &other)
 Makes a copy of the QNetworkAddressEntry object other.
 
 ~QNetworkAddressEntry ()
 Destroys this QNetworkAddressEntry object.
 
void swap (QNetworkAddressEntry &other) noexcept
 
bool operator== (const QNetworkAddressEntry &other) const
 Returns true if this network address entry is the same as other.
 
bool operator!= (const QNetworkAddressEntry &other) const
 Returns true if this network address entry is different from other.
 
DnsEligibilityStatus dnsEligibility () const
 
void setDnsEligibility (DnsEligibilityStatus status)
 
QHostAddress ip () const
 This function returns one IPv4 or IPv6 address found, that was found in a network interface.
 
void setIp (const QHostAddress &newIp)
 Sets the IP address the QNetworkAddressEntry object contains to newIp.
 
QHostAddress netmask () const
 Returns the netmask associated with the IP address.
 
void setNetmask (const QHostAddress &newNetmask)
 Sets the netmask that this QNetworkAddressEntry object contains to newNetmask.
 
int prefixLength () const
 
void setPrefixLength (int length)
 
QHostAddress broadcast () const
 Returns the broadcast address associated with the IPv4 address and netmask.
 
void setBroadcast (const QHostAddress &newBroadcast)
 Sets the broadcast IP address of this QNetworkAddressEntry object to newBroadcast.
 
bool isLifetimeKnown () const
 
QDeadlineTimer preferredLifetime () const
 
QDeadlineTimer validityLifetime () const
 
void setAddressLifetime (QDeadlineTimer preferred, QDeadlineTimer validity)
 
void clearAddressLifetime ()
 
bool isPermanent () const
 
bool isTemporary () const
 

Related Symbols

(Note that these are not member symbols.)

QDebug operator<< (QDebug debug, const QNetworkAddressEntry &entry)
 

Detailed Description

The QNetworkAddressEntry class stores one IP address supported by a network interface, along with its associated netmask and broadcast address.

Since
4.2 \reentrant

\inmodule QtNetwork

Each network interface can contain zero or more IP addresses, which in turn can be associated with a netmask and/or a broadcast address (depending on support from the operating system).

This class represents one such group.

Definition at line 21 of file qnetworkinterface.h.

Member Enumeration Documentation

◆ DnsEligibilityStatus

Since
5.11

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.

\value DnsEligibilityUnknown 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. \value DnsEligible This address is eligible for publication in DNS. \value DnsIneligible 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.

See also
dnsEligibility(), setDnsEligibility()
Enumerator
DnsEligibilityUnknown 
DnsIneligible 
DnsEligible 

Definition at line 24 of file qnetworkinterface.h.

Constructor & Destructor Documentation

◆ QNetworkAddressEntry() [1/2]

QNetworkAddressEntry::QNetworkAddressEntry ( )

Constructs an empty QNetworkAddressEntry object.

Definition at line 167 of file qnetworkinterface.cpp.

◆ QNetworkAddressEntry() [2/2]

QNetworkAddressEntry::QNetworkAddressEntry ( const QNetworkAddressEntry & other)

Constructs a QNetworkAddressEntry object that is a copy of the object other.

Definition at line 176 of file qnetworkinterface.cpp.

◆ ~QNetworkAddressEntry()

QNetworkAddressEntry::~QNetworkAddressEntry ( )

Destroys this QNetworkAddressEntry object.

Definition at line 201 of file qnetworkinterface.cpp.

Member Function Documentation

◆ broadcast()

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).

Definition at line 359 of file qnetworkinterface.cpp.

◆ clearAddressLifetime()

void QNetworkAddressEntry::clearAddressLifetime ( )
Since
5.11

Resets both the preferred and valid lifetimes for this address. After this call, isLifetimeKnown() will return false.

See also
preferredLifetime(), validityLifetime(), isLifetimeKnown(), setAddressLifetime()

Definition at line 451 of file qnetworkinterface.cpp.

References QDeadlineTimer::Forever.

◆ dnsEligibility()

QNetworkAddressEntry::DnsEligibilityStatus QNetworkAddressEntry::dnsEligibility ( ) const
Since
5.11

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.

On some systems, QNetworkInterface will need to heuristically determine which addresses are eligible.

See also
isLifetimeKnown(), isPermanent(), setDnsEligibility()

Definition at line 234 of file qnetworkinterface.cpp.

◆ ip()

QHostAddress QNetworkAddressEntry::ip ( ) const

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

Definition at line 262 of file qnetworkinterface.cpp.

Referenced by setNetmask().

+ Here is the caller graph for this function:

◆ isLifetimeKnown()

bool QNetworkAddressEntry::isLifetimeKnown ( ) const
Since
5.11

Returns true if the address lifetime is known, false if not. If the lifetime is not known, both preferredLifetime() and validityLifetime() will return QDeadlineTimer::Forever.

See also
preferredLifetime(), validityLifetime(), setAddressLifetime(), clearAddressLifetime()

Definition at line 382 of file qnetworkinterface.cpp.

◆ isPermanent()

bool QNetworkAddressEntry::isPermanent ( ) const
Since
5.11

Returns 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.

Note
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.
See also
isLifetimeKnown(), validityLifetime(), isTemporary()

Definition at line 474 of file qnetworkinterface.cpp.

◆ isTemporary()

bool QNetworkAddressEntry::isTemporary ( ) const
inline
Since
5.11

Returns true if this address is temporary on this interface, false if it's permanent.

See also
isLifetimeKnown(), validityLifetime(), isPermanent()

Definition at line 62 of file qnetworkinterface.h.

◆ netmask()

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::

See also
prefixLength()

Definition at line 289 of file qnetworkinterface.cpp.

◆ operator!=()

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

Returns true if this network address entry is different from other.

Definition at line 39 of file qnetworkinterface.h.

References other().

+ Here is the call graph for this function:

◆ operator=() [1/2]

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

Makes a copy of the QNetworkAddressEntry object other.

Definition at line 184 of file qnetworkinterface.cpp.

References other().

+ Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 32 of file qnetworkinterface.h.

References other(), and swap().

+ Here is the call graph for this function:

◆ operator==()

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

Returns true if this network address entry is the same as other.

Definition at line 209 of file qnetworkinterface.cpp.

References other().

+ Here is the call graph for this function:

◆ preferredLifetime()

QDeadlineTimer QNetworkAddressEntry::preferredLifetime ( ) const
Since
5.11

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()).

See also
validityLifetime(), isLifetimeKnown(), setAddressLifetime(), clearAddressLifetime()

Definition at line 401 of file qnetworkinterface.cpp.

◆ prefixLength()

int QNetworkAddressEntry::prefixLength ( ) const
Since
4.5 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()).

See also
netmask()

Definition at line 324 of file qnetworkinterface.cpp.

◆ setAddressLifetime()

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

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

See also
preferredLifetime(), validityLifetime(), isLifetimeKnown(), clearAddressLifetime()

Definition at line 436 of file qnetworkinterface.cpp.

◆ setBroadcast()

void QNetworkAddressEntry::setBroadcast ( const QHostAddress & newBroadcast)

Sets the broadcast IP address of this QNetworkAddressEntry object to newBroadcast.

Definition at line 368 of file qnetworkinterface.cpp.

◆ setDnsEligibility()

void QNetworkAddressEntry::setDnsEligibility ( DnsEligibilityStatus status)
Since
5.11

Sets the DNS eligibility flag for this address to status.

See also
dnsEligibility()

Definition at line 246 of file qnetworkinterface.cpp.

◆ setIp()

void QNetworkAddressEntry::setIp ( const QHostAddress & newIp)

Sets the IP address the QNetworkAddressEntry object contains to newIp.

Definition at line 271 of file qnetworkinterface.cpp.

Referenced by interfaceListing().

+ Here is the caller graph for this function:

◆ setNetmask()

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.

See also
setPrefixLength()

Definition at line 301 of file qnetworkinterface.cpp.

References ip().

+ Here is the call graph for this function:

◆ setPrefixLength()

void QNetworkAddressEntry::setPrefixLength ( int length)
Since
4.5 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()).

See also
setNetmask()

Definition at line 341 of file qnetworkinterface.cpp.

◆ swap()

void QNetworkAddressEntry::swap ( QNetworkAddressEntry & other)
inlinenoexcept
Since
5.0

Swaps this network address entry instance with other. This function is very fast and never fails.

Definition at line 36 of file qnetworkinterface.h.

References d, and other().

+ Here is the call graph for this function:

◆ validityLifetime()

QDeadlineTimer QNetworkAddressEntry::validityLifetime ( ) const
Since
5.11

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()).

See also
preferredLifetime(), isLifetimeKnown(), setAddressLifetime(), clearAddressLifetime()

Definition at line 421 of file qnetworkinterface.cpp.

Friends And Related Symbol Documentation

◆ operator<<()

QDebug operator<< ( QDebug debug,
const QNetworkAddressEntry & entry )
related
Since
6.2

Writes the QNetworkAddressEntry entry to the stream and returns a reference to the debug stream.

Definition at line 909 of file qnetworkinterface.cpp.

References debug.


The documentation for this class was generated from the following files: