dont use cppcodec
[ghsmtp.git] / IP4.hpp
blob4aa268fa18c63179d025958c30e9d592027a3dc9
1 #ifndef IP4_DOT_HPP
2 #define IP4_DOT_HPP
4 #include <string>
5 #include <string_view>
6 #include <vector>
8 #include <glog/logging.h>
10 namespace IP4 {
11 using namespace std::literals::string_view_literals;
13 auto is_private(std::string_view addr) -> bool;
14 auto is_address(std::string_view addr) -> bool;
15 auto is_address_literal(std::string_view addr) -> bool;
16 auto to_address_literal(std::string_view addr) -> std::string;
17 auto reverse(std::string_view addr) -> std::string;
18 auto fcrdns(std::string_view addr) -> std::vector<std::string>;
20 auto constexpr lit_pfx{"["sv};
21 auto constexpr lit_pfx_sz{std::size(lit_pfx)};
23 auto constexpr lit_sfx{"]"sv};
24 auto constexpr lit_sfx_sz{std::size(lit_sfx)};
26 auto constexpr lit_extra_sz{lit_pfx_sz + lit_sfx_sz};
28 auto constexpr loopback_literal{"[127.0.0.1]"sv};
30 constexpr auto as_address(std::string_view address_literal) -> std::string_view
32 CHECK(is_address_literal(address_literal));
33 return address_literal.substr(lit_pfx_sz,
34 address_literal.length() - lit_extra_sz);
37 } // namespace IP4
39 #endif // IP4_DOT_HPP