43 #include "private/qipaddress_p.h"
46 # include <winsock2.h>
47 # include <ws2tcpip.h>
49 # include <netinet/in.h>
51 #include "qplatformdefs.h"
54 #ifndef QT_NO_DATASTREAM
58 # include <private/qsimd_p.h>
62 # include <arpa/inet.h>
70 memset(&
a6, 0,
sizeof(
a6));
96 if (qFromUnaligned<quint64>(ptr) != 0)
99 const quint32 mid = qFromBigEndian<quint32>(ptr + 8);
101 a = qFromBigEndian<quint32>(ptr + 12);
107 const quint32 low = qFromBigEndian<quint32>(ptr + 12);
126 memcpy(
a6.
c, a_,
sizeof(
a6));
140 int scopeIdPos = tmp.lastIndexOf(
QLatin1Char(
'%'));
141 if (scopeIdPos != -1) {
142 *scopeId = tmp.
mid(scopeIdPos + 1).toString();
143 tmp.
chop(tmp.size() - scopeIdPos);
160 if (parseIp6(
a, maybeIp6, &
scopeId)) {
179 memset(&
a6, 0,
sizeof(
a6));
190 if ((
a & 0xff000000U) == 0x7f000000U)
192 if ((
a & 0xf0000000U) == 0xe0000000U)
194 if ((
a & 0xffff0000U) == 0xa9fe0000U)
196 if ((
a & 0xff000000U) == 0)
198 if ((
a & 0xf0000000U) == 0xf0000000U) {
199 if (
a == 0xffffffffU)
213 switch (high16 >> 8) {
217 switch (high16 & 0xffc0) {
238 if (low64 >> 32 == 0xffff) {
254 static const quint8 zeroes[16] = { 0 };
269 memcpy(ip.v6,
address.toIPv6Address().c, 16);
313 if (ptr <
end && memcmp(ptr + 1, zeroes,
end - ptr - 1) != 0)
328 where[
start / 8] &= bytemask;
331 memset(where + (
start + 7) / 8, 0,
end / 8 - (
start + 7) / 8);
350 memset(a6.
c, 0xFF,
sizeof(a6));
470 if (sockaddr->sa_family == AF_INET)
471 setAddress(htonl(((
const sockaddr_in *)sockaddr)->sin_addr.s_addr));
472 else if (sockaddr->sa_family ==
AF_INET6)
473 setAddress(((
const sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr);
619 if (sockaddr->sa_family == AF_INET)
620 setAddress(htonl(((
const sockaddr_in *)sockaddr)->sin_addr.s_addr));
621 else if (sockaddr->sa_family ==
AF_INET6)
622 setAddress(((
const sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr);
636 memset(&ip6, 0,
sizeof ip6);
644 ip4 = INADDR_BROADCAST;
647 ip4 = INADDR_LOOPBACK;
835 switch (
other.d->protocol) {
840 return convertToIpv4(a4,
other.d->a6,
mode) && (a4 ==
d->
a);
849 switch (
other.d->protocol) {
852 return convertToIpv4(a4,
d->
a6,
mode) && (a4 ==
other.d->a);
857 && (
other.d->a6_64.c[0] == 0) && (
other.d->a6_64.c[1] == 0);
865 switch (
other.d->protocol) {
867 return other.d->a == 0;
869 return (
other.d->a6_64.c[0] == 0) && (
other.d->a6_64.c[1] == 0);
890 ip4 = INADDR_BROADCAST;
894 ip4 = INADDR_LOOPBACK;
969 net = subnet.
d->
a6.
c;
974 if (netmask >= 8 && memcmp(ip, net, netmask / 8) != 0)
976 if ((netmask & 7) == 0)
980 quint8 bytemask = 256 - (1 << (8 - (netmask & 7)));
981 quint8 ipbyte = ip[netmask / 8];
982 quint8 netbyte = net[netmask / 8];
983 return (ipbyte & bytemask) == (netbyte & bytemask);
997 return isInSubnet(subnet.first, subnet.second);
1060 if (!
mask.setAddress(subnet.
mid(slash + 1)))
1064 netmask =
parser.prefixLength();
1084 clearBits(net.
d->
a6.
c, netmask, 128);
1093 if (parts.isEmpty() || parts.count() > 4)
1096 if (parts.constLast().isEmpty())
1100 for (
int i = 0;
i < parts.count(); ++
i) {
1102 uint byteValue = parts.at(
i).toUInt(&
ok);
1103 if (!
ok || byteValue > 255)
1109 addr <<= 8 * (4 - parts.count());
1110 if (netmask == -1) {
1111 netmask = 8 * parts.count();
1112 }
else if (netmask == 0) {
1117 }
else if (netmask != 32) {
1251 #ifndef QT_NO_DEBUG_STREAM
1255 d.resetFormat().nospace();
1257 d <<
"QHostAddress(QHostAddress::Any)";
1259 d <<
"QHostAddress(" <<
address.toString() <<
')';
1293 #ifndef QT_NO_DATASTREAM
1317 for (
int i = 0;
i < 16; ++
i)
1351 for (
int i = 0;
i < 16; ++
i)
1374 #include "moc_qhostaddress.cpp"
small capitals from c petite p scientific i
[1]
The QDataStream class provides serialization of binary data to a QIODevice.
operator<<(QDataStream &ds, qfloat16 f)
The QDebug class provides an output stream for debugging information.
Convenience class for custom QDebug operators.
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
size_t qHashBits(const void *p, size_t len, size_t seed=0)
The QHostAddress class provides an IP address.\inmodule QtNetwork.
QExplicitlySharedDataPointer< QHostAddressPrivate > d
@ ConvertUnspecifiedAddress
quint32 toIPv4Address(bool *ok=nullptr) const
bool isUniqueLocalUnicast() const
QHostAddress & operator=(QHostAddress &&other) noexcept
QDataStream & operator<<(QDataStream &out, const QHostAddress &address)
bool operator==(const QHostAddress &address) const
QDataStream & operator>>(QDataStream &in, QHostAddress &address)
bool isInSubnet(const QHostAddress &subnet, int netmask) const
void setAddress(quint32 ip4Addr)
static QPair< QHostAddress, int > parseSubnet(const QString &subnet)
Q_IPV6ADDR toIPv6Address() const
@ UnknownNetworkLayerProtocol
bool isEqual(const QHostAddress &address, ConversionMode mode=TolerantConversion) const
void setScopeId(const QString &id)
NetworkLayerProtocol protocol() const
void setAddress(quint32 a_=0)
bool parse(const QString &ipString)
AddressClassification classify() const
struct QHostAddressPrivate::@711::@714 a6_32
struct QHostAddressPrivate::@711::@713 a6_64
void removeLast() noexcept
bool setAddress(const QHostAddress &address)
QHostAddress address(QAbstractSocket::NetworkLayerProtocol protocol) const
The QString class provides a Unicode character string.
uint toUInt(bool *ok=nullptr, int base=10) const
QString mid(qsizetype position, qsizetype n=-1) const
QString simplified() const &
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr void truncate(qsizetype n) noexcept
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
void toString(QString &appendTo, IPv4Address address)
bool parseIp4(IPv4Address &address, const QChar *begin, const QChar *end)
const QChar * parseIp6(IPv6Address &address, const QChar *begin, const QChar *end)
std::pair< T1, T2 > QPair
constexpr T qToBigEndian(T source)
constexpr T qFromBigEndian(T source)
QT_BEGIN_INCLUDE_NAMESPACE typedef unsigned char uchar
unsigned long long quint64
QT_BEGIN_NAMESPACE typedef signed char qint8
GLenum GLuint GLenum GLsizei length
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLuint GLuint64EXT address
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
QTextStream out(stdout)
[7]
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QThreadStorage< int * > dummy[8]