-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNSStore.cpp
80 lines (71 loc) · 1.92 KB
/
DNSStore.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by 92798 on 2021/7/5.
//
#include <stdio.h>
#include <iostream>
#include "DNSStore.h"
#include <fstream>
#include <string>
#include <vector>
#include "functions.h"
int DNSStoreNum;
int DNSStoreNum6;
std::string DNSStore::getStoredIpByDomain(const std::string& domain) {
if(store_map.count(domain) != 1) {
return "";
}
return store_map[domain];
}
void DNSStore::initLocalTable(const std::string Path) {
functions function;
int i=0;
std::ifstream myfile;
std::cout << "Load from:"<<Path << std::endl;
myfile.open(Path, std::ios::in);
std::string Temp[TABLE_SIZE];
std::string temp;
if (!myfile.is_open()) {
printf("Open file failed, input a valid file path");
exit(-1);
}
while (getline(myfile,temp)) {
if (temp=="") {
break;
}
Temp[i]=temp;
i++;
DNSStoreNum++;
if ((DNSStoreNum+DNSStoreNum6)>TABLE_SIZE) {
printf("The DNS Store is full!");
break;
}
}
for (int j=0;j<(DNSStoreNum+DNSStoreNum6);j++) {
std::vector<std::string> res;
std::string result;
std::stringstream input(Temp[j]);
while (input >> result)
res.push_back(result);
if (function.Get_Type_Name(function.Check_IP(res[0]))=="IPV4") {
store_map[res[1]] = res[0];
}
else {
store_map6[res[1]] = res[0];
--DNSStoreNum;
++DNSStoreNum6;
}
}
// for (auto &iter : store_map) {
// std::cout << iter.first << " " << iter.second << std::endl;
// }
// for (auto &iter : store_map6) {
// std::cout << iter.first << " " << iter.second << std::endl;
// }
printf("Load records success.\n");
}
std::string DNSStore::getStoredIp6ByDomain(const std::string& domain) {
if(store_map6.count(domain)!=1) {
return "";
}
return store_map6[domain];
}