2020-10-10 18:37:02 +00:00
|
|
|
#pragma once
|
2019-06-15 14:20:32 +00:00
|
|
|
#include <array>
|
2020-11-08 16:01:12 +00:00
|
|
|
#include <common/types.h>
|
2019-06-15 14:20:32 +00:00
|
|
|
|
|
|
|
namespace Poco { namespace Net { class IPAddress; }}
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-11-21 14:56:58 +00:00
|
|
|
/// Convert IP address to raw binary with IPv6 data (big endian). If it's an IPv4, map it to IPv6.
|
|
|
|
/// Saves result into the first 16 bytes of `res`.
|
|
|
|
void IPv6ToRawBinary(const Poco::Net::IPAddress & address, char * res);
|
|
|
|
|
2019-06-15 14:20:32 +00:00
|
|
|
/// Convert IP address to 16-byte array with IPv6 data (big endian). If it's an IPv4, map it to IPv6.
|
|
|
|
std::array<char, 16> IPv6ToBinary(const Poco::Net::IPAddress & address);
|
|
|
|
|
2021-03-19 07:24:38 +00:00
|
|
|
/// Returns a reference to 16-byte array containing mask with first `prefix_len` bits set to `1` and `128 - prefix_len` to `0`.
|
|
|
|
/// The reference is valid during all program execution time.
|
2020-11-29 17:54:46 +00:00
|
|
|
/// Values of prefix_len greater than 128 interpreted as 128 exactly.
|
2021-03-19 07:24:38 +00:00
|
|
|
const std::array<uint8_t, 16> & getCIDRMaskIPv6(UInt8 prefix_len);
|
|
|
|
|
|
|
|
/// This is identical to getCIDRMaskIPv6 except it's for IPv4 addresses.
|
|
|
|
const std::array<uint8_t, 4> & getCIDRMaskIPv4(UInt8 prefix_len);
|
2020-11-29 17:54:46 +00:00
|
|
|
|
2019-06-15 14:20:32 +00:00
|
|
|
}
|