-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
117 lines (106 loc) · 1.97 KB
/
main.cpp
File metadata and controls
117 lines (106 loc) · 1.97 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <cstdlib>
#include <fstream>
#include <string>
#include <iostream>
#include "Trie.h"
#include <cstring>
using namespace std;
int readEntry(char entry[25],int mask[6], ifstream& ifs, short* outport)
{
ifs.read(entry,24);
ifs.read((char*)(outport),sizeof( short));
short boo;
ifs.read((char*)(&boo),sizeof boo);//read the 0x0d0a
int mark=0;
if(((int)(*entry)<<16)+(short)(*(entry+4)))
{
mask[0]=1;
mark = 0;
}
if(((int)(*(entry+6))<<16)+(short)(*(entry+10)))
{
mask[1]=1;
mark = 1;
}
if((int)(*(entry+12)))
{
mask[2]=1;
mark = 2;
}
if((int)(*(entry+16)))
{
mask[3]=1;
mark = 3;
}
if((short)(*(entry+20)))
{
mask[4]=1;
mark =4;
}
if((short)(*(entry+22)))
{
mask[5]=1;
mark =5;
}
entry[24]='\0';
return mark;
}
int main(int argc, char **argv)
{
ifstream table("table.dat");
Trie* trie = new Trie();
// int count = 0;
int mask[6];
char entry[25];
int mark = 0;
short outport;
// while (!table.eof()&&count<10)
while(!table.eof())
{
//count++;
memset(mask,0,6);
mark =readEntry(entry,mask,table,&outport);
cout<<trie->insert(mask, mark, entry, outport);
//if(!trie->insert(mask,mark,entry,outport))
// cout<<"failed insertion"<<endl;
cin.get();
}
table.close();
ifstream packet("packet.dat");
ofstream output("output.txt");
char packetEntry[25];
int count=0;
while (!packet.eof())
{
packet.read((char*)(packetEntry),24);
short boo;
packet.read((char*)(&boo),sizeof boo);
packetEntry[24] = '\0';
char pattern[25]={0};
pattern[24]='\0';
output << trie->match(trie->getRoot(), pattern, packetEntry)<<endl;
count++;
}
cout<<count<<endl;
packet.close();
output.close();
// ifstream out("output.txt");
// ifstream port("outport.dat");
// while(!output.eof())
// {
// int a;
// int b;
// short boo;
// out>>a;
// port.read((char*)(&b),sizeof b);
// port.read((char*)(&boo),sizeof boo);
//
// if(a!=b)
// {
// cout<<"boo!"<<endl;
// }
// }
// output.close();
// port.close();
return 0;
}