12#ifndef OPENVPN_ADDR_ADDRPAIR_H
13#define OPENVPN_ADDR_ADDRPAIR_H
18#include <system_error>
50 explicit StringPair(
const std::string &s1,
const std::string &s2)
62 throw addr_pair_string_error();
68 throw addr_pair_string_error();
75 throw addr_pair_string_error();
108 const auto pair = Split::by_char<StringPair, NullLex, Split::NullLimit>(s1,
'/');
115 catch (
const std::exception &e)
127 const auto pair = Split::by_char<StringPair, NullLex, Split::NullLimit>(s,
'/');
130 catch (
const std::exception &e)
143 catch (
const std::exception &e)
150 std::string
to_string(
const bool netmask_form =
false)
const
170 static void error(
const std::exception &e,
const std::string &s,
const char *title)
174 OPENVPN_THROW(addr_pair_mask_parse_error,
"AddrMaskPair parse error '" << title <<
"': " << s <<
" : " << e.what());
185 unsigned int val = 0;
186 const auto [ptr, ec] = std::from_chars(s.data(), s.data() + s.size(), val);
192 if (ec != std::errc{} || ptr != s.data() + s.size() || val >
Addr::V6_SIZE)
194 throw number_parse_exception(
"prefix length");
202 if (pair.
size() == 1 || pair.
size() == 2)
205 if (pair.
size() == 2 && !pair[1].empty())
219 throw addr_pair_mask_parse_error(
"only one or two address terms allowed");
std::string & operator[](const size_t i)
void push_back(const std::string &s)
OPENVPN_SIMPLE_EXCEPTION(addr_pair_string_error)
std::string render() const
StringPair(const std::string &s1)
const std::string & operator[](const size_t i) const
StringPair(const std::string &s1, const std::string &s2)
static Addr from_string(const std::string &ipstr, const TITLE &title, const Version required_version)
void verify_version_consistency(const Addr &other) const
std::string to_string() const
static Addr netmask_from_prefix_len(Version v, const unsigned int prefix_len)
unsigned int prefix_len() const
static Addr from_zero_complement(const Version v)
#define OPENVPN_THROW(exc, stuff)
bool is_number(std::string_view str)
#define OPENVPN_OSTREAM(TYPE, METH)
static AddrMaskPair from_string(const StringPair &pair, const char *title=nullptr)
static void error(const std::exception &e, const std::string &s, const char *title)
bool is_canonical() const
std::string to_string(const bool netmask_form=false) const
OPENVPN_EXCEPTION(addr_pair_mask_parse_error)
static AddrMaskPair from_string(const std::string &s1, const std::string &s2, const char *title=nullptr)
static AddrMaskPair from_string_impl(const StringPair &pair, const char *title=nullptr)
static AddrMaskPair from_string(const std::string &s, const char *title=nullptr)
Addr::Version version() const
static unsigned int parse_prefix_len_throw(std::string_view s)
Parses an IP prefix length from a string view.