diff options
Diffstat (limited to 'src/network/kernel/qhostaddress.cpp')
-rw-r--r-- | src/network/kernel/qhostaddress.cpp | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp index d775007f46..13ecfac3f5 100644 --- a/src/network/kernel/qhostaddress.cpp +++ b/src/network/kernel/qhostaddress.cpp @@ -1,31 +1,38 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtNetwork module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -108,14 +115,13 @@ public: QString ipString; QString scopeId; - quint32 a; // IPv4 address union { Q_IPV6ADDR a6; // IPv6 address struct { quint64 c[2]; } a6_64; struct { quint32 c[4]; } a6_32; }; - QAbstractSocket::NetworkLayerProtocol protocol; - + quint32 a; // IPv4 address + qint8 protocol; bool isParsed; friend class QHostAddress; @@ -694,7 +700,7 @@ quint32 QHostAddress::toIPv4Address(bool *ok) const QAbstractSocket::NetworkLayerProtocol QHostAddress::protocol() const { QT_ENSURE_PARSED(this); - return d->protocol; + return QAbstractSocket::NetworkLayerProtocol(d->protocol); } /*! @@ -730,24 +736,17 @@ Q_IPV6ADDR QHostAddress::toIPv6Address() const QString QHostAddress::toString() const { QT_ENSURE_PARSED(this); + QString s; if (d->protocol == QAbstractSocket::IPv4Protocol || d->protocol == QAbstractSocket::AnyIPProtocol) { quint32 i = toIPv4Address(); - QString s; QIPAddressUtils::toString(s, i); - return s; - } - - if (d->protocol == QAbstractSocket::IPv6Protocol) { - QString s; + } else if (d->protocol == QAbstractSocket::IPv6Protocol) { QIPAddressUtils::toString(s, d->a6.c); - if (!d->scopeId.isEmpty()) s.append(QLatin1Char('%') + d->scopeId); - return s; } - - return QString(); + return s; } /*! @@ -1016,7 +1015,7 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet) netmask = parser.prefixLength(); } else { bool ok; - netmask = subnet.mid(slash + 1).toUInt(&ok); + netmask = subnet.midRef(slash + 1).toUInt(&ok); if (!ok) return invalid; // failed to parse the subnet } @@ -1041,11 +1040,11 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet) return invalid; // invalid netmask // parse the address manually - QStringList parts = netStr.split(QLatin1Char('.')); + auto parts = netStr.splitRef(QLatin1Char('.')); if (parts.isEmpty() || parts.count() > 4) return invalid; // invalid IPv4 address - if (parts.last().isEmpty()) + if (parts.constLast().isEmpty()) parts.removeLast(); quint32 addr = 0; |