Qt 4.8
qhostaddress.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 <QtCore/qscopedpointer.h>
48 #include <QtNetwork/qabstractsocket.h>
49 
50 struct sockaddr;
51 
53 
55 
56 QT_MODULE(Network)
57 
59 
61 {
62 public:
63  inline quint8 &operator [](int index) { return c[index]; }
64  inline quint8 operator [](int index) const { return c[index]; }
65  quint8 c[16];
66 };
67 
69 
71 {
72 public:
78  Any,
79  AnyIPv6
80  };
81 
82  QHostAddress();
83  explicit QHostAddress(quint32 ip4Addr);
84  explicit QHostAddress(quint8 *ip6Addr);
85  explicit QHostAddress(const Q_IPV6ADDR &ip6Addr);
86  explicit QHostAddress(const sockaddr *sockaddr);
87  explicit QHostAddress(const QString &address);
88  QHostAddress(const QHostAddress &copy);
90  ~QHostAddress();
91 
92  QHostAddress &operator=(const QHostAddress &other);
93  QHostAddress &operator=(const QString &address);
94 
95  void setAddress(quint32 ip4Addr);
96  void setAddress(quint8 *ip6Addr);
97  void setAddress(const Q_IPV6ADDR &ip6Addr);
98  void setAddress(const sockaddr *sockaddr);
99  bool setAddress(const QString &address);
100 
101  QAbstractSocket::NetworkLayerProtocol protocol() const;
102  quint32 toIPv4Address() const;
103  Q_IPV6ADDR toIPv6Address() const;
104 
105  QString toString() const;
106 
107  QString scopeId() const;
108  void setScopeId(const QString &id);
109 
110  bool operator ==(const QHostAddress &address) const;
111  bool operator ==(SpecialAddress address) const;
112  inline bool operator !=(const QHostAddress &address) const
113  { return !operator==(address); }
114  inline bool operator !=(SpecialAddress address) const
115  { return !operator==(address); }
116  bool isNull() const;
117  void clear();
118 
119 #ifdef QT3_SUPPORT
120  inline QT3_SUPPORT quint32 ip4Addr() const { return toIPv4Address(); }
121  inline QT3_SUPPORT bool isIPv4Address() const { return protocol() == QAbstractSocket::IPv4Protocol
123  inline QT3_SUPPORT bool isIp4Addr() const { return protocol() == QAbstractSocket::IPv4Protocol
125  inline QT3_SUPPORT bool isIPv6Address() const { return protocol() == QAbstractSocket::IPv6Protocol; }
126 #endif
127 
128  bool isInSubnet(const QHostAddress &subnet, int netmask) const;
129  bool isInSubnet(const QPair<QHostAddress, int> &subnet) const;
130 
131  static QPair<QHostAddress, int> parseSubnet(const QString &subnet);
132 
133 protected:
135 };
136 
137 inline bool operator ==(QHostAddress::SpecialAddress address1, const QHostAddress &address2)
138 { return address2 == address1; }
139 
140 #ifndef QT_NO_DEBUG_STREAM
142 #endif
143 
144 
146 
147 #ifndef QT_NO_DATASTREAM
150 #endif
151 
153 
155 #endif // QHOSTADDRESS_H
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
Q_NETWORK_EXPORT QDataStream & operator>>(QDataStream &, QHostAddress &)
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QScopedPointer< QHostAddressPrivate > d
Definition: qhostaddress.h:134
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
unsigned char quint8
Definition: qglobal.h:934
bool operator!=(QBool b1, bool b2)
Definition: qglobal.h:2026
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool operator==(QHostAddress::SpecialAddress address1, const QHostAddress &address2)
Definition: qhostaddress.h:137
static QString toString(Register *reg, int type, bool *ok=0)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
unsigned int uint
Definition: qglobal.h:996
QIPv6Address Q_IPV6ADDR
Definition: qhostaddress.h:68
Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QHostAddress &)
#define Q_NETWORK_EXPORT
Definition: qglobal.h:1452
int key
unsigned int quint32
Definition: qglobal.h:938
quint16 index
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
#define QT_END_HEADER
Definition: qglobal.h:137
Q_NETWORK_EXPORT uint qHash(const QHostAddress &key)
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300