diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/network/kernel/qhostaddress.cpp | 22 | ||||
-rw-r--r-- | src/network/kernel/qhostaddress.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp index d66d471206..cbd804c44b 100644 --- a/src/network/kernel/qhostaddress.cpp +++ b/src/network/kernel/qhostaddress.cpp @@ -1109,6 +1109,28 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet) return qMakePair(QHostAddress(addr), netmask); } +/*! + \since 5.0 + + returns true if the address is the IPv6 loopback address, or any + of the IPv4 loopback addresses. +*/ +bool QHostAddress::isLoopback() const +{ + QT_ENSURE_PARSED(this); + if ((d->a & 0xFF000000) == 0x7F000000) + return true; // v4 range (including IPv6 wrapped IPv4 addresses) + if (d->protocol == QAbstractSocket::IPv6Protocol) { + if (d->a6.c[15] != 1) + return false; + for (int i = 0; i < 15; i++) + if (d->a6[i] != 0) + return false; + return true; + } + return false; +} + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug d, const QHostAddress &address) { diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h index 3d364de6e6..83e8a7ce3c 100644 --- a/src/network/kernel/qhostaddress.h +++ b/src/network/kernel/qhostaddress.h @@ -120,6 +120,8 @@ public: bool isInSubnet(const QHostAddress &subnet, int netmask) const; bool isInSubnet(const QPair<QHostAddress, int> &subnet) const; + bool isLoopback() const; + static QPair<QHostAddress, int> parseSubnet(const QString &subnet); protected: |