#include <QHostAddress.h>
This is a Qt compatible IP address container capable of working transparently with IPv4 and IPv6 addresses. It has no network knowledge and so cannot be more intelligent than what the IP specification rules permit (eg; it can't tell if an IPv4 and IPv6 addresses refer to the same machine).
An IPv4 address is 32 bits long whereas IPv6, a substantial improvement over IPv4, is up to 128 bits long (though it can vary). A discussion of IP is beyond the scope of this page, there are hundreds of books and RFC's about the matter which you should consult.
Some mapping though is provided. IPv4 maps to IPv6 where an IPv4 address AA.BB.CC.DD
(if the numbers were in hex) becomes in IPv6 FFFF:AABB:CCDD
. Also loopback is treated specially: 127.0.0.1 is equivalent to ::1 and vice versa. In the comparison operators, 0.0.0.0 is treated as being equivalent to loopback.
Public Member Functions | |
QHostAddress () | |
QHostAddress (FXuint ip4addr) | |
QHostAddress (const FXuchar *ip6addr) | |
QHostAddress (const QHostAddress &o) | |
QHostAddress & | operator= (const QHostAddress &o) |
bool | operator! () const |
bool | operator== (const QHostAddress &o) const |
bool | operator!= (const QHostAddress &o) const |
void | setAddress (FXuint ip4addr) |
void | setAddress (const FXuchar *ip6addr) |
bool | setAddress (const FXString &addr) |
bool | isNull () const |
bool | isIp4Addr () const |
FXuint | ip4Addr () const |
bool | isIp6Addr () const |
const FXuchar * | ip6Addr () const |
FXString | toString () const |
bool | isLocalMachine () const |
Friends | |
FXAPIR FXStream & | operator<< (FXStream &s, const QHostAddress &i) |
FXAPIR FXStream & | operator>> (FXStream &s, QHostAddress &i) |
FX::QHostAddress::QHostAddress | ( | ) |
Constructs a null address.
FX::QHostAddress::QHostAddress | ( | FXuint | ip4addr | ) |
Constructs the specified IPv4 address.
FX::QHostAddress::QHostAddress | ( | const FXuchar * | ip6addr | ) |
Constructs the specified IPv6 address. Must be in network order.
bool FX::QHostAddress::operator! | ( | ) | const [inline] |
Returns true if the contents is a null address.
bool FX::QHostAddress::operator== | ( | const QHostAddress & | o | ) | const |
Returns true if both addresses are the same by ruleset.
bool FX::QHostAddress::operator!= | ( | const QHostAddress & | o | ) | const [inline] |
Returns true if both addresses are not the same.
void FX::QHostAddress::setAddress | ( | FXuint | ip4addr | ) |
Sets the contents to the specified IPv4 address.
void FX::QHostAddress::setAddress | ( | const FXuchar * | ip6addr | ) |
Sets the contents to the specified IPv6 address. Must be in network order.
bool FX::QHostAddress::setAddress | ( | const FXString & | addr | ) |
Sets the contents by parsing a string. If the string is of the format X.X.X.X then it is assumed to be an IPv4 descriptor and is set as such. If not, it is assumed to be an IPv6 descriptor and is set as such, including expanding "::" sections. Returns false if there was an error in parsing.
bool FX::QHostAddress::isNull | ( | ) | const |
Returns true if the contents are a null address.
bool FX::QHostAddress::isIp4Addr | ( | ) | const |
Returns true if the contents contain an IPv4 address.
FXuint FX::QHostAddress::ip4Addr | ( | ) | const |
Returns the contents in IPv4 format. Returns zero if the container holds an IPv6 address (use isIp4Addr() to check) unless that IPv6 address is a 6to4 protocol map (FFFF:...) or loopback (::1) in which case it returns 127.0.0.1
bool FX::QHostAddress::isIp6Addr | ( | ) | const |
Returns true if the contents contain an IPv6 address.
const FXuchar* FX::QHostAddress::ip6Addr | ( | ) | const |
Returns the contents in IPv6 format. If the contents are in IPv4 format, returns the IPv4 address mapped as an IPv6 using the 6to4 protocol
FXString FX::QHostAddress::toString | ( | ) | const |
Returns the contents as a string representation. If in IPv4, this is in the format X.X.X.X. If in IPv6, this is the standard colon separated IPv6 representation, including with zero sections condensed to "::".
bool FX::QHostAddress::isLocalMachine | ( | ) | const |
Returns true if the address is the local machine.
FXAPIR FXStream& operator<< | ( | FXStream & | s, | |
const QHostAddress & | i | |||
) | [friend] |
Writes the contents of the IP address to stream s.
FXAPIR FXStream& operator>> | ( | FXStream & | s, | |
QHostAddress & | i | |||
) | [friend] |
Reads an IP address from stream s.