Skip to content
Snippets Groups Projects

First unit tests

Merged Leon Dietrich requested to merge first_unit_tests into master
Compare and Show latest version
7 files
+ 199
90
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 25
2
@@ -310,8 +310,8 @@ static constexpr void inet6_array_to_saddr(std::array<uint16_t, 8> const &ip6_co
for (size_t i = 0; i < ip6_comps.size(); i++) {
uint16_t hexlet = ip6_comps[i];
in6.s6_addr[i * 2] = hexlet >> 8;
in6.s6_addr[i * 2 + 1] = hexlet & 0xff;
in6.s6_addr[i * 2] = static_cast<uint8_t>(hexlet >> 8);
in6.s6_addr[i * 2 + 1] = static_cast<uint8_t>(hexlet & 0xff);
}
}
@@ -479,8 +479,29 @@ static constexpr bool is_valid_ip6addr(const char (&str)[N])
return details::inet6_aton(str, in6) != -1;
}
static bool is_valid_ip4addr(const std::string& str)
{
struct in_addr in = {};
return ::inet_pton(AF_INET, str.c_str(), &in) != -1;
}
static bool is_valid_ip6addr(const std::string& str)
{
struct in6_addr in = {};
return ::inet_pton(AF_INET6, str.c_str(), &in) != -1;
}
}
// Work around use of non-standard feature (not part of ISO-C++)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wgnu-string-literal-operator-template"
#endif
template <typename CharT, CharT... Cs>
static constexpr auto operator"" _ipaddr()
{
@@ -513,6 +534,8 @@ static constexpr auto operator"" _ip6()
return rmrf::net::inet_pton<AF_INET6>(str);
}
#pragma GCC diagnostic pop
static constexpr uint16_t operator "" _ipport(unsigned long long port)
{
if (port > 65535) {
Loading