Kea 2.7.6
isc::asiolink::IOAddress Class Reference

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

#include <io_address.h>

Classes

struct  Hash
 An IOAddress hash enabling the use in the unordered STL containers. More...
 

Methods returning @c IOAddress objects encapsulating typical addresses.

static const IOAddressIPV4_ZERO_ADDRESS ()
 Returns an address set to all zeros.
 
static const IOAddressIPV4_BCAST_ADDRESS ()
 Returns a "255.255.255.255" broadcast address.
 
static const IOAddressIPV6_ZERO_ADDRESS ()
 Returns an IPv6 zero address.
 

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.
 
 IOAddress (const boost::asio::ip::address &asio_address)
 Constructor from an ASIO ip::address object.
 
 IOAddress (uint32_t v4address)
 Constructor for ip::address_v4 object.
 
std::string toText () const
 Convert the address to a string.
 
short getFamily () const
 Returns the address family.
 
bool isV4 () const
 Convenience function to check for an IPv4 address.
 
bool isV4Zero () const
 Convenience function to check if it is an IPv4 zero address.
 
bool isV4Bcast () const
 Convenience function to check if it is an IPv4 broadcast address.
 
bool isV6 () const
 Convenience function to check for an IPv6 address.
 
bool isV6Zero () const
 Convenience function to check if it is an IPv4 zero address.
 
bool isV6LinkLocal () const
 checks whether and address is IPv6 and is link-local
 
bool isV6Multicast () const
 checks whether and address is IPv6 and is multicast
 
std::vector< uint8_t > toBytes () const
 Return address as set of bytes.
 
bool equals (const IOAddress &other) const
 Compare addresses for equality.
 
bool operator== (const IOAddress &other) const
 Compare addresses for equality.
 
bool nequals (const IOAddress &other) const
 Compare addresses for inequality.
 
bool operator< (const IOAddress &other) const
 Checks if one address is smaller than the other.
 
bool operator<= (const IOAddress &other) const
 Checks if one address is smaller or equal than the other.
 
bool operator!= (const IOAddress &other) const
 Compare addresses for inequality.
 
uint32_t toUint32 () const
 Converts IPv4 address to uint32_t.
 
static IOAddress fromBytes (short family, const uint8_t *data)
 Creates an address from over wire data.
 
static IOAddress subtract (const IOAddress &a, const IOAddress &b)
 Subtracts one address from another (a - b)
 
static IOAddress increase (const IOAddress &addr)
 Returns an address increased by one.
 

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

◆ IOAddress() [1/3]

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 38 of file io_address.cc.

References isc_throw.

Referenced by fromBytes(), and subtract().

◆ IOAddress() [2/3]

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 47 of file io_address.cc.

◆ IOAddress() [3/3]

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 host byte order.

Parameters
v4addressIPv4 address represented by uint32_t

Definition at line 51 of file io_address.cc.

Member Function Documentation

◆ equals()

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 176 of file io_address.h.

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

◆ fromBytes()

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

Creates an address from over wire data.

Parameters
familyAF_INET for IPv4 or AF_INET6 for IPv6.
datapointer to first char of data
Returns
Created IOAddress object

Definition at line 62 of file io_address.cc.

References IOAddress(), and isc_throw.

Referenced by isc::dhcp::TokenIpAddressToText::evaluate(), isc::dhcp::Option6PDExclude::getExcludedPrefix(), increase(), isc::dhcp::IterativeAllocator::increasePrefix(), isc::dhcp::CfgSubnets4::initSelector(), isc::asiolink::offsetAddress(), isc::dhcp::OptionDataTypeUtil::readAddress(), isc::dhcp::OptionDataTypeUtil::readPrefix(), subtract(), isc::dhcp::Option6AddrLst::unpack(), isc::dhcp::Option6IAAddr::unpack(), isc::dhcp::Option6IAPrefix::unpack(), isc::dhcp::Option6Dnr::unpackAddresses(), and isc::dhcp::Pkt6::unpackRelayMsg().

+ Here is the call graph for this function:

◆ getFamily()

◆ increase()

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 167 of file io_address.cc.

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

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

+ Here is the call graph for this function:

◆ IPV4_BCAST_ADDRESS()

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

Returns a "255.255.255.255" broadcast address.

Definition at line 283 of file io_address.h.

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

◆ IPV4_ZERO_ADDRESS()

◆ IPV6_ZERO_ADDRESS()

◆ isV4()

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 114 of file io_address.h.

Referenced by isc::dhcp::Pool4::Pool4(), isc::dhcp::Pool4::Pool4(), isc::dhcp::Subnet::Subnet(), isc::dhcp::Subnet4::Subnet4(), isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::db::PsqlBindArray::add(), isc::dhcp::Option4AddrLst::addAddress(), isc::dhcp::OptionCustom::addArrayDataField(), isc::db::PsqlBindArray::addInet4(), isc::asiolink::addrsInRange(), isc::dhcp::IfaceMgr::collectBoundAddresses(), isc::dhcp::SubnetConfigParser::createSubnet(), isc::dhcp::CfgHosts::del(), isc::asiolink::firstAddrInPrefix(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::db::PgSqlExchange::getInetValue4(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRemoteId(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::asiolink::hash_value(), isc::dhcp::IfaceMgr::hasOpenSocket(), 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::dhcp::D2ClientConfigParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), isc::asiolink::prefixLengthFromRange(), isc::d2::D2CfgMgr::reverseIpAddress(), isc::d2::D2CfgMgr::reverseV4Address(), isc::perfdhcp::TestControl::sendRequest4(), isc::perfdhcp::TestControl::sendRequest4(), isc::dhcp::Option4AddrLst::setAddress(), isc::dhcp::Host::setIPv4Reservation(), isc::dhcp::Host::setNextServer(), subtract(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), and isc::dhcp::OptionCustom::writeAddress().

◆ isV4Bcast()

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 129 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:

◆ isV4Zero()

bool isc::asiolink::IOAddress::isV4Zero ( ) 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 121 of file io_address.h.

References equals(), and IPV4_ZERO_ADDRESS().

Referenced by isc::dhcp::Host::Host(), isc::dhcp::Host::Host(), isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::Dhcpv4Srv::evaluateAdditionalClasses(), isc::dhcp::Pkt4::isRelayed(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::Dhcpv4Srv::setFixedFields(), isc::dhcp::Host::setIPv4Reservation(), isc::dhcp::Host::toElement4(), isc::dhcp::Host::toText(), and isc::dhcp::Subnet4ConfigParser::validateResv().

+ Here is the call graph for this function:

◆ isV6()

◆ isV6LinkLocal()

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 101 of file io_address.cc.

Referenced by isc::dhcp::Pkt::getMACFromIPv6(), isc::dhcp::PktFilterInet6::openSocket(), and isc::dhcp::CfgIface::use().

◆ isV6Multicast()

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 109 of file io_address.cc.

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

◆ isV6Zero()

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 143 of file io_address.h.

References equals(), and IPV6_ZERO_ADDRESS().

Referenced by isc::dhcp::Pool6::Pool6(), and isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap().

+ Here is the call graph for this function:

◆ nequals()

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 194 of file io_address.h.

References equals().

Referenced by operator!=().

+ Here is the call graph for this function:

◆ operator!=()

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 217 of file io_address.h.

References nequals().

+ Here is the call graph for this function:

◆ operator<()

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 201 of file io_address.h.

◆ operator<=()

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 208 of file io_address.h.

◆ operator==()

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 185 of file io_address.h.

References equals().

+ Here is the call graph for this function:

◆ subtract()

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 133 of file io_address.cc.

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

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

+ Here is the call graph for this function:

◆ toBytes()

◆ toText()

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 57 of file io_address.cc.

Referenced by isc::db::PsqlBindArray::add(), isc::dhcp::Network::RelayInfo::addAddress(), isc::db::PsqlBindArray::addInet4(), isc::db::PsqlBindArray::addInet6(), isc::perfdhcp::TestControl::address6Uniqueness(), isc::asiolink::addrsInRange(), isc::dhcp::CSVLeaseFile4::append(), isc::dhcp::CSVLeaseFile6::append(), isc::dhcp::Dhcpv6Srv::assignIA_NA(), isc::dhcp::Dhcpv6Srv::assignIA_PD(), isc::dhcp::Dhcpv4Srv::assignLease(), isc::agent::CtrlAgentProcess::configure(), isc::config::HttpCommandMgrImpl::configure(), isc::lease_cmds::LeaseCmdsImpl::createFailedLeaseMap(), isc::dhcp::CfgHosts::del(), isc::dhcp::Subnet6ConfigParser::duplicateOptionWarning(), isc::dhcp::TokenIpAddressToText::evaluate(), isc::dhcp::D2ClientMgr::generateFqdn(), isc::dhcp::CfgHosts::get4(), isc::dhcp::HostMgr::get4(), isc::dhcp::HostMgr::get6(), isc::dhcp::HostMgr::get6(), isc::yang::TranslatorPool::getAddresses(), getAddrStrIA_NA(), getAddrStrIA_PD(), isc::dhcp::HostMgr::getAll4(), isc::dhcp::HostMgr::getAll6(), isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::Memfile_LeaseMgr::getLease6(), isc::dhcp::Memfile_LeaseMgr::getLeases4(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases4ByRemoteId(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRelayId(), isc::dhcp::Memfile_LeaseMgr::getLeases6ByRemoteId(), isc::lease_cmds::LeaseCmdsImpl::lease4ResendDdnsHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6ResendDdnsHandler(), isc::dhcp::CSVLeaseFile4::next(), isc::dhcp::PktFilterInet6::openSocket(), isc::dhcp::PktFilterInet::openSocket(), isc::dhcp::PktFilterLPF::openSocket(), isc::asiolink::operator<<(), isc::dhcp::D2ClientConfigParser::parse(), isc::lease_cmds::Lease4Parser::parse(), isc::lease_cmds::Lease6Parser::parse(), pkt4_send(), isc::asiolink::prefixLengthFromRange(), isc::dhcp::Dhcpv4Srv::processDecline(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::CfgSubnets4::selectSubnet(), isc::dhcp::CfgSubnets6::selectSubnet(), isc::config::HttpCommandConfig::toElement(), isc::d2::D2CfgContext::toElement(), isc::d2::DnsServerInfo::toElement(), isc::dhcp::ClientClassDef::toElement(), isc::dhcp::D2ClientConfig::toElement(), isc::dhcp::Lease4::toElement(), isc::dhcp::Lease6::toElement(), isc::dhcp::Pool4::toElement(), isc::dhcp::Pool6::toElement(), isc::dhcp::Host::toElement4(), isc::d2::D2Params::toText(), isc::d2::DnsServerInfo::toText(), isc::dhcp::D2ClientConfig::toText(), isc::dhcp::Host::toText(), toUint32(), isc::dhcp::ResourceHandler::unLock(), isc::dhcp::CfgIface::use(), isc::dhcp::D2ClientConfig::validateContents(), isc::dhcp::Subnet4ConfigParser::validateResv(), and isc::dhcp::Subnet6ConfigParser::validateResvs().

◆ toUint32()

uint32_t isc::asiolink::IOAddress::toUint32 ( ) const

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