Kea  1.9.9-git
isc::asiolink::IOAddress Class Reference

The IOAddress class represents an IP addresses (version agnostic) More...

#include <io_address.h>

Public Member Functions

 IOAddress (uint32_t v4address)
 Constructor for ip::address_v4 object. More...
 
bool equals (const IOAddress &other) const
 Compare addresses for equality. More...
 
short getFamily () const
 Returns the address family. More...
 
bool isV4 () const
 Convenience function to check for an IPv4 address. More...
 
bool isV4Bcast () const
 Convenience function to check if it is an IPv4 broadcast address. More...
 
bool isV4Zero () const
 Convenience function to check if it is an IPv4 zero address. More...
 
bool isV6 () const
 Convenience function to check for an IPv6 address. More...
 
bool isV6LinkLocal () const
 checks whether and address is IPv6 and is link-local More...
 
bool isV6Multicast () const
 checks whether and address is IPv6 and is multicast More...
 
bool isV6Zero () const
 Convenience function to check if it is an IPv4 zero address. More...
 
bool nequals (const IOAddress &other) const
 Compare addresses for inequality. More...
 
bool operator!= (const IOAddress &other) const
 Compare addresses for inequality. More...
 
bool operator< (const IOAddress &other) const
 Checks if one address is smaller than the other. More...
 
bool operator<= (const IOAddress &other) const
 Checks if one address is smaller or equal than the other. More...
 
bool operator== (const IOAddress &other) const
 Compare addresses for equality. More...
 
std::vector< uint8_t > toBytes () const
 Return address as set of bytes. More...
 
std::string toText () const
 Convert the address to a string. More...
 
uint32_t toUint32 () const
 Converts IPv4 address to uint32_t. More...
 
Constructors and Destructor

This class is copyable.

We use default versions of copy constructor and the assignment operator. We use the default destructor.

 IOAddress (const std::string &address_str)
 Constructor from string. More...
 
 IOAddress (const boost::asio::ip::address &asio_address)
 Constructor from an ASIO ip::address object. More...
 

Static Public Member Functions

static IOAddress fromBytes (short family, const uint8_t *data)
 Creates an address from over wire data. More...
 
static IOAddress increase (const IOAddress &addr)
 Returns an address increased by one. More...
 
static IOAddress subtract (const IOAddress &a, const IOAddress &b)
 Subtracts one address from another (a - b) More...
 
Methods returning @c IOAddress objects encapsulating typical addresses.
static const IOAddressIPV4_ZERO_ADDRESS ()
 Returns an address set to all zeros. More...
 
static const IOAddressIPV4_BCAST_ADDRESS ()
 Returns a "255.255.255.255" broadcast address. More...
 
static const IOAddressIPV6_ZERO_ADDRESS ()
 Returns an IPv6 zero address. More...
 

Detailed Description

The IOAddress class represents an IP addresses (version agnostic)

This class is a wrapper for the ASIO ip::address class.

Definition at line 45 of file io_address.h.

Constructor & Destructor Documentation

isc::asiolink::IOAddress::IOAddress ( const std::string &  address_str)

Constructor from string.

This constructor converts a textual representation of IPv4 and IPv6 addresses into an IOAddress object. If address_str is not a valid representation of any type of address, an exception of class IOError will be thrown. This constructor allocates memory for the object, and if that fails a corresponding standard exception will be thrown.

Parameters
address_strTextual representation of address.

Definition at line 33 of file io_address.cc.

References isc_throw.

Referenced by fromBytes(), and subtract().

isc::asiolink::IOAddress::IOAddress ( const boost::asio::ip::address &  asio_address)

Constructor from an ASIO ip::address object.

This constructor is intended to be used within the wrapper implementation; user applications of the wrapper API won't use it.

This constructor never throws an exception.

Parameters
asio_addressThe ASIO ip::address to be converted.

Definition at line 42 of file io_address.cc.

isc::asiolink::IOAddress::IOAddress ( uint32_t  v4address)

Constructor for ip::address_v4 object.

This constructor is intended to be used when constructing IPv4 address out of uint32_t type. Passed value must be in network byte order

Parameters
v4addressIPv4 address represented by uint32_t

Definition at line 46 of file io_address.cc.

Member Function Documentation

bool isc::asiolink::IOAddress::equals ( const IOAddress other) const
inline

Compare addresses for equality.

Parameters
otherAddress to compare against.
Returns
true if addresses are equal, false if not.

Definition at line 165 of file io_address.h.

Referenced by isV4Bcast(), isV4Zero(), isV6Zero(), nequals(), and operator==().

IOAddress isc::asiolink::IOAddress::fromBytes ( short  family,
const uint8_t *  data 
)
static
IOAddress isc::asiolink::IOAddress::increase ( const IOAddress addr)
static

Returns an address increased by one.

This method works for both IPv4 and IPv6 addresses. For example, increase 192.0.2.255 will become 192.0.3.0.

Address space is a finite field in the mathematical sense, so keep in mind that the address space "loops". 255.255.255.255 increased by one gives 0.0.0.0. The same is true for maximum value of IPv6 (all 1's) looping to ::.

Todo:
Determine if we have a use-case for increasing the address by more than one. Increase by one is used in AllocEngine. This method could take extra parameter that specifies the value by which the address should be increased.
Parameters
addraddress to be increased
Returns
address increased by one

Definition at line 163 of file io_address.cc.

References fromBytes(), getFamily(), and toBytes().

Referenced by isc::asiolink::addrsInRange(), and isc::dhcp::AllocEngine::IterativeAllocator::increaseAddress().

+ Here is the call graph for this function:

static const IOAddress& isc::asiolink::IOAddress::IPV4_BCAST_ADDRESS ( )
inlinestatic

Returns a "255.255.255.255" broadcast address.

Definition at line 272 of file io_address.h.

Referenced by isc::dhcp::Dhcpv4Srv::adjustRemoteAddr(), and isV4Bcast().

bool isc::asiolink::IOAddress::isV4 ( ) const
inline

Convenience function to check for an IPv4 address.

Returns
true if the address is a V4 address

Definition at line 103 of file io_address.h.

Referenced by isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::db::PsqlBindArray::add(), isc::dhcp::Option4AddrLst::addAddress(), isc::dhcp::OptionCustom::addArrayDataField(), isc::asiolink::addrsInRange(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::PgSqlHostDataSource::del(), isc::asiolink::firstAddrInPrefix(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::dhcp::MySqlHostDataSource::get4(), isc::dhcp::PgSqlHostDataSource::get4(), isc::dhcp::CqlHostDataSourceImpl::get4(), isc::dhcp::MySqlHostDataSource::getAll4(), isc::dhcp::PgSqlHostDataSource::getAll4(), isc::dhcp::CqlLeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::PgSqlLeaseMgr::getLeases4(), isc::dhcp::MySqlLeaseMgr::getLeases4(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::asiolink::hash_value(), isc::dhcp::IfaceMgr::hasOpenSocket(), isc::dhcp_ddns::NameChangeRequest::isV4(), isc::asiolink::lastAddrInPrefix(), isc::dhcp::IPRangePermutation::next(), isc::asiolink::offsetAddress(), isc::dhcp_ddns::NameChangeUDPListener::open(), isc::dhcp_ddns::NameChangeUDPSender::open(), isc::dhcp::IfaceMgr::openSocket(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::D2ClientConfigParser::parse(), isc::dhcp::Pool4::Pool4(), isc::asiolink::prefixLengthFromRange(), isc::d2::D2CfgMgr::reverseIpAddress(), isc::d2::D2CfgMgr::reverseV4Address(), isc::perfdhcp::TestControl::sendRequest4(), isc::dhcp::Option4AddrLst::setAddress(), isc::dhcp::Host::setIPv4Reservation(), isc::dhcp::Host::setNextServer(), isc::dhcp::Network4::setSiaddr(), isc::dhcp::Subnet::Subnet(), isc::dhcp::Subnet4::Subnet4(), subtract(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), and isc::dhcp::OptionCustom::writeAddress().

bool isc::asiolink::IOAddress::isV4Bcast ( ) const
inline

Convenience function to check if it is an IPv4 broadcast address.

Returns
true if the address is the broadcast IPv4 address.

Definition at line 118 of file io_address.h.

References equals(), and IPV4_BCAST_ADDRESS().

Referenced by isc::dhcp::Dhcpv4Srv::adjustIfaceData(), isc::dhcp::Dhcpv4Srv::appendServerID(), isc::dhcp::Pkt4::isRelayed(), isc::dhcp::ClientClassDefParser::parse(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::Host::setIPv4Reservation(), and isc::dhcp::Host::setNextServer().

+ Here is the call graph for this function:

bool isc::asiolink::IOAddress::isV4Zero ( ) const
inline
bool isc::asiolink::IOAddress::isV6LinkLocal ( ) const

checks whether and address is IPv6 and is link-local

Returns
true if the address is IPv6 link-local, false otherwise

Definition at line 97 of file io_address.cc.

Referenced by isc::dhcp::Pkt::getMACFromIPv6(), isc::dhcp::CfgSubnets6::initSelector(), isc::dhcp::PktFilterInet6::openSocket(), isc::dhcp::PktFilterInet6::receive(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), and isc::dhcp::CfgIface::use().

bool isc::asiolink::IOAddress::isV6Multicast ( ) const

checks whether and address is IPv6 and is multicast

Returns
true if the address is IPv6 multicast, false otherwise

Definition at line 105 of file io_address.cc.

Referenced by isc::dhcp::PktFilterInet6::openSocket(), isc::perfdhcp::PerfSocket::openSocket(), isc::dhcp::PktFilterInet6::receive(), isc::dhcp::IPv6Resrv::set(), and isc::dhcp::CfgIface::use().

bool isc::asiolink::IOAddress::isV6Zero ( ) const
inline

Convenience function to check if it is an IPv4 zero address.

Returns
true if the address is the zero IPv4 address.

Definition at line 132 of file io_address.h.

References equals(), and IPV6_ZERO_ADDRESS().

Referenced by isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap(), isc::dhcp::CqlLeaseMgr::getLeases6(), isc::dhcp::PgSqlLeaseMgr::getLeases6(), isc::dhcp::MySqlLeaseMgr::getLeases6(), isc::dhcp::CfgSubnets6::initSelector(), isc::dhcp::Pool6::Pool6(), and isc::dhcp::Dhcpv4Srv::selectSubnet4o6().

+ Here is the call graph for this function:

bool isc::asiolink::IOAddress::nequals ( const IOAddress other) const
inline

Compare addresses for inequality.

Parameters
otherAddress to compare against.
Returns
false if addresses are equal, true if not.

Definition at line 183 of file io_address.h.

References equals().

Referenced by operator!=().

+ Here is the call graph for this function:

bool isc::asiolink::IOAddress::operator!= ( const IOAddress other) const
inline

Compare addresses for inequality.

Parameters
otherAddress to compare against.
Returns
false if addresses are equal, true if not.

Definition at line 206 of file io_address.h.

References nequals().

+ Here is the call graph for this function:

bool isc::asiolink::IOAddress::operator< ( const IOAddress other) const
inline

Checks if one address is smaller than the other.

Parameters
otherAddress to compare against.

Definition at line 190 of file io_address.h.

bool isc::asiolink::IOAddress::operator<= ( const IOAddress other) const
inline

Checks if one address is smaller or equal than the other.

Parameters
otherAddress to compare against.

Definition at line 197 of file io_address.h.

bool isc::asiolink::IOAddress::operator== ( const IOAddress other) const
inline

Compare addresses for equality.

Parameters
otherAddress to compare against.
Returns
true if addresses are equal, false if not.

Definition at line 174 of file io_address.h.

References equals().

+ Here is the call graph for this function:

IOAddress isc::asiolink::IOAddress::subtract ( const IOAddress a,
const IOAddress b 
)
static

Subtracts one address from another (a - b)

Treats addresses as integers and subtracts them. For example:

192.0.2.5 - 192.0.2.0 = 0.0.0.5
fe80::abcd - fe80:: = ::abcd

It is possible to subtract greater from lesser address, e.g. 192.168.56.10 - 192.168.67.20, but please do understand that the address space is a finite field in mathematical sense, so you may end up with a result that is greater then any of the addresses you specified. Also, subtraction is not commutative, so a - b != b - a.

This operation is essential for calculating the number of leases in a pool, where we need to calculate (max - min).

Exceptions
BadValueif addresses are of different family
Parameters
aaddress to be subtracted from
baddress to be subtracted
Returns
IOAddress object that represents the difference

Definition at line 129 of file io_address.cc.

References fromBytes(), getFamily(), IOAddress(), isc_throw, isV4(), toBytes(), and toUint32().

Referenced by isc::asiolink::addrsInRange().

+ Here is the call graph for this function:

string isc::asiolink::IOAddress::toText ( ) const

Convert the address to a string.

This method is basically expected to be exception free, but generating the string will involve resource allocation, and if it fails the corresponding standard exception will be thrown.

Returns
A string representation of the address.

Definition at line 52 of file io_address.cc.

Referenced by isc::db::PsqlBindArray::add(), isc::dhcp::Network::RelayInfo::addAddress(), isc::asiolink::addrsInRange(), isc::dhcp::CSVLeaseFile6::append(), isc::dhcp::CSVLeaseFile4::append(), isc::db::MySqlBinding::condCreateIPv4Address(), isc::agent::CtrlAgentProcess::configure(), isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::PgSqlHostDataSource::del(), isc::dhcp::CqlLeaseMgr::deleteLease(), isc::dhcp::PgSqlLeaseMgr::deleteLease(), isc::dhcp::MySqlLeaseMgr::deleteLease(), isc::dhcp::Subnet6ConfigParser::duplicate_option_warning(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::dhcp::HostMgr::get4(), isc::dhcp::CfgHosts::get4(), isc::dhcp::MySqlHostDataSource::get6(), isc::dhcp::HostMgr::get6(), isc::dhcp::CqlHostDataSourceImpl::get6(), isc::yang::TranslatorPool::getAddresses(), getAddrStrIA_NA(), getAddrStrIA_PD(), isc::dhcp::HostMgr::getAll4(), isc::dhcp::CfgHosts::getAll4(), isc::dhcp::MySqlHostDataSource::getAll6(), isc::dhcp::HostMgr::getAll6(), isc::dhcp_ddns::NameChangeRequest::getIpAddress(), isc::dhcp::CqlLeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::PgSqlLeaseMgr::getLease4(), isc::dhcp::MySqlLeaseMgr::getLease4(), isc::dhcp::CqlLeaseMgr::getLease6(), isc::dhcp::Memfile_LeaseMgr::getLease6(), isc::dhcp::PgSqlLeaseMgr::getLease6(), isc::dhcp::MySqlLeaseMgr::getLease6(), isc::dhcp::CqlLeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::PgSqlLeaseMgr::getLeases4(), isc::dhcp::MySqlLeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::CqlLeaseMgr::getLeases6(), isc::dhcp::PgSqlLeaseMgr::getLeases6(), isc::dhcp::MySqlLeaseMgr::getLeases6(), isc::lease_cmds::LeaseCmdsImpl::lease4ResendDdnsHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6ResendDdnsHandler(), isc::dhcp::CSVLeaseFile4::next(), isc::dhcp::PktFilterInet6::openSocket(), isc::asiolink::operator<<(), isc::lease_cmds::Lease4Parser::parse(), isc::d2::D2SimpleParser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::dhcp::D2ClientConfigParser::parse(), pkt4_send(), isc::asiolink::prefixLengthFromRange(), isc::dhcp::CqlHostExchange::prepareExchange(), isc::dhcp::CfgSubnets6::selectSubnet(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::Subnet4::Subnet4(), isc::d2::D2CfgContext::toElement(), isc::dhcp::D2ClientConfig::toElement(), isc::dhcp::ClientClassDef::toElement(), isc::dhcp::Pool4::toElement(), isc::dhcp::Pool6::toElement(), isc::dhcp::Lease4::toElement(), isc::d2::DnsServerInfo::toElement(), isc::dhcp::Lease6::toElement(), isc::dhcp::Host::toElement4(), isc::dhcp::D2ClientConfig::toText(), isc::d2::D2Params::toText(), isc::d2::DnsServerInfo::toText(), isc::dhcp::Host::toText(), toUint32(), isc::dhcp::ResourceHandler::unLock(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), isc::d2::D2Params::validateContents(), isc::dhcp::Subnet4ConfigParser::validateResv(), and isc::dhcp::Subnet6ConfigParser::validateResvs().


The documentation for this class was generated from the following files: