summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-08-09 23:57:44 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-10-14 02:13:51 +0000
commit0a98f790bf59bc66722a645d89c560771da7efb2 (patch)
tree0cb5960d09e43ce05920d8f74082227eb8b2762c /src
parent28a6529c2a6b6a0e350037a712511d5bc822e70c (diff)
QNetworkInterface: don't include addresses from inactive interfaces
Incidentally, we can fix a typo. [ChangeLog][QtNetwork][QNetworkInterface] Changed allAddresses() to not include addresses found in inactive interfaces, matching the user expectations of this function. If those addresses are needed for some purpose, the application will need to call allInterfaces() and obtain the addresses in each interface. Task-number: QTBUG-51922 Change-Id: Iaf4157b7efa2416d898cfffd14d969c963ec0a2a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/network/kernel/qnetworkinterface.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index 2c28ae9ed9..3857ff87b9 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -355,9 +355,9 @@ void QNetworkAddressEntry::setBroadcast(const QHostAddress &newBroadcast)
contain zero or more IP addresses, each of which is optionally
associated with a netmask and/or a broadcast address. The list of
such trios can be obtained with addressEntries(). Alternatively,
- when the netmask or the broadcast addresses aren't necessary, use
- the allAddresses() convenience function to obtain just the IP
- addresses.
+ when the netmask or the broadcast addresses or other information aren't
+ necessary, use the allAddresses() convenience function to obtain just the
+ IP addresses of the active interfaces.
QNetworkInterface also reports the interface's hardware address with
hardwareAddress().
@@ -516,9 +516,9 @@ QString QNetworkInterface::hardwareAddress() const
Returns the list of IP addresses that this interface possesses
along with their associated netmasks and broadcast addresses.
- If the netmask or broadcast address information is not necessary,
- you can call the allAddresses() function to obtain just the IP
- addresses.
+ If the netmask or broadcast address or other information is not necessary,
+ you can call the allAddresses() function to obtain just the IP addresses of
+ the active interfaces.
*/
QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const
{
@@ -624,16 +624,21 @@ QList<QNetworkInterface> QNetworkInterface::allInterfaces()
}
/*!
- This convenience function returns all IP addresses found on the
- host machine. It is equivalent to calling addressEntries() on all the
- objects returned by allInterfaces() to obtain lists of QHostAddress
- objects then calling QHostAddress::ip() on each of these.
+ This convenience function returns all IP addresses found on the host
+ machine. It is equivalent to calling addressEntries() on all the objects
+ returned by allInterfaces() that are in the QNetworkInterface::IsUp state
+ to obtain lists of QNetworkAddressEntry objects then calling
+ QNetworkAddressEntry::ip() on each of these.
*/
QList<QHostAddress> QNetworkInterface::allAddresses()
{
const QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
QList<QHostAddress> result;
for (const auto &p : privs) {
+ // skip addresses if the interface isn't up
+ if ((p->flags & QNetworkInterface::IsUp) == 0)
+ continue;
+
for (const QNetworkAddressEntry &entry : qAsConst(p->addressEntries))
result += entry.ip();
}