Kea 2.5.5
io_address.h
Go to the documentation of this file.
1// Copyright (C) 2010-2023 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef IO_ADDRESS_H
8#define IO_ADDRESS_H 1
9
10// IMPORTANT NOTE: only very few ASIO headers files can be included in
11// this file. In particular, asio.hpp should never be included here.
12// See the description of the namespace below.
13#include <unistd.h> // for some network system calls
14#include <stdint.h> // for uint32_t
15#include <boost/asio/ip/address.hpp>
16
17#include <functional>
18#include <string>
19#include <vector>
20
22
23namespace isc {
24namespace asiolink {
25
27 static constexpr size_t V6ADDRESS_LEN = 16;
28
30 static constexpr size_t V4ADDRESS_LEN = 4;
31
34 static constexpr size_t V4ADDRESS_TEXT_MAX_LEN = 15u;
35
39 static constexpr size_t V6ADDRESS_TEXT_MAX_LEN = 39u;
40
45class IOAddress {
46public:
47
50 struct Hash {
55 size_t operator()(const IOAddress &io_address) const;
56 };
57
64
65
75 IOAddress(const std::string& address_str);
76
85 IOAddress(const boost::asio::ip::address& asio_address);
87
95 IOAddress(uint32_t v4address);
96
104 std::string toText() const;
105
109 short getFamily() const;
110
114 bool isV4() const {
115 return (asio_address_.is_v4());
116 }
117
121 bool isV4Zero() const {
122 return (equals(IPV4_ZERO_ADDRESS()));
123 }
124
129 bool isV4Bcast() const {
130 return (equals(IPV4_BCAST_ADDRESS()));
131 }
132
136 bool isV6() const {
137 return (asio_address_.is_v6());
138 }
139
143 bool isV6Zero() const {
144 return (equals(IPV6_ZERO_ADDRESS()));
145 }
146
150 bool isV6LinkLocal() const;
151
155 bool isV6Multicast() const;
156
163 static IOAddress fromBytes(short family, const uint8_t* data);
164
169 std::vector<uint8_t> toBytes() const;
170
176 bool equals(const IOAddress& other) const {
177 return (asio_address_ == other.asio_address_);
178 }
179
185 bool operator==(const IOAddress& other) const {
186 return equals(other);
187 }
188
194 bool nequals(const IOAddress& other) const {
195 return (!equals(other));
196 }
197
201 bool operator<(const IOAddress& other) const {
202 return (asio_address_ < other.asio_address_);
203 }
204
208 bool operator<=(const IOAddress& other) const {
209 return (asio_address_ <= other.asio_address_);
210 }
211
217 bool operator!=(const IOAddress& other) const {
218 return (nequals(other));
219 }
220
242 static IOAddress subtract(const IOAddress& a, const IOAddress& b);
243
261 static IOAddress
262 increase(const IOAddress& addr);
263
271 uint32_t toUint32() const;
272
275
276
277 static const IOAddress& IPV4_ZERO_ADDRESS() {
278 static IOAddress address(0);
279 return (address);
280 }
281
284 static IOAddress address(0xFFFFFFFF);
285 return (address);
286 }
287
289 static const IOAddress& IPV6_ZERO_ADDRESS() {
290 static IOAddress address("::");
291 return (address);
292 }
293
295
296private:
297 boost::asio::ip::address asio_address_;
298};
299
313std::ostream&
314operator<<(std::ostream& os, const IOAddress& address);
315
325size_t hash_value(const IOAddress& address);
326
327} // namespace asiolink
328} // namespace isc
329#endif // IO_ADDRESS_H
Defines the logger used by the top-level component of kea-lfc.