13#include <boost/static_assert.hpp>
15#include <boost/functional/hash.hpp>
19#include <sys/socket.h>
20#include <netinet/in.h>
23using boost::asio::ip::udp;
24using boost::asio::ip::tcp;
39 boost::system::error_code err;
40 asio_address_ = ip::address::from_string(address_str, err);
43 << address_str <<
"': " << err.message());
48 asio_address_(asio_address)
52 asio_address_(
boost::asio::ip::address_v4(v4address)) {
58 return (asio_address_.to_string());
65 }
else if ((family != AF_INET) && (family != AF_INET6)) {
70 BOOST_STATIC_ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
71 char addr_str[INET6_ADDRSTRLEN];
72 inet_ntop(family, data, addr_str, INET6_ADDRSTRLEN);
78 if (asio_address_.is_v4()) {
79 const boost::asio::ip::address_v4::bytes_type bytes4 =
80 asio_address_.to_v4().to_bytes();
81 return (std::vector<uint8_t>(bytes4.begin(), bytes4.end()));
86 const boost::asio::ip::address_v6::bytes_type bytes6 =
87 asio_address_.to_v6().to_bytes();
88 return (std::vector<uint8_t>(bytes6.begin(), bytes6.end()));
93 if (asio_address_.is_v4()) {
102 if (!asio_address_.is_v6()) {
105 return (asio_address_.to_v6().is_link_local());
110 if (!asio_address_.is_v6()) {
113 return (asio_address_.to_v6().is_multicast());
118 if (asio_address_.is_v4()) {
119 return (asio_address_.to_v4().to_ulong());
122 <<
" address to IPv4.");
144 vector<uint8_t> a_vec = a.
toBytes();
145 vector<uint8_t> b_vec = b.
toBytes();
148 vector<uint8_t> result(V6ADDRESS_LEN,0);
157 for (
int i = a_vec.size() - 1; i >= 0; --i) {
158 result[i] = a_vec[i] - b_vec[i] - carry;
159 carry = (a_vec[i] < b_vec[i] + carry);
162 return (
fromBytes(AF_INET6, &result[0]));
168 std::vector<uint8_t> packed(addr.
toBytes());
171 for (
int i = packed.size() - 1; i >= 0; --i) {
173 if (++packed[i] != 0) {
183 if (address.
isV4()) {
184 boost::hash<uint32_t> hasher;
185 return (hasher(address.
toUint32()));
187 boost::hash<std::vector<uint8_t> > hasher;
188 return (hasher(address.
toBytes()));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
static IOAddress subtract(const IOAddress &a, const IOAddress &b)
Subtracts one address from another (a - b)
std::string toText() const
Convert the address to a string.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV4() const
Convenience function to check for an IPv4 address.
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
static IOAddress increase(const IOAddress &addr)
Returns an address increased by one.
IOAddress(const std::string &address_str)
Constructor from string.
bool isV6LinkLocal() const
checks whether and address is IPv6 and is link-local
short getFamily() const
Returns the address family.
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
An exception that is thrown if an error occurs within the IO module.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A wrapper interface for the ASIO library.
std::ostream & operator<<(std::ostream &os, const IOAddress &address)
Insert the IOAddress as a string into stream.
size_t hash_value(const IOAddress &address)
Hash the IOAddress.
Defines the logger used by the top-level component of kea-lfc.
size_t operator()(const IOAddress &io_address) const
A hashing operator.