• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • KNetwork
  • KIpAddress
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
KNetwork::KIpAddress Class Reference

#include <k3socketaddress.h>

Public Member Functions

 KIpAddress ()
 
 KIpAddress (const KIpAddress &other)
 
 KIpAddress (const QString &addr)
 
 KIpAddress (const char *addr)
 
 KIpAddress (const void *addr, int version=4)
 
 KIpAddress (quint32 ip4addr)
 
 ~KIpAddress ()
 
const void * addr () const
 
bool compare (const KIpAddress &other, bool checkMapped=true) const
 
quint32 IPv4Addr (bool convertMapped=true) const
 
bool isClassA () const
 
bool isClassB () const
 
bool isClassC () const
 
bool isClassD () const
 
bool isGlobal () const
 
bool isIPv4Addr () const
 
bool isIPv6Addr () const
 
bool isLinkLocal () const
 
bool isLocalhost () const
 
bool isLoopback () const
 
bool isMulticast () const
 
bool isMulticastGlobal () const
 
bool isMulticastLinkLocal () const
 
bool isMulticastNodeLocal () const
 
bool isMulticastOrgLocal () const
 
bool isMulticastSiteLocal () const
 
bool isSiteLocal () const
 
bool isUnspecified () const
 
bool isV4Compat () const
 
bool isV4Mapped () const
 
KIpAddress & operator= (const KIpAddress &other)
 
bool operator== (const KIpAddress &other) const
 
bool setAddress (const QString &address)
 
bool setAddress (const char *address)
 
bool setAddress (const void *raw, int version=4)
 
QString toString () const
 
int version () const
 

Static Public Attributes

static const KIpAddress anyhostV4
 
static const KIpAddress anyhostV6
 
static const KIpAddress localhostV4
 
static const KIpAddress localhostV6
 

Protected Attributes

quint32 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 thiag.nosp@m.o@kd.nosp@m.e.org
Deprecated:
Use KSocketFactory or KLocalSocket instead

Definition at line 62 of file k3socketaddress.h.

Constructor & Destructor Documentation

KNetwork::KIpAddress::KIpAddress ( )
inline

Default constructor.

Creates an empty address. It defaults to IP version 4.

Definition at line 69 of file k3socketaddress.h.

KNetwork::KIpAddress::KIpAddress ( const KIpAddress &  other)
inline

Copy constructor.

Copies the data from the other object.

Data is not shared.

Parameters
otherthe other

Definition at line 80 of file k3socketaddress.h.

KNetwork::KIpAddress::KIpAddress ( const QString &  addr)
inline

Creates an object from the given string representation.

The IP version is guessed from the address format.

Parameters
addrthe address

Definition at line 90 of file k3socketaddress.h.

KNetwork::KIpAddress::KIpAddress ( const char *  addr)
inline

Creates an object from the given string representation.

The IP version is guessed from the address format.

Parameters
addrthe address

Definition at line 100 of file k3socketaddress.h.

KNetwork::KIpAddress::KIpAddress ( const void *  addr,
int  version = 4 
)
inline

Creates an object from the given raw data and IP version.

Parameters
addrthe raw data
versionthe IP version (4 or 6)

Definition at line 109 of file k3socketaddress.h.

KNetwork::KIpAddress::KIpAddress ( quint32  ip4addr)
inline

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.

Parameters
ip4addrthe IPv4 address

Definition at line 122 of file k3socketaddress.h.

KNetwork::KIpAddress::~KIpAddress ( )
inline

Destructor.

This frees resources associated with this object.

Note: destructor is non-virtual. The compiler will happily optimize it out of the way.

Definition at line 131 of file k3socketaddress.h.

Member Function Documentation

const void* KNetwork::KIpAddress::addr ( ) const
inline

Returns a pointer to binary raw data representing the address.

Definition at line 220 of file k3socketaddress.h.

bool KIpAddress::compare ( const KIpAddress &  other,
bool  checkMapped = true 
) const

Compares this address against the other, supplied one and return true if they match.

The checkMapped parameter controls whether a check for an IPv6 v4-mapped address will be performed.

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 checkMapped parameter.

Parameters
otherthe other IP address
checkMappedwhether v4-mapped addresses will be taken into account

Definition at line 100 of file k3socketaddress.cpp.

quint32 KNetwork::KIpAddress::IPv4Addr ( bool  convertMapped = true) const
inline

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 convertMapped parameter is true, the result will also be valid.

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.

Bug:
Check if byte ordering is done right

Definition at line 236 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isClassA ( ) const
inline

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 267 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isClassB ( ) const
inline

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 276 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isClassC ( ) const
inline

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 285 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isClassD ( ) const
inline

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 294 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isGlobal ( ) const
inline

Returns true if this is a global IPv6 address.

Definition at line 332 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isIPv4Addr ( ) const
inline

Returns true if this is an IPv4 address.

Definition at line 177 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isIPv6Addr ( ) const
inline

Returns true if this is an IPv6 address.

Definition at line 183 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isLinkLocal ( ) const
inline

Returns true if this is an IPv6 link-local address.

Definition at line 310 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isLocalhost ( ) const
inline

Returns true if this is either the IPv4 or the IPv6 localhost address.

Definition at line 252 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isLoopback ( ) const
inline

This is an alias for isLocalhost().

Definition at line 258 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isMulticast ( ) const
inline

Returns true if this is a multicast address, be it IPv4 or IPv6.

Definition at line 300 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isMulticastGlobal ( ) const
inline

Returns true if this is an IPv6 global multicast address.

Definition at line 384 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isMulticastLinkLocal ( ) const
inline

Returns true if this is an IPv6 link-local multicast address.

Definition at line 366 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isMulticastNodeLocal ( ) const
inline

Returns true if this is an IPv6 node-local multicast address.

Definition at line 360 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isMulticastOrgLocal ( ) const
inline

Returns true if this is an IPv6 organisational-local multicast address.

Definition at line 378 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isMulticastSiteLocal ( ) const
inline

Returns true if this is an IPv6 site-local multicast address.

Definition at line 372 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isSiteLocal ( ) const
inline

Returns true if this is an IPv6 site-local address.

Definition at line 321 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isUnspecified ( ) const
inline

Returns true if this is the IPv4 or IPv6 unspecified address.

Definition at line 246 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isV4Compat ( ) const
inline

Returns true if this is a v4-compat IPv6 address.

Definition at line 350 of file k3socketaddress.h.

bool KNetwork::KIpAddress::isV4Mapped ( ) const
inline

Returns true if this is a v4-mapped IPv6 address.

Definition at line 338 of file k3socketaddress.h.

KIpAddress & KIpAddress::operator= ( const KIpAddress &  other)

Copy operator.

Copies the data from the other object into this one.

Parameters
otherthe object to copy

Definition at line 91 of file k3socketaddress.cpp.

bool KNetwork::KIpAddress::operator== ( const KIpAddress &  other) const
inline

Returns true if the two addresses match.

This function performs a v4-mapped check.

See also
compare

Definition at line 148 of file k3socketaddress.h.

bool KIpAddress::setAddress ( const QString &  address)

Sets the address to the given string representation.

Returns
true if the address was successfully parsed; otherwise returns false and leaves the object unchanged.

Definition at line 133 of file k3socketaddress.cpp.

bool KIpAddress::setAddress ( const char *  address)

Sets the address to the given string representation.

Returns
true if the address was successfully parsed; otherwise returns false and leaves the object unchanged.

Definition at line 170 of file k3socketaddress.cpp.

bool KIpAddress::setAddress ( const void *  raw,
int  version = 4 
)

Sets the address to the given raw binary representation.

Parameters
rawa pointer to the raw binary data
versionthe IP version
Returns
true if the address was successfully parsed; otherwise returns false and leaves the object unchanged.

Definition at line 176 of file k3socketaddress.cpp.

QString KIpAddress::toString ( ) const

Returns the address as a string.

Definition at line 193 of file k3socketaddress.cpp.

int KNetwork::KIpAddress::version ( ) const
inline

Retrieves the IP version in this object.

Returns
the version: 4 or 6

Definition at line 171 of file k3socketaddress.h.

Member Data Documentation

const KIpAddress KIpAddress::anyhostV4
static

the any host or undefined address in IPv4 (0.0.0.0)

Definition at line 396 of file k3socketaddress.h.

const KIpAddress KIpAddress::anyhostV6
static

the any host or undefined address in IPv6 (::)

Definition at line 401 of file k3socketaddress.h.

const KIpAddress KNetwork::KIpAddress::localhostV4
static

localhost in IPv4 (127.0.0.1)

Definition at line 394 of file k3socketaddress.h.

const KIpAddress KNetwork::KIpAddress::localhostV6
static

localhost in IPv6 (::1)

Definition at line 399 of file k3socketaddress.h.

quint32 KNetwork::KIpAddress::m_data[4]
protected

Definition at line 388 of file k3socketaddress.h.

char KNetwork::KIpAddress::m_version
protected

Definition at line 390 of file k3socketaddress.h.


The documentation for this class was generated from the following files:
  • k3socketaddress.h
  • k3socketaddress.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal