41#ifndef _DWMIPV6PREFIX_HH_
42#define _DWMIPV6PREFIX_HH_
84 inline const in6_addr & In6Addr()
const
159 std::istream &
Read(std::istream & is);
164 std::ostream &
Write(std::ostream & os)
const;
190 bool Read(boost::asio::ip::tcp::socket & s,
191 boost::system::error_code & ec);
197 bool Write(boost::asio::ip::tcp::socket & s,
198 boost::system::error_code & ec)
const;
204 bool Read(boost::asio::local::stream_protocol::socket & s,
205 boost::system::error_code & ec);
211 bool Write(boost::asio::local::stream_protocol::socket & s,
212 boost::system::error_code & ec)
const;
218 bool Read(boost::asio::generic::stream_protocol::socket & s,
219 boost::system::error_code & ec);
225 bool Write(boost::asio::generic::stream_protocol::socket & s,
226 boost::system::error_code & ec)
const;
231 uint64_t StreamedLength()
const
232 {
return (
sizeof(_length) + ((_length + 7) >> 3)); }
257 return XXH32(_addr.s6_addr, (_length + 7) >> 3, 0);
262 alignas(8)
struct in6_addr _addr;
268 inline uint8_t NumAddrBytes()
const
270 return((_length + 7) >> 3);
276 template <
typename S>
277 requires IsSupportedASIOSocket<S>
278 bool ASIO_Read(S & s, boost::system::error_code & ec)
280 using boost::asio::read, boost::asio::buffer;
282 if ((read(s, buffer(&_length,
sizeof(_length)), ec) ==
sizeof(_length))
284 size_t len = (_length + 7) >> 3;
285 if ((read(s, buffer(_addr.s6_addr, len), ec) ==
sizeof(_length))
296 template <
typename S>
297 requires IsSupportedASIOSocket<S>
298 bool ASIO_Write(S & s, boost::system::error_code & ec)
const
300 using boost::asio::write, boost::asio::buffer;
302 if ((write(s, buffer(&_length,
sizeof(_length)), ec) ==
sizeof(_length))
304 size_t len = (_length + 7) >> 3;
305 if ((write(s, buffer(_addr.s6_addr, len), ec) ==
sizeof(_addr.s6_addr))
Dwm::Ipv6Address class definition.
This class encapsulates an IPv6 address.
Definition DwmIpv6Address.hh:64
This class encapsulates an IPv6 network prefix.
Definition DwmIpv6Prefix.hh:52
bool operator==(const Ipv6Prefix &prefix) const
Equal-to operator.
std::ostream & Write(std::ostream &os) const
Writes the prefix to an ostream. Returns the ostream.
bool Read(boost::asio::local::stream_protocol::socket &s, boost::system::error_code &ec)
Reads the prefix from s.
Ipv6Address Network() const
Returns the network address.
bool operator<(const Ipv6Prefix &prefix) const
Less-than operator.
bool Read(boost::asio::generic::stream_protocol::socket &s, boost::system::error_code &ec)
Reads the prefix from s.
int BZRead(BZFILE *bzf)
Reads the prefix from a BZFILE pointer.
ssize_t Read(int fd)
Reads the prefix from a file descriptor.
std::string ToString() const
Returns a string representation of the prefix in the usual form, for example "1234:5678::/32".
Ipv6Prefix(const Ipv6Prefix &prefix)
Copy constructor.
Ipv6Prefix(const Ipv6Address &network, uint8_t maskLength)
Construct from an IPv6 network address and netmask length.
bool operator>(const Ipv6Prefix &prefix) const
Greater-than operator.
Ipv6Prefix(const std::string &prefix)
Construct from a string.
bool Set(const Ipv6Address &network, uint8_t maskLength)
Set the prefix using a network address and netmask length.
friend std::ostream & operator<<(std::ostream &os, const Ipv6Prefix &prefix)
Prints a prefix to an ostream in the usual colon-delimited form.
bool Read(boost::asio::ip::tcp::socket &s, boost::system::error_code &ec)
Reads the prefix from s.
bool Write(boost::asio::generic::stream_protocol::socket &s, boost::system::error_code &ec) const
Writes the prefix to s.
size_t Write(FILE *f) const
Writes the prefix to a FILE pointer.
size_t Read(FILE *f)
Reads the prefix from a FILE pointer.
bool operator!=(const Ipv6Prefix &prefix) const
Not-equal-to operator.
uint64_t Hash() const
Given that the number of IPv6 addresses I typically deal with is nowhere near 4 billion,...
Definition DwmIpv6Prefix.hh:255
ssize_t Write(int fd) const
Writes the prefix to a file descriptor.
bool Write(boost::asio::ip::tcp::socket &s, boost::system::error_code &ec) const
Writes the prefix to s.
uint8_t MaskLength(uint8_t maskLen)
Sets and returns the netmask length.
int Read(gzFile gzf)
Reads the prefix from a gzFile.
bool Write(boost::asio::local::stream_protocol::socket &s, boost::system::error_code &ec) const
Writes the prefix to s.
std::istream & Read(std::istream &is)
Reads the prefix from an istream. Returns the istream.
uint8_t MaskLength() const
Returns the netmask length.
Definition DwmIpv6Prefix.hh:95
int BZWrite(BZFILE *bzf) const
Writes the prefix to a BZFILE pointer.
bool Contains(const Ipv6Address &addr) const
Returns true if addr falls within the prefix.
Ipv6Address Netmask() const
Returns the netmask.
int Write(gzFile gzf) const
Writes the prefix to a gzFile.