An overview of my failed project
Lead in
In this project, we need to program a project to match the data_list with the rule_list and output the ans_list.
As a result, however, I failed finally.
What We Need To Learn
1.How to use file I/O (learnt,but cannot use it fluently and correctly)
2.How to use *file(as a file pointer)(I will learn this part and will fill in the blank of my project in the winter vacation)
3. Know about TCP/IP and need to deal with CIDR code(failed)
4.use visual stdio to program as a big project (succeed, to some extent)
Here is my thought(as a brief pseudo code)
#include<bits/stdc++.h>
int main () {
{
ifstream fin();//fin Rule//输入Rule文件
f()//对文件进行处理;
fin.close();;//关掉Rule文件
}
{
ifstream fin();//fin data i//输入Data文件
f()//对文件进行处理;
fin.close();;//关掉Rule文件
}
f//f(match)//对两个文件进行匹配
//变量如下
1.data_ip_source & rule_ip_source_low & rule_ip_source_high;
2.data_ip_destination & rule_ip_destination_low & rule_ip_destination_high;
3.data_port_source & rule_port_source_low & rule_port_source_high;
4.data_port_destination & rule_port_destination_low & rule_port_destination_high;
5.tcp_source & tcp_destination;
//{
data源ip == rule源ip;
data目的ip between rule目的ip范围;
data源port between rule源port范围;
data目的port between rule目的port范围;
data的tcp == rule_tcp or (rule_ctp == 0xFF);
fout << ();//将结果输出result;
ofstream fout();
}
Then I Write Down The Match_Function(as below)
bool match(&data,&rule)
{
if (data_ip_source < rule_ip_source_low ||
data_ip_source > rule_ip_source_high) {
return false;
}
if (data_ip_destination < rule_ip_destination_low ||
data_ip_destination > rule_ip_destination_high) {
return false;
}
if (data_port_source < rule_port_source_low
|| data_port_source > rule_port_source_high) {
return false;
}
return false;
if (data_port_destination < rule_port_destination_low
|| data_port_destination > rule_port_destination_high) {
return false;
}
return false;
if (tcp_source != tcp_destination && tcp_destination <= 255) {
return false;
}
return true;
}
So I write the code to deal with it as below.
void num_10_to_8(int num, char arr[9]) {
int i;
for (i = 1; i <= 8; i++) {
arr[i] = '0';
}
for (i = 1; i <= 8; i++) {
arr[i] = num % 2 + 48;
num >> 1;
}
}
Then match.(Have been shown before)
Finally,output our "res.txt"file.
My Harvest & Problems needed to be solved
Learnt to process file's I/O
Learnt to use Visual Studio
Learnt to program a project with several separated files
Need to Learn to process the rule_list & data_list. And need to finish the code.