-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip_filter.cpp
54 lines (43 loc) · 1.24 KB
/
ip_filter.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
#include <iostream>
#include <string>
#include <vector>
#include <regex>
#include "ip_filter.h"
std::vector<std::string> split(const std::string &str)
{
std::vector<std::string> r;
char d = '\t';
std::string::size_type start = 0;
std::string::size_type stop = str.find_first_of(d);
while(stop != std::string::npos)
{
r.push_back(str.substr(start, stop - start));
start = stop + 1;
stop = str.find_first_of(d, start);
}
r.push_back(str.substr(start));
return r;
}
std::vector<uint32_t> split_ip(const std::string &str)
{
std::vector<uint32_t> r;
std::string::size_type start = 0;
std::string::size_type stop = str.find_first_of('.');
uint32_t s2i;
while(stop != std::string::npos)
{
s2i = stoi(str.substr(start, stop - start));
r.push_back(s2i);
start = stop + 1;
stop = str.find_first_of('.', start);
}
s2i = stoi(str.substr(start));
r.push_back(s2i);
return r;
}
ipv4_validate::ipv4_validate(const std::string& in_str)
: ipv4_regex(in_str) {}
bool ipv4_validate::operator()(const std::string& is_valid)
{
return regex_match(is_valid, match, ipv4_regex);
}