7#include "private/qipaddress_p.h"
13# include <netinet/in.h>
15#include "qplatformdefs.h"
18#ifndef QT_NO_DATASTREAM
22# include <private/qsimd_p.h>
26# include <arpa/inet.h>
34 memset(&
a6, 0,
sizeof(
a6));
60 if (qFromUnaligned<quint64>(
ptr) != 0)
63 const quint32 mid = qFromBigEndian<quint32>(
ptr + 8);
65 a = qFromBigEndian<quint32>(
ptr + 12);
71 const quint32 low = qFromBigEndian<quint32>(
ptr + 12);
90 memcpy(
a6.c, a_,
sizeof(
a6));
105 if (scopeIdPos != -1) {
106 *scopeId = tmp.
mid(scopeIdPos + 1).toString();
122 if (
a.contains(u
':')) {
143 memset(&
a6, 0,
sizeof(
a6));
154 if ((
a & 0xff000000U) == 0x7f000000U)
156 if ((
a & 0xf0000000U) == 0xe0000000U)
158 if ((
a & 0xffff0000U) == 0xa9fe0000U)
160 if ((
a & 0xff000000U) == 0)
162 if ((
a & 0xf0000000U) == 0xf0000000U) {
163 if (
a == 0xffffffffU)
167 if (((
a & 0xff000000U) == 0x0a000000U)
168 || ((
a & 0xfff00000U) == 0xac100000U)
169 || ((
a & 0xffff0000U) == 0xc0a80000U))
181 switch (high16 >> 8) {
185 switch (high16 & 0xffc0) {
206 if (low64 >> 32 == 0xffff) {
222 static const quint8 zeroes[16] = { 0 };
237 memcpy(ip.v6,
address.toIPv6Address().c, 16);
296 where[
start / 8] &= bytemask;
299 memset(where + (
start + 7) / 8, 0,
end / 8 - (
start + 7) / 8);
318 memset(a6.c, 0xFF,
sizeof(a6));
438 if (sockaddr->sa_family == AF_INET)
439 setAddress(htonl(((
const sockaddr_in *)sockaddr)->sin_addr.s_addr));
440 else if (sockaddr->sa_family ==
AF_INET6)
441 setAddress(((
const sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr);
587 if (sockaddr->sa_family == AF_INET)
588 setAddress(htonl(((
const sockaddr_in *)sockaddr)->sin_addr.s_addr));
589 else if (sockaddr->sa_family ==
AF_INET6)
590 setAddress(((
const sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr);
604 memset(&ip6, 0,
sizeof ip6);
612 ip4 = INADDR_BROADCAST;
615 ip4 = INADDR_LOOPBACK;
803 switch (
other.d->protocol) {
817 switch (
other.d->protocol) {
833 switch (
other.d->protocol) {
835 return other.d->a == 0;
837 return (
other.d->a6_64.c[0] == 0) && (
other.d->a6_64.c[1] == 0);
858 ip4 = INADDR_BROADCAST;
862 ip4 = INADDR_LOOPBACK;
917 if (subnet.protocol() !=
d->
protocol || netmask < 0)
937 net = subnet.d->a6.c;
942 if (netmask >= 8 && memcmp(ip, net, netmask / 8) != 0)
944 if ((netmask & 7) == 0)
948 quint8 bytemask = 256 - (1 << (8 - (netmask & 7)));
949 quint8 ipbyte = ip[netmask / 8];
950 quint8 netbyte = net[netmask / 8];
951 return (ipbyte & bytemask) == (netbyte & bytemask);
965 return isInSubnet(subnet.first, subnet.second);
1011 if (subnet.isEmpty())
1017 netStr.truncate(slash);
1020 bool isIpv6 = netStr.contains(u
':');
1024 if (!isIpv6 && subnet.indexOf(u
'.', slash + 1) != -1) {
1028 if (!
mask.setAddress(subnet.mid(slash + 1)))
1049 if (!net.setAddress(netStr.toString()))
1060 auto parts = netStr.split(u
'.');
1061 if (parts.isEmpty() || parts.size() > 4)
1064 if (parts.constLast().isEmpty())
1068 for (
int i = 0;
i < parts.size(); ++
i) {
1070 uint byteValue = parts.at(
i).toUInt(&
ok);
1071 if (!
ok || byteValue > 255)
1077 addr <<= 8 * (4 - parts.size());
1078 if (netmask == -1) {
1079 netmask = 8 * parts.size();
1080 }
else if (netmask == 0) {
1085 }
else if (netmask != 32) {
1233#ifndef QT_NO_DEBUG_STREAM
1237 d.resetFormat().nospace();
1239 d <<
"QHostAddress(QHostAddress::Any)";
1241 d <<
"QHostAddress(" <<
address.toString() <<
')';
1275#ifndef QT_NO_DATASTREAM
1299 for (
int i = 0;
i < 16; ++
i)
1333 for (
int i = 0;
i < 16; ++
i)
1347 in.setStatus(QDataStream::ReadCorruptData);
1356#include "moc_qhostaddress.cpp"
\inmodule QtCore\reentrant
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
void setAddress(quint32 a_=0)
bool parse(const QString &ipString)
struct QHostAddressPrivate::@401::@404 a6_32
AddressClassification classify() const
struct QHostAddressPrivate::@401::@403 a6_64
The QHostAddress class provides an IP address.
QExplicitlySharedDataPointer< QHostAddressPrivate > d
SpecialAddress
\value Null The null address object.
@ ConvertUnspecifiedAddress
quint32 toIPv4Address(bool *ok=nullptr) const
Returns the IPv4 address as a number.
bool isUniqueLocalUnicast() const
QHostAddress & operator=(QHostAddress &&other) noexcept
QDataStream & operator<<(QDataStream &out, const QHostAddress &address)
Writes host address address to the stream out and returns a reference to the stream.
bool isNull() const
Returns true if this host address is not valid for any host or interface.
QDataStream & operator>>(QDataStream &in, QHostAddress &address)
Reads a host address into address from the stream in and returns a reference to the stream.
void clear()
Sets the host address to null and sets the protocol to QAbstractSocket::UnknownNetworkLayerProtocol.
bool isInSubnet(const QHostAddress &subnet, int netmask) const
friend bool operator==(QHostAddress::SpecialAddress lhs, const QHostAddress &rhs)
Returns true if special address lhs is the same as host address rhs; otherwise returns false.
QHostAddress()
Constructs a null host address object, i.e.
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
~QHostAddress()
Destroys the host address object.
static QPair< QHostAddress, int > parseSubnet(const QString &subnet)
Q_IPV6ADDR toIPv6Address() const
Returns the IPv6 address as a Q_IPV6ADDR structure.
@ UnknownNetworkLayerProtocol
bool isEqual(const QHostAddress &address, ConversionMode mode=TolerantConversion) const
void setScopeId(const QString &id)
bool isPrivateUse() const
QString toString() const
Returns the address as a string.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
bool setAddress(const QHostAddress &address)
QHostAddress address(QAbstractSocket::NetworkLayerProtocol protocol) const
constexpr void chop(qsizetype n) noexcept
Truncates this string view by length characters.
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
const_iterator begin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the st...
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
const_iterator end() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character after...
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
void clear()
Clears the contents of the string and makes it null.
QString simplified() 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)
Combined button and popup list for selecting options.
constexpr T qToBigEndian(T source)
constexpr T qFromBigEndian(T source)
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
size_t qHashBits(const void *p, size_t size, size_t seed) noexcept
static bool convertToIpv4(quint32 &a, const Q_IPV6ADDR &a6, const QHostAddress::ConversionMode mode)
QDebug operator<<(QDebug d, const QHostAddress &address)
static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId)
static void clearBits(quint8 *where, int start, int end)
static ControlElement< T > * ptr(QWidget *widget)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLuint GLuint64EXT address
QT_BEGIN_NAMESPACE constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
unsigned long long quint64
QT_BEGIN_NAMESPACE typedef signed char qint8
static const QChar * parseIp6(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode)
QTextStream out(stdout)
[7]