-
Notifications
You must be signed in to change notification settings - Fork 3
/
IP4.hpp
39 lines (28 loc) · 1.06 KB
/
IP4.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef IP4_DOT_HPP
#define IP4_DOT_HPP
#include <string>
#include <string_view>
#include <vector>
#include <glog/logging.h>
namespace IP4 {
using namespace std::literals::string_view_literals;
auto is_private(std::string_view addr) -> bool;
auto is_address(std::string_view addr) -> bool;
auto is_address_literal(std::string_view addr) -> bool;
auto to_address_literal(std::string_view addr) -> std::string;
auto reverse(std::string_view addr) -> std::string;
auto fcrdns(std::string_view addr) -> std::vector<std::string>;
auto constexpr lit_pfx{"["sv};
auto constexpr lit_pfx_sz{std::size(lit_pfx)};
auto constexpr lit_sfx{"]"sv};
auto constexpr lit_sfx_sz{std::size(lit_sfx)};
auto constexpr lit_extra_sz{lit_pfx_sz + lit_sfx_sz};
auto constexpr loopback_literal{"[127.0.0.1]"sv};
constexpr auto as_address(std::string_view address_literal) -> std::string_view
{
// CHECK(is_address_literal(address_literal));
return address_literal.substr(lit_pfx_sz,
address_literal.length() - lit_extra_sz);
}
} // namespace IP4
#endif // IP4_DOT_HPP