45 #include "qplatformdefs.h" 48 #ifndef QT_NO_DATASTREAM 51 #if defined(Q_OS_WINCE) 56 # include <arpa/inet.h> 61 #define QT_ENSURE_PARSED(a) \ 63 if (!(a)->d->isParsed) \ 68 # if !defined (QT_NO_IPV6) 72 #if defined(Q_OS_WINCE) 74 # define u_char unsigned char 76 # if !defined(u_short) 77 # define u_short unsigned short 80 # define u_long unsigned long 100 #define qt_sockaddr_in6 sockaddr_in6 101 #define qt_s6_addr s6_addr 110 void setAddress(
quint32 a_ = 0);
111 void setAddress(
const quint8 *a_);
131 memset(&
a6, 0,
sizeof(
a6));
143 for (
int i = 0; i < 16; i++)
160 if (ipv4.
count() != 4)
164 for (
int i = 0; i < 4; ++i) {
167 if (!ok || byteValue > 255)
171 ipv4Address += byteValue;
182 if (scopeIdPos != -1) {
183 *scopeId = tmp.
mid(scopeIdPos + 1);
190 int count = ipv6.
count();
191 if (count < 3 || count > 8)
195 if(count == 8 && colonColon > 1)
208 int fillCount = 9 - count;
209 for (
int i = count - 1; i >= 0; --i) {
214 if (i == count - 1) {
227 for (
int j = 0; j < fillCount; ++j) {
237 if (ok && byteValue <= 0xffff) {
238 addr[--mc] = byteValue & 0xff;
239 addr[--mc] = (byteValue >> 8) & 0xff;
249 addr[--mc] = maybeIp4 & 0xff;
250 addr[--mc] = (maybeIp4 >> 8) & 0xff;
251 addr[--mc] = (maybeIp4 >> 16) & 0xff;
252 addr[--mc] = (maybeIp4 >> 24) & 0xff;
295 memset(&
a6, 0,
sizeof(
a6));
308 static const quint8 zeroes[16] = { 0 };
325 memcpy(ip.v6,
d->a6.c, 16);
365 if (ptr < end && memcmp(ptr + 1, zeroes, end - ptr - 1) != 0) {
381 quint8 bytemask = 256 - (1 << (8 - (start & 7)));
382 where[start / 8] &= bytemask;
385 memset(where + (start + 7) / 8, 0, end / 8 - (start + 7) / 8);
408 }
else if (length == 32) {
411 d->a =
quint32(0xffffffff) >> (32 - length) << (32 - length);
414 memset(
d->a6.c, 0xFF,
sizeof(
d->a6));
519 if (sockaddr->sa_family == AF_INET)
520 setAddress(htonl(((sockaddr_in *)sockaddr)->sin_addr.s_addr));
522 else if (sockaddr->sa_family ==
AF_INET6)
685 if (sockaddr->sa_family == AF_INET)
686 setAddress(htonl(((sockaddr_in *)sockaddr)->sin_addr.s_addr));
688 else if (sockaddr->sa_family ==
AF_INET6)
751 s.
sprintf(
"%d.%d.%d.%d", (i>>24) & 0xff, (i>>16) & 0xff,
752 (i >> 8) & 0xff, i & 0xff);
758 for (
int i = 0; i < 8; i++) {
763 bool zeroDetected =
false;
764 bool zeroShortened =
false;
765 for (
int i = 0; i < 8; i++) {
766 if ((ugle[i] != 0) || zeroShortened) {
770 zeroShortened =
true;
773 if (i<7 && (ugle[i+1] == 0)) {
784 if (i<7 && ((ugle[i] != 0) || zeroShortened || (i==0 && zeroDetected)))
896 return int(other) == int(
Null);
991 net = subnet.
d->
a6.
c;
996 if (netmask >= 8 && memcmp(ip, net, netmask / 8) != 0)
998 if ((netmask & 7) == 0)
1002 quint8 bytemask = 256 - (1 << (8 - (netmask & 7)));
1003 quint8 ipbyte = ip[netmask / 8];
1004 quint8 netbyte = net[netmask / 8];
1005 return (ipbyte & bytemask) == (netbyte & bytemask);
1092 netmask = subnet.
mid(slash + 1).
toUInt(&ok);
1125 for (
int i = 0; i < parts.
count(); ++i) {
1128 if (!ok || byteValue > 255)
1134 addr <<= 8 * (4 - parts.
count());
1135 if (netmask == -1) {
1136 netmask = 8 * parts.
count();
1137 }
else if (netmask == 0) {
1142 }
else if (netmask != 32) {
1144 quint32 mask =
quint32(0xffffffff) >> (32 - netmask) << (32 - netmask);
1151 #ifndef QT_NO_DEBUG_STREAM 1164 #ifndef QT_NO_DATASTREAM 1190 for (
int i = 0; i < 16; ++i)
1227 for (
int i = 0; i < 16; ++i)
1243 #endif //QT_NO_DATASTREAM void setScopeId(const QString &id)
Sets the IPv6 scope ID of the address to id.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QDebug class provides an output stream for debugging information.
QString scopeId() const
Returns the scope ID of an IPv6 address.
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
bool isNull() const
Returns true if this host address is null (INADDR_ANY or in6addr_any).
Q_IPV6ADDR toIPv6Address() const
Returns the IPv6 address as a Q_IPV6ADDR structure.
QHostAddress & operator=(const QHostAddress &other)
Assigns another host address to this object, and returns a reference to this object.
#define QT_END_NAMESPACE
This macro expands to.
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QHostAddressPrivate > d
void chop(int n)
Removes n characters from the end of the string.
static void clear(QVariant::Private *d)
void removeLast()
Removes the last item in the list.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QAbstractSocket::NetworkLayerProtocol protocol
long ASN1_INTEGER_get ASN1_INTEGER * a
void setStatus(Status status)
Sets the status of the data stream to the status given.
int count(const T &t) const
Returns the number of occurrences of value in the list.
quint32 toIPv4Address() const
Returns the IPv4 address as a number.
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
QDataStream & operator>>(QDataStream &in, QHostAddress &address)
Reads a host address into address from the stream in and returns a reference to the stream...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void clear()
Sets the host address to 0.0.0.0.
uint qHash(const QHostAddress &key)
bool operator==(const QHostAddress &address) const
Returns true if this host address is the same as the other address given; otherwise returns false...
#define QT_BEGIN_NAMESPACE
This macro expands to.
void truncate(int pos)
Truncates the string at the given position index.
~QHostAddress()
Destroys the host address object.
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setAddress(quint32 a_=0)
static QPair< QHostAddress, int > parseSubnet(const QString &subnet)
Parses the IP and subnet information contained in subnet and returns the network prefix for that netw...
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString toString() const
Returns the address as a string.
const T * ptr(const T &t)
QDebug & maybeSpace()
Writes a space character to the debug stream, depending on the last character sent to the stream...
static bool parseIp4(const QString &address, quint32 *addr)
static bool parseIp6(const QString &address, quint8 *addr, QString *scopeId)
bool isInSubnet(const QHostAddress &subnet, int netmask) const
Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask...
QHostAddress()
Constructs a host address object with the IP address 0.0.0.0.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
QString & append(QChar c)
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
#define QT_ENSURE_PARSED(a)
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
void clear()
Clears the contents of the string and makes it empty.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QDataStream & operator<<(QDataStream &out, const QHostAddress &address)
Writes host address address to the stream out and returns a reference to the stream.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
T & last()
Returns a reference to the last item in the list.
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
static void clearBits(quint8 *where, int start, int end)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
The QDataStream class provides serialization of binary data to a QIODevice.
The QHostAddress class provides an IP address.
void setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int len)
static const KeyPair *const end
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
The QAbstractSocket class provides the base functionality common to all socket types.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool setAddress(const QString &address)