KNetwork::KIpAddress Class Reference
An IP address. More...
#include <ksocketaddress.h>
Collaboration diagram for KNetwork::KIpAddress:

Public Member Functions | |
KIpAddress () | |
KIpAddress (const KIpAddress &other) | |
KIpAddress (const QString &addr) | |
KIpAddress (const char *addr) | |
KIpAddress (const void *addr, int version=4) | |
KIpAddress (Q_UINT32 ip4addr) | |
~KIpAddress () | |
KIpAddress & | operator= (const KIpAddress &other) |
bool | operator== (const KIpAddress &other) const |
bool | compare (const KIpAddress &other, bool checkMapped=true) const |
int | version () const |
bool | isIPv4Addr () const |
bool | isIPv6Addr () const |
bool | setAddress (const QString &address) |
bool | setAddress (const char *address) |
bool | setAddress (const void *raw, int version=4) |
QString | toString () const |
const void * | addr () const |
Q_UINT32 | IPv4Addr (bool convertMapped=true) const |
bool | isUnspecified () const |
bool | isLocalhost () const |
bool | isLoopback () const |
bool | isClassA () const |
bool | isClassB () const |
bool | isClassC () const |
bool | isClassD () const |
bool | isMulticast () const |
bool | isLinkLocal () const |
bool | isSiteLocal () const |
bool | isGlobal () const |
bool | isV4Mapped () const |
bool | isV4Compat () const |
bool | isMulticastNodeLocal () const |
bool | isMulticastLinkLocal () const |
bool | isMulticastSiteLocal () const |
bool | isMulticastOrgLocal () const |
bool | isMulticastGlobal () const |
Static Public Attributes | |
const KIpAddress | localhostV4 |
const KIpAddress | anyhostV4 |
const KIpAddress | localhostV6 |
const KIpAddress | anyhostV6 |
Protected Attributes | |
Q_UINT32 | m_data [4] |
char | m_version |
Detailed Description
An IP address.This class represents one IP address, version 4 or 6. This is only the address, not including port information or other data.
It is not a good programming practice to create address from objects like this. Instead, prefer a more thorough function like KResolver::resolve, which also handle extra information like scope ids.
This is a light-weight class. Most of the member functions are inlined and there are no virtual functions. This object's size should be less than 20 bytes. Also note that there is no sharing of data.
- Author:
- Thiago Macieira <thiago.macieira@kdemail.net>
Definition at line 61 of file ksocketaddress.h.
Constructor & Destructor Documentation
|
Default constructor. Creates an empty address. It defaults to IP version 4. Definition at line 68 of file ksocketaddress.h. |
|
Copy constructor. Copies the data from the other object. Data is not shared.
|
|
Creates an object from the given string representation. The IP version is guessed from the address format.
References setAddress(). |
|
Creates an object from the given string representation. The IP version is guessed from the address format.
References setAddress(). |
|
Creates an object from the given raw data and IP version.
References setAddress(). |
|
This is a convenience constructor. Constructs an object from the given IPv4 address in the form of an integer. Note: do not write code to depend on IPv4 addresses being integer types. Instead, treat them as a special type, like a KIpAddress or the system's in_addr.
References setAddress(). |
|
Destructor. This frees resources associated with this object. Note: destructor is non-virtual. The compiler will happily optimise it out of the way. Definition at line 130 of file ksocketaddress.h. |
Member Function Documentation
|
Copy operator. Copies the data from the other object into this one.
|
|
Returns true if the two addresses match. This function performs a v4-mapped check.
References compare(). |
|
Compares this address against the other, supplied one and return true if they match.
The
An IPv6 v4-mapped address is an IPv6 address that is, for all purposes, equivalent to an IPv4 one. The default behaviour of this function is to take that into account. If you want a strict matching, pass false to the
References m_data, and m_version. Referenced by operator==(). |
|
Retrieves the IP version in this object.
Referenced by isClassA(), isClassB(), isClassC(), isClassD(), isGlobal(), isIPv4Addr(), isIPv6Addr(), isLinkLocal(), isLocalhost(), isMulticast(), isMulticastGlobal(), isMulticastLinkLocal(), isMulticastNodeLocal(), isMulticastOrgLocal(), isMulticastSiteLocal(), isSiteLocal(), isUnspecified(), isV4Compat(), and isV4Mapped(). |
|
Returns true if this is an IPv4 address. Definition at line 176 of file ksocketaddress.h. References version(). |
|
Returns true if this is an IPv6 address. Definition at line 182 of file ksocketaddress.h. References version(). |
|
Sets the address to the given string representation.
Referenced by KIpAddress(), and setAddress(). |
|
Sets the address to the given string representation.
References setAddress(). |
|
Sets the address to the given raw binary representation.
|
|
Returns the address as a string. Definition at line 188 of file ksocketaddress.cpp. |
|
Returns a pointer to binary raw data representing the address. Definition at line 219 of file ksocketaddress.h. Referenced by isLinkLocal(), isMulticast(), isMulticastGlobal(), isMulticastLinkLocal(), isMulticastNodeLocal(), isMulticastOrgLocal(), isMulticastSiteLocal(), isSiteLocal(), isV4Compat(), and isV4Mapped(). |
|
This is a convenience function.
Returns the IPv4 address in a 32-bit integer. The result is only valid if isIPv4Addr returns true. Alternatively, if the contained IPv6 address is a v4-mapped one and the Note: you should not treat IP addresses as integers. Instead, use types defined for that purpose, such as KIpAddress or the system's in_addr type.
References isV4Mapped(). Referenced by isClassA(), isClassB(), isClassC(), and isClassD(). |
|
Returns true if this is the IPv4 or IPv6 unspecified address. Definition at line 245 of file ksocketaddress.h. |
|
Returns true if this is either the IPv4 or the IPv6 localhost address. Definition at line 251 of file ksocketaddress.h. References localhostV4, localhostV6, and version(). Referenced by isLoopback(), and isV4Compat(). |
|
This is an alias for isLocalhost. Definition at line 257 of file ksocketaddress.h. References isLocalhost(). |
|
Returns true if this is an IPv4 class A address, i.e., from 0.0.0.0 to 127.255.255.255. This function does not test for v4-mapped addresses. Definition at line 266 of file ksocketaddress.h. References IPv4Addr(), and version(). |
|
Returns true if this is an IPv4 class B address, i.e., one from 128.0.0.0 to 191.255.255.255. This function does not test for v4-mapped addresses. Definition at line 275 of file ksocketaddress.h. References IPv4Addr(), and version(). |
|
Returns true if this is an IPv4 class C address, i.e., one from 192.0.0.0 to 223.255.255.255. This function does not test for v4-mapped addresses. Definition at line 284 of file ksocketaddress.h. References IPv4Addr(), and version(). |
|
Returns true if this is an IPv4 class D (a.k.a. multicast) address. Note: this function is not the same as isMulticast. isMulticast also tests for IPv6 multicast addresses. Definition at line 293 of file ksocketaddress.h. References IPv4Addr(), and version(). Referenced by isMulticast(). |
|
Returns true if this is a multicast address, be it IPv4 or IPv6. Definition at line 299 of file ksocketaddress.h. References addr(), isClassD(), and version(). Referenced by isGlobal(), isMulticastGlobal(), isMulticastLinkLocal(), isMulticastNodeLocal(), isMulticastOrgLocal(), and isMulticastSiteLocal(). |
|
Returns true if this is an IPv6 link-local address. Definition at line 309 of file ksocketaddress.h. References addr(), and version(). Referenced by isGlobal(). |
|
Returns true if this is an IPv6 site-local address. Definition at line 320 of file ksocketaddress.h. References addr(), and version(). Referenced by isGlobal(). |
|
Returns true if this is a global IPv6 address. Definition at line 331 of file ksocketaddress.h. References isLinkLocal(), isMulticast(), isSiteLocal(), and version(). |
|
Returns true if this is a v4-mapped IPv6 address. Definition at line 337 of file ksocketaddress.h. References addr(), and version(). Referenced by IPv4Addr(). |
|
Returns true if this is a v4-compat IPv6 address. Definition at line 349 of file ksocketaddress.h. References addr(), isLocalhost(), and version(). |
|
Returns true if this is an IPv6 node-local multicast address. Definition at line 359 of file ksocketaddress.h. References addr(), isMulticast(), and version(). |
|
Returns true if this is an IPv6 link-local multicast address. Definition at line 365 of file ksocketaddress.h. References addr(), isMulticast(), and version(). |
|
Returns true if this is an IPv6 site-local multicast address. Definition at line 371 of file ksocketaddress.h. References addr(), isMulticast(), and version(). |
|
Returns true if this is an IPv6 organisational-local multicast address. Definition at line 377 of file ksocketaddress.h. References addr(), isMulticast(), and version(). |
|
Returns true if this is an IPv6 global multicast address. Definition at line 383 of file ksocketaddress.h. References addr(), isMulticast(), and version(). |
Member Data Documentation
|
localhost in IPv4 (127.0.0.1)
Referenced by isLocalhost(). |
|
the any host or undefined address in IPv4 (0.0.0.0)
Referenced by isUnspecified(). |
|
localhost in IPv6 (::1)
Referenced by isLocalhost(). |
|
the any host or undefined address in IPv6 (::)
Referenced by isUnspecified(). |
The documentation for this class was generated from the following files: