| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QHOSTADDRESS_H
|
|---|
| 43 | #define QHOSTADDRESS_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qpair.h>
|
|---|
| 46 | #include <QtCore/qstring.h>
|
|---|
| 47 | #include <QtNetwork/qabstractsocket.h>
|
|---|
| 48 |
|
|---|
| 49 | struct sockaddr;
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_HEADER
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | QT_MODULE(Network)
|
|---|
| 56 |
|
|---|
| 57 | class QHostAddressPrivate;
|
|---|
| 58 |
|
|---|
| 59 | class Q_NETWORK_EXPORT QIPv6Address
|
|---|
| 60 | {
|
|---|
| 61 | public:
|
|---|
| 62 | inline quint8 &operator [](int index) { return c[index]; }
|
|---|
| 63 | inline quint8 operator [](int index) const { return c[index]; }
|
|---|
| 64 | quint8 c[16];
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | typedef QIPv6Address Q_IPV6ADDR;
|
|---|
| 68 |
|
|---|
| 69 | class Q_NETWORK_EXPORT QHostAddress
|
|---|
| 70 | {
|
|---|
| 71 | public:
|
|---|
| 72 | enum SpecialAddress {
|
|---|
| 73 | Null,
|
|---|
| 74 | Broadcast,
|
|---|
| 75 | LocalHost,
|
|---|
| 76 | LocalHostIPv6,
|
|---|
| 77 | Any,
|
|---|
| 78 | AnyIPv6
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | QHostAddress();
|
|---|
| 82 | explicit QHostAddress(quint32 ip4Addr);
|
|---|
| 83 | explicit QHostAddress(quint8 *ip6Addr);
|
|---|
| 84 | explicit QHostAddress(const Q_IPV6ADDR &ip6Addr);
|
|---|
| 85 | explicit QHostAddress(const sockaddr *sockaddr);
|
|---|
| 86 | explicit QHostAddress(const QString &address);
|
|---|
| 87 | QHostAddress(const QHostAddress ©);
|
|---|
| 88 | QHostAddress(SpecialAddress address);
|
|---|
| 89 | ~QHostAddress();
|
|---|
| 90 |
|
|---|
| 91 | QHostAddress &operator=(const QHostAddress &other);
|
|---|
| 92 | QHostAddress &operator=(const QString &address);
|
|---|
| 93 |
|
|---|
| 94 | void setAddress(quint32 ip4Addr);
|
|---|
| 95 | void setAddress(quint8 *ip6Addr);
|
|---|
| 96 | void setAddress(const Q_IPV6ADDR &ip6Addr);
|
|---|
| 97 | void setAddress(const sockaddr *sockaddr);
|
|---|
| 98 | bool setAddress(const QString &address);
|
|---|
| 99 |
|
|---|
| 100 | QAbstractSocket::NetworkLayerProtocol protocol() const;
|
|---|
| 101 | quint32 toIPv4Address() const;
|
|---|
| 102 | Q_IPV6ADDR toIPv6Address() const;
|
|---|
| 103 |
|
|---|
| 104 | QString toString() const;
|
|---|
| 105 |
|
|---|
| 106 | QString scopeId() const;
|
|---|
| 107 | void setScopeId(const QString &id);
|
|---|
| 108 |
|
|---|
| 109 | bool operator ==(const QHostAddress &address) const;
|
|---|
| 110 | bool operator ==(SpecialAddress address) const;
|
|---|
| 111 | inline bool operator !=(const QHostAddress &address) const
|
|---|
| 112 | { return !operator==(address); }
|
|---|
| 113 | inline bool operator !=(SpecialAddress address) const
|
|---|
| 114 | { return !operator==(address); }
|
|---|
| 115 | bool isNull() const;
|
|---|
| 116 | void clear();
|
|---|
| 117 |
|
|---|
| 118 | #ifdef QT3_SUPPORT
|
|---|
| 119 | inline QT3_SUPPORT quint32 ip4Addr() const { return toIPv4Address(); }
|
|---|
| 120 | inline QT3_SUPPORT bool isIPv4Address() const { return protocol() == QAbstractSocket::IPv4Protocol
|
|---|
| 121 | || protocol() == QAbstractSocket::UnknownNetworkLayerProtocol; }
|
|---|
| 122 | inline QT3_SUPPORT bool isIp4Addr() const { return protocol() == QAbstractSocket::IPv4Protocol
|
|---|
| 123 | || protocol() == QAbstractSocket::UnknownNetworkLayerProtocol; }
|
|---|
| 124 | inline QT3_SUPPORT bool isIPv6Address() const { return protocol() == QAbstractSocket::IPv6Protocol; }
|
|---|
| 125 | #endif
|
|---|
| 126 |
|
|---|
| 127 | bool isInSubnet(const QHostAddress &subnet, int netmask) const;
|
|---|
| 128 | bool isInSubnet(const QPair<QHostAddress, int> &subnet) const;
|
|---|
| 129 |
|
|---|
| 130 | static QPair<QHostAddress, int> parseSubnet(const QString &subnet);
|
|---|
| 131 |
|
|---|
| 132 | protected:
|
|---|
| 133 | QHostAddressPrivate *d;
|
|---|
| 134 | };
|
|---|
| 135 |
|
|---|
| 136 | inline bool operator ==(QHostAddress::SpecialAddress address1, const QHostAddress &address2)
|
|---|
| 137 | { return address2 == address1; }
|
|---|
| 138 |
|
|---|
| 139 | #ifndef QT_NO_DEBUG_STREAM
|
|---|
| 140 | Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QHostAddress &);
|
|---|
| 141 | #endif
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | Q_NETWORK_EXPORT uint qHash(const QHostAddress &key);
|
|---|
| 145 |
|
|---|
| 146 | #ifndef QT_NO_DATASTREAM
|
|---|
| 147 | Q_NETWORK_EXPORT QDataStream &operator<<(QDataStream &, const QHostAddress &);
|
|---|
| 148 | Q_NETWORK_EXPORT QDataStream &operator>>(QDataStream &, QHostAddress &);
|
|---|
| 149 | #endif
|
|---|
| 150 |
|
|---|
| 151 | QT_END_NAMESPACE
|
|---|
| 152 |
|
|---|
| 153 | QT_END_HEADER
|
|---|
| 154 | #endif // QHOSTADDRESS_H
|
|---|