-
Notifications
You must be signed in to change notification settings - Fork 3
/
IP.cpp
55 lines (46 loc) · 1.23 KB
/
IP.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "IP.hpp"
#include "IP4.hpp"
#include "IP6.hpp"
#include <glog/logging.h>
namespace IP {
bool is_private(std::string_view addr)
{
if (IP4::is_address(addr))
return IP4::is_private(addr);
else if (IP6::is_address(addr))
return IP6::is_private(addr);
return false;
}
bool is_address(std::string_view addr)
{
return IP4::is_address(addr) || IP6::is_address(addr);
}
bool is_address_literal(std::string_view addr)
{
return IP4::is_address_literal(addr) || IP6::is_address_literal(addr);
}
std::string to_address_literal(std::string_view addr)
{
if (IP4::is_address(addr))
return IP4::to_address_literal(addr);
if (IP6::is_address(addr))
return IP6::to_address_literal(addr);
LOG(FATAL) << "not a valid IP address " << addr;
}
std::string_view as_address(std::string_view addr)
{
if (IP4::is_address_literal(addr))
return IP4::as_address(addr);
if (IP6::is_address_literal(addr))
return IP6::as_address(addr);
LOG(FATAL) << "not a valid IP address literal " << addr;
}
std::string reverse(std::string_view addr)
{
if (IP4::is_address(addr))
return IP4::reverse(addr);
if (IP6::is_address(addr))
return IP6::reverse(addr);
LOG(FATAL) << "not a valid IP address " << addr;
}
} // namespace IP