![]() |
Qt 6.x
The Qt SDK
|
The QHostAddress class provides an IP address. More...
#include <qhostaddress.h>
Public Types | |
enum | SpecialAddress { Null , Broadcast , LocalHost , LocalHostIPv6 , Any , AnyIPv6 , AnyIPv4 } |
\value Null The null address object. More... | |
enum | ConversionModeFlag { ConvertV4MappedToIPv4 = 1 , ConvertV4CompatToIPv4 = 2 , ConvertUnspecifiedAddress = 4 , ConvertLocalHost = 8 , TolerantConversion = 0xff , StrictConversion = 0 } |
enum | NetworkLayerProtocol { IPv4Protocol , IPv6Protocol , AnyIPProtocol , UnknownNetworkLayerProtocol = -1 } |
Public Member Functions | |
QHostAddress () | |
Constructs a null host address object, i.e. | |
QHostAddress (quint32 ip4Addr) | |
Constructs a host address object with the IPv4 address ip4Addr. | |
QHostAddress (const quint8 *ip6Addr) | |
QHostAddress (const Q_IPV6ADDR &ip6Addr) | |
Constructs a host address object with the IPv6 address ip6Addr. | |
QHostAddress (const sockaddr *address) | |
Constructs an IPv4 or IPv6 address using the address specified by the native structure sockaddr. | |
QHostAddress (const QString &address) | |
Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1"). | |
QHostAddress (const QHostAddress ©) | |
Constructs a copy of the given address. | |
QHostAddress (SpecialAddress address) | |
Constructs a QHostAddress object for address. | |
~QHostAddress () | |
Destroys the host address object. | |
QHostAddress & | operator= (QHostAddress &&other) noexcept |
QHostAddress & | operator= (const QHostAddress &other) |
Assigns another host address to this object, and returns a reference to this object. | |
QHostAddress & | operator= (SpecialAddress address) |
void | swap (QHostAddress &other) noexcept |
void | setAddress (quint32 ip4Addr) |
Set the IPv4 address specified by ip4Addr. | |
void | setAddress (const quint8 *ip6Addr) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | setAddress (const Q_IPV6ADDR &ip6Addr) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Set the IPv6 address specified by ip6Addr. | |
void | setAddress (const sockaddr *address) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the native structure sockaddr. | |
bool | setAddress (const QString &address) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g. | |
void | setAddress (SpecialAddress address) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
NetworkLayerProtocol | protocol () const |
Returns the network layer protocol of the host address. | |
quint32 | toIPv4Address (bool *ok=nullptr) const |
Returns the IPv4 address as a number. | |
Q_IPV6ADDR | toIPv6Address () const |
Returns the IPv6 address as a Q_IPV6ADDR structure. | |
QString | toString () const |
Returns the address as a string. | |
QString | scopeId () const |
void | setScopeId (const QString &id) |
bool | isEqual (const QHostAddress &address, ConversionMode mode=TolerantConversion) const |
bool | operator== (const QHostAddress &address) const |
Returns true if this host address is the same as the other address given; otherwise returns false . | |
bool | operator== (SpecialAddress address) const |
Returns true if this host address is the same as the other address given; otherwise returns false . | |
bool | operator!= (const QHostAddress &address) const |
bool | operator!= (SpecialAddress address) const |
Returns true if this host address is not the same as the other address given; otherwise returns false . | |
bool | isNull () const |
Returns true if this host address is not valid for any host or interface. | |
void | clear () |
Sets the host address to null and sets the protocol to QAbstractSocket::UnknownNetworkLayerProtocol. | |
bool | isInSubnet (const QHostAddress &subnet, int netmask) const |
bool | isInSubnet (const QPair< QHostAddress, int > &subnet) const |
bool | isLoopback () const |
bool | isGlobal () const |
bool | isLinkLocal () const |
bool | isSiteLocal () const |
bool | isUniqueLocalUnicast () const |
bool | isMulticast () const |
bool | isBroadcast () const |
bool | isPrivateUse () const |
Static Public Member Functions | |
static QPair< QHostAddress, int > | parseSubnet (const QString &subnet) |
Protected Attributes | |
QExplicitlySharedDataPointer< QHostAddressPrivate > | d |
Friends | |
class | QHostAddressPrivate |
Q_NETWORK_EXPORT size_t | qHash (const QHostAddress &key, size_t seed) noexcept |
bool | operator== (QHostAddress::SpecialAddress lhs, const QHostAddress &rhs) |
Returns true if special address lhs is the same as host address rhs; otherwise returns false . | |
bool | operator!= (QHostAddress::SpecialAddress lhs, const QHostAddress &rhs) |
Related Symbols | |
(Note that these are not member symbols.) | |
size_t | qHash (const QHostAddress &key, size_t seed) noexcept |
QDataStream & | operator<< (QDataStream &out, const QHostAddress &address) |
Writes host address address to the stream out and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &in, QHostAddress &address) |
Reads a host address into address from the stream in and returns a reference to the stream. | |
The QHostAddress class provides an IP address.
\inmodule QtNetwork
This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.
QHostAddress is normally used with the QTcpSocket, QTcpServer, and QUdpSocket to connect to a host or to set up a server.
A host address is set with setAddress(), and retrieved with toIPv4Address(), toIPv6Address(), or toString(). You can check the type with protocol().
The class also supports common predefined addresses: \l Null, \l LocalHost, \l LocalHostIPv6, \l Broadcast, and \l Any.
Definition at line 37 of file qhostaddress.h.
\value StrictConversion Don't convert IPv6 addresses to IPv4 when comparing two QHostAddress objects of different protocols, so they will always be considered different. \value ConvertV4MappedToIPv4 Convert IPv4-mapped IPv6 addresses (RFC 4291 sect. 2.5.5.2) when comparing. Therefore QHostAddress("::ffff:192.168.1.1") will compare equal to QHostAddress("192.168.1.1"). \value ConvertV4CompatToIPv4 Convert IPv4-compatible IPv6 addresses (RFC 4291 sect. 2.5.5.1) when comparing. Therefore QHostAddress("::192.168.1.1") will compare equal to QHostAddress("192.168.1.1"). \value ConvertLocalHost Convert the IPv6 loopback addresses to its IPv4 equivalent when comparing. Therefore e.g. QHostAddress("::1") will compare equal to QHostAddress("127.0.0.1"). \value ConvertUnspecifiedAddress All unspecified addresses will compare equal, namely AnyIPv4, AnyIPv6 and Any. \value TolerantConversion Sets all three preceding flags.
Enumerator | |
---|---|
ConvertV4MappedToIPv4 | |
ConvertV4CompatToIPv4 | |
ConvertUnspecifiedAddress | |
ConvertLocalHost | |
TolerantConversion | |
StrictConversion |
Definition at line 50 of file qhostaddress.h.
Enumerator | |
---|---|
IPv4Protocol | |
IPv6Protocol | |
AnyIPProtocol | |
UnknownNetworkLayerProtocol |
Definition at line 68 of file qhostaddress.h.
\value Null The null address object.
Equivalent to QHostAddress(). See also QHostAddress::isNull(). \value LocalHost The IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1"). \value LocalHostIPv6 The IPv6 localhost address. Equivalent to QHostAddress("::1"). \value Broadcast The IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255"). \value AnyIPv4 The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0"). A socket bound with this address will listen only on IPv4 interfaces. \value AnyIPv6 The IPv6 any-address. Equivalent to QHostAddress("::"). A socket bound with this address will listen only on IPv6 interfaces. \value Any The dual stack any-address. A socket bound with this address will listen on both IPv4 and IPv6 interfaces.
Enumerator | |
---|---|
Null | |
Broadcast | |
LocalHost | |
LocalHostIPv6 | |
Any | |
AnyIPv6 | |
AnyIPv4 |
Definition at line 41 of file qhostaddress.h.
QHostAddress::QHostAddress | ( | ) |
Constructs a null host address object, i.e.
an address which is not valid for any host or interface.
Definition at line 379 of file qhostaddress.cpp.
Referenced by parseSubnet().
|
explicit |
Constructs a host address object with the IPv4 address ip4Addr.
Definition at line 387 of file qhostaddress.cpp.
References setAddress().
|
explicit |
ip6Addr must be a 16-byte array in network byte order (big endian).
Definition at line 400 of file qhostaddress.cpp.
References setAddress().
|
explicit |
Constructs a host address object with the IPv6 address ip6Addr.
Definition at line 409 of file qhostaddress.cpp.
References setAddress().
|
explicit |
Constructs an IPv4 or IPv6 address using the address specified by the native structure sockaddr.
|
explicit |
Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1").
Definition at line 421 of file qhostaddress.cpp.
References d, and QHostAddressPrivate::parse().
QHostAddress::QHostAddress | ( | const QHostAddress & | copy | ) |
Constructs a copy of the given address.
Definition at line 447 of file qhostaddress.cpp.
QHostAddress::QHostAddress | ( | SpecialAddress | address | ) |
Constructs a QHostAddress object for address.
Definition at line 455 of file qhostaddress.cpp.
References setAddress().
QHostAddress::~QHostAddress | ( | ) |
Destroys the host address object.
Definition at line 464 of file qhostaddress.cpp.
void QHostAddress::clear | ( | ) |
Sets the host address to null and sets the protocol to QAbstractSocket::UnknownNetworkLayerProtocol.
Definition at line 520 of file qhostaddress.cpp.
References QHostAddressPrivate::clear(), d, and QExplicitlySharedDataPointer< T >::detach().
Referenced by QNetworkDatagram::clear(), QIpPacketHeader::clear(), QNativeSocketEnginePrivate::fetchConnectionParameters(), and setAddress().
bool QHostAddress::isBroadcast | ( | ) | const |
Returns true
if the address is the IPv4 broadcast address, false
otherwise. The IPv4 broadcast address is 255.255.255.255.
Note that this function does not return true for an IPv4 network's local broadcast address. For that, please use \l QNetworkInterface to obtain the broadcast addresses of the local machine.
Definition at line 1214 of file qhostaddress.cpp.
References BroadcastAddress, QHostAddressPrivate::classify(), and d.
bool QHostAddress::isEqual | ( | const QHostAddress & | other, |
ConversionMode | mode = TolerantConversion |
||
) | const |
Returns true
if this host address is the same as the other address given; otherwise returns false
.
The parameter mode controls which conversions are performed between addresses of differing protocols. If no mode is given, TolerantConversion
is performed by default.
Definition at line 797 of file qhostaddress.cpp.
References QHostAddressPrivate::a, QHostAddressPrivate::a6, QHostAddressPrivate::a6_64, AnyIPProtocol, QHostAddressPrivate::c, convertToIpv4(), ConvertUnspecifiedAddress, d, IPv4Protocol, IPv6Protocol, other(), QHostAddressPrivate::protocol, and UnknownNetworkLayerProtocol.
Referenced by QSslSocketPrivate::isMatchingHostname(), and operator==().
bool QHostAddress::isGlobal | ( | ) | const |
Returns true
if the address is an IPv4 or IPv6 global address, false
otherwise. A global address is an address that is not reserved for special purposes (like loopback or multicast) or future purposes.
Note that IPv6 unique local unicast addresses are considered global addresses (see isUniqueLocalUnicast()), as are IPv4 addresses reserved for local networks by \l {RFC 1918}.
Also note that IPv6 site-local addresses are deprecated and should be considered as global in new applications. This function returns true for site-local addresses too.
Definition at line 1122 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, and GlobalAddress.
bool QHostAddress::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.
An IP is considered to belong to a subnet if it is contained between the lowest and the highest address in that subnet. In the case of IP version 4, the lowest address is the network address, while the highest address is the broadcast address.
The subnet argument does not have to be the actual network address (the lowest address in the subnet). It can be any valid IP belonging to that subnet. In particular, if it is equal to the IP address held by this object, this function will always return true (provided the netmask is a valid value).
Definition at line 915 of file qhostaddress.cpp.
References QHostAddressPrivate::a, QHostAddressPrivate::a6, d, IPv4Protocol, IPv6Protocol, protocol(), QHostAddressPrivate::protocol, and qToBigEndian().
Referenced by isBypassed(), isHostExcluded(), isInSubnet(), and QNetworkConnectionMonitorPrivate::setTargets().
bool QHostAddress::isInSubnet | ( | const QPair< QHostAddress, int > & | subnet | ) | const |
Returns true
if this IP is in the subnet described by subnet. The QHostAddress member of subnet contains the network prefix and the int (second) member contains the netmask (prefix length).
Definition at line 963 of file qhostaddress.cpp.
References isInSubnet().
bool QHostAddress::isLinkLocal | ( | ) | const |
Returns true
if the address is an IPv4 or IPv6 link-local address, false
otherwise.
An IPv4 link-local address is an address in the network 169.254.0.0/16. An IPv6 link-local address is one in the network fe80::/10. See the \l{https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml}{IANA IPv6 Address Space} registry for more information.
Definition at line 1140 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, and LinkLocalAddress.
Referenced by QNetworkConnectionMonitorPrivate::setTargets().
bool QHostAddress::isLoopback | ( | ) | const |
returns true
if the address is the IPv6 loopback address, or any of the IPv4 loopback addresses.
Definition at line 1100 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, and LoopbackAddress.
Referenced by isBypassed(), and QGlobalNetworkProxy::proxyForQuery().
bool QHostAddress::isMulticast | ( | ) | const |
Returns true
if the address is an IPv4 or IPv6 multicast address, false
otherwise.
Definition at line 1197 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, and MulticastAddress.
bool QHostAddress::isNull | ( | ) | const |
Returns true
if this host address is not valid for any host or interface.
The default constructor creates a null address.
Definition at line 891 of file qhostaddress.cpp.
References d, QHostAddressPrivate::protocol, and UnknownNetworkLayerProtocol.
Referenced by applyNameServer(), QSslSocketPrivate::isMatchingHostname(), QTlsPrivate::X509CertificateGeneric::parse(), QNetworkConnectionMonitor::setTargets(), and QTlsPrivate::X509CertificateOpenSSL::subjectAlternativeNames().
bool QHostAddress::isPrivateUse | ( | ) | const |
Returns true
if the address is an IPv6 unique local unicast address or IPv4 address reserved for local networks by \l {RFC 1918}, false
otherwise.
Definition at line 1227 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, PrivateNetworkAddress, and UniqueLocalAddress.
bool QHostAddress::isSiteLocal | ( | ) | const |
Returns true
if the address is an IPv6 site-local address, false
otherwise.
An IPv6 site-local address is one in the network fec0::/10. See the \l{https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml}{IANA IPv6 Address Space} registry for more information.
IPv6 site-local addresses are deprecated and should not be depended upon in new applications. New applications should not depend on this function and should consider site-local addresses the same as global (which is why isGlobal() also returns true). Site-local addresses were replaced by Unique Local Addresses (ULA).
Definition at line 1163 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, and SiteLocalAddress.
bool QHostAddress::isUniqueLocalUnicast | ( | ) | const |
Returns true
if the address is an IPv6 unique local unicast address, false
otherwise.
An IPv6 unique local unicast address is one in the network fc00::/7. See the \l{https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml} {IANA IPv6 Address Space} registry for more information.
Note that Unique local unicast addresses count as global addresses too. RFC 4193 says that, in practice, "applications may treat these addresses like global scoped addresses." Only routers need care about the distinction.
Definition at line 1184 of file qhostaddress.cpp.
References QHostAddressPrivate::classify(), d, and UniqueLocalAddress.
|
inline |
Returns true
if this host address is not the same as the other address given; otherwise returns false
.
Definition at line 113 of file qhostaddress.h.
References operator==().
|
inline |
Returns true
if this host address is not the same as the other address given; otherwise returns false
.
Definition at line 115 of file qhostaddress.h.
References operator==().
QHostAddress & QHostAddress::operator= | ( | const QHostAddress & | other | ) |
Assigns another host address to this object, and returns a reference to this object.
Definition at line 472 of file qhostaddress.cpp.
References d.
|
inlinenoexcept |
Definition at line 87 of file qhostaddress.h.
References other(), and swap().
QHostAddress & QHostAddress::operator= | ( | SpecialAddress | address | ) |
Definition at line 485 of file qhostaddress.cpp.
References setAddress().
bool QHostAddress::operator== | ( | const QHostAddress & | other | ) | const |
Returns true
if this host address is the same as the other address given; otherwise returns false
.
This operator just calls isEqual(other, StrictConversion).
Definition at line 780 of file qhostaddress.cpp.
References d, isEqual(), other(), and StrictConversion.
bool QHostAddress::operator== | ( | SpecialAddress | address | ) | const |
Returns true
if this host address is the same as the other address given; otherwise returns false
.
Definition at line 850 of file qhostaddress.cpp.
References QHostAddressPrivate::a, QHostAddressPrivate::a6_64, Any, AnyIPProtocol, AnyIPv4, AnyIPv6, Broadcast, QHostAddressPrivate::c, d, IPv4Protocol, IPv6Protocol, LocalHost, LocalHostIPv6, Null, other(), QHostAddressPrivate::protocol, qToBigEndian(), and UnknownNetworkLayerProtocol.
|
static |
Parses the IP and subnet information contained in subnet and returns the network prefix for that network and its prefix length.
The IP address and the netmask must be separated by a slash (/).
This function supports arguments in the form: \list
For IP version 4, this function accepts as well missing trailing components (i.e., less than 4 octets, like "192.168.1"), followed or not by a dot. If the netmask is also missing in that case, it is set to the number of octets actually passed (in the example above, it would be 24, for 3 octets).
Definition at line 993 of file qhostaddress.cpp.
References QHostAddress(), QHostAddressPrivate::a6, clearBits(), QStringView::contains(), d, i, QString::indexOf(), QString::isEmpty(), QString::mid(), ok, QNetmask::prefixLength(), qMakePair(), QList< T >::removeLast(), QNetmask::setAddress(), setAddress(), QStringView::split(), QStringView::toString(), QString::toUInt(), and QStringView::truncate().
Referenced by isBypassed(), and isHostExcluded().
QHostAddress::NetworkLayerProtocol QHostAddress::protocol | ( | ) | const |
Returns the network layer protocol of the host address.
Definition at line 665 of file qhostaddress.cpp.
References d, and QHostAddressPrivate::protocol.
Referenced by QHttpNetworkConnectionChannel::_q_connected(), QAbstractSocketPrivate::_q_connectToNextAddress(), applyNameServer(), QAbstractSocketPrivate::bind(), dtlsutil::cookie_for_peer(), QNetworkDatagram::destinationPort(), isInSubnet(), QNetworkDatagram::isValid(), QNativeSocketEngine::joinMulticastGroup(), multicastMembershipHelper(), multicastMembershipHelper(), QNativeSocketEnginePrivate::nativeSetMulticastInterface(), QNetworkCookie::normalize(), QNetworkDatagram::senderPort(), QNetworkAddressEntry::setNetmask(), QNetworkConnectionMonitorPrivate::setTargets(), QHttpNetworkConnectionPrivate::startHostInfoLookup(), and QNetworkCookie::toRawForm().
QString QHostAddress::scopeId | ( | ) | const |
Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the address does not contain a scope ID, an empty QString is returned.
The IPv6 scope ID specifies the scope of reachability for non-global IPv6 addresses, limiting the area in which the address can be used. All IPv6 addresses are associated with such a reachability scope. The scope ID is used to disambiguate addresses that are not guaranteed to be globally unique.
IPv6 specifies the following four levels of reachability:
\list
\endlist
When using a link-local or site-local address for IPv6 connections, you must specify the scope ID. The scope ID for a link-local address is usually the same as the interface name (e.g., "eth0", "en1") or number (e.g., "1", "2").
Definition at line 750 of file qhostaddress.cpp.
References d, IPv6Protocol, QHostAddressPrivate::protocol, and QHostAddressPrivate::scopeId.
void QHostAddress::setAddress | ( | const Q_IPV6ADDR & | ip6Addr | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Set the IPv6 address specified by ip6Addr.
Definition at line 555 of file qhostaddress.cpp.
References d, QExplicitlySharedDataPointer< T >::detach(), and QHostAddressPrivate::setAddress().
bool QHostAddress::setAddress | ( | const QString & | address | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g.
"127.0.0.1"). Returns true
and sets the address if the address was successfully parsed; otherwise returns false
.
Definition at line 569 of file qhostaddress.cpp.
References d, QExplicitlySharedDataPointer< T >::detach(), and QHostAddressPrivate::parse().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Set the IPv6 address specified by ip6Addr.
ip6Addr must be an array of 16 bytes in network byte order (high-order byte first).
Definition at line 544 of file qhostaddress.cpp.
References d, QExplicitlySharedDataPointer< T >::detach(), and QHostAddressPrivate::setAddress().
void QHostAddress::setAddress | ( | const sockaddr * | sockaddr | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the native structure sockaddr.
Returns true
and sets the address if the address was successfully parsed; otherwise returns false
.
Set the IPv4 address specified by ip4Addr.
Definition at line 529 of file qhostaddress.cpp.
References d, QExplicitlySharedDataPointer< T >::detach(), and QHostAddressPrivate::setAddress().
Referenced by QHostAddress(), QHostAddress(), QHostAddress(), QHostAddress(), QAbstractSocket::connectToHost(), isBypassed(), isHostExcluded(), operator=(), parseSubnet(), QGlobalNetworkProxy::proxyForQuery(), qt_socket_getPortAndAddress(), QHttpNetworkConnectionPrivate::startHostInfoLookup(), and QAbstractSocket::waitForConnected().
void QHostAddress::setAddress | ( | SpecialAddress | address | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the special address specified by address.
Definition at line 599 of file qhostaddress.cpp.
References Any, AnyIPProtocol, AnyIPv4, AnyIPv6, Broadcast, clear(), d, LocalHost, LocalHostIPv6, Null, QHostAddressPrivate::protocol, Q_FALLTHROUGH, and QHostAddressPrivate::setAddress().
Sets the IPv6 scope ID of the address to id. If the address protocol is not IPv6, this function does nothing. The scope ID may be set as an interface name (such as "eth0" or "en1") or as an integer representing the interface index. If id is an interface name, QtNetwork will convert to an interface index using QNetworkInterface::interfaceIndexFromName() before calling the operating system networking functions.
Definition at line 767 of file qhostaddress.cpp.
References d, QExplicitlySharedDataPointer< T >::detach(), IPv6Protocol, QHostAddressPrivate::protocol, and QHostAddressPrivate::scopeId.
Referenced by qt_socket_getPortAndAddress().
|
inlinenoexcept |
Swaps this host address with other. This operation is very fast and never fails.
Definition at line 92 of file qhostaddress.h.
Returns the IPv4 address as a number.
For example, if the address is 127.0.0.1, the returned value is 2130706433 (i.e. 0x7f000001).
This value is valid if the protocol() is \l{QAbstractSocket::}{IPv4Protocol}, or if the protocol is \l{QAbstractSocket::}{IPv6Protocol}, and the IPv6 address is an IPv4 mapped address (RFC4291). In those cases, ok will be set to true. Otherwise, it will be set to false.
Definition at line 651 of file qhostaddress.cpp.
References QHostAddressPrivate::a, QHostAddressPrivate::a6, AnyIPProtocol, convertToIpv4(), ConvertUnspecifiedAddress, ConvertV4MappedToIPv4, d, IPv4Protocol, IPv6Protocol, ok, and QHostAddressPrivate::protocol.
Referenced by dtlsutil::cookie_for_peer(), multicastMembershipHelper(), multicastMembershipHelper(), QNativeSocketEnginePrivate::nativeSetMulticastInterface(), postProcess(), and toString().
Q_IPV6ADDR QHostAddress::toIPv6Address | ( | ) | const |
Returns the IPv6 address as a Q_IPV6ADDR structure.
The structure consists of 16 unsigned characters.
This value is valid if the protocol() is \l{QAbstractSocket::}{IPv6Protocol}. If the protocol is \l{QAbstractSocket::}{IPv4Protocol}, then the address is returned as an IPv4 mapped IPv6 address. (RFC4291)
Definition at line 684 of file qhostaddress.cpp.
References QHostAddressPrivate::a6, and d.
Referenced by dtlsutil::cookie_for_peer(), multicastMembershipHelper(), and multicastMembershipHelper().
QString QHostAddress::toString | ( | ) | const |
Returns the address as a string.
For example, if the address is the IPv4 address 127.0.0.1, the returned string is "127.0.0.1". For IPv6 the string format will follow the RFC5952 recommendation. For QHostAddress::Any, its IPv4 address will be returned ("0.0.0.0")
Definition at line 699 of file qhostaddress.cpp.
References QHostAddressPrivate::a6, AnyIPProtocol, d, i, IPv4Protocol, IPv6Protocol, QString::isEmpty(), QHostAddressPrivate::protocol, QHostAddressPrivate::scopeId, toIPv4Address(), and QIPAddressUtils::toString().
Referenced by QAbstractSocketPrivate::_q_connectToNextAddress(), QAbstractSocketPrivate::_q_startConnecting(), QAbstractSocketPrivate::bind(), QAbstractSocketPrivate::fetchConnectionParameters(), QNativeSocketEnginePrivate::fetchConnectionParameters(), QTlsPrivate::X509CertificateGeneric::parse(), QTlsPrivate::X509CertificateOpenSSL::subjectAlternativeNames(), QSctpSocket::writeDatagram(), and QUdpSocket::writeDatagram().
|
friend |
Returns false
if special address lhs is the same as host address rhs; otherwise returns true
.
Definition at line 138 of file qhostaddress.h.
|
related |
Writes host address address to the stream out and returns a reference to the stream.
Definition at line 1284 of file qhostaddress.cpp.
References AnyIPProtocol, i, IPv4Protocol, IPv6Protocol, out, qint8, and UnknownNetworkLayerProtocol.
|
friend |
Returns true
if special address lhs is the same as host address rhs; otherwise returns false
.
Definition at line 136 of file qhostaddress.h.
|
related |
Reads a host address into address from the stream in and returns a reference to the stream.
Definition at line 1315 of file qhostaddress.cpp.
References Any, AnyIPProtocol, i, IPv4Protocol, IPv6Protocol, qint8, QDataStream::ReadCorruptData, and UnknownNetworkLayerProtocol.
|
related |
Returns a hash of the host address key, using seed to seed the calculation.
Definition at line 1251 of file qhostaddress.cpp.
|
friend |
Returns a hash of the host address key, using seed to seed the calculation.
Definition at line 1251 of file qhostaddress.cpp.
|
friend |
Definition at line 142 of file qhostaddress.h.
|
protected |
Definition at line 143 of file qhostaddress.h.
Referenced by QHostAddress(), clear(), isBroadcast(), isEqual(), isGlobal(), isInSubnet(), isLinkLocal(), isLoopback(), isMulticast(), isNull(), isPrivateUse(), isSiteLocal(), isUniqueLocalUnicast(), operator=(), operator==(), operator==(), parseSubnet(), protocol(), scopeId(), setAddress(), setAddress(), setAddress(), setAddress(), setAddress(), setScopeId(), toIPv4Address(), toIPv6Address(), and toString().