-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclasses.cc
85 lines (69 loc) · 1.42 KB
/
classes.cc
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
#include <string>
#include <time.h>
#include <iostream>
#include <deque>
#include <memory>
class Event
{
public:
std::string getType();
struct timeval getTime();
virtual std::string getDescription()=0;
protected:
std::string m_type;
struct timeval m_time;
};
std::string Event::getType()
{
return m_type;
}
class PortScanEvent : public Event
{
public:
PortScanEvent(std::string fromIP) : m_fromIP(fromIP)
{
m_type = "Portscan";
}
virtual std::string getDescription() override
{
return "Port scan from "+m_fromIP;
}
private:
std::string m_fromIP;
};
class ICMPEvent : public Event
{
public:
ICMPEvent()
{
m_type = "ICMP";
}
virtual std::string getDescription() override
{
return "ICMP type "+std::to_string(m_icmptype);
}
private:
int m_icmptype;
};
using namespace std;
int main()
{
PortScanEvent pse("1.2.3.4");
cout << pse.getType() << endl;
ICMPEvent ice;
cout << ice.getType() << endl;
Event* e = &ice;
cout << e->getDescription() <<endl;
e = &pse;
cout << e->getDescription() <<endl;
auto ptr = dynamic_cast<PortScanEvent*>(e);
if(ptr) {
cout<<"This is a PortScanEvent"<<endl;
}
std::deque<std::unique_ptr<Event>> eventQueue;
eventQueue.push_back(std::make_unique<PortScanEvent>("1.2.3.4"));
eventQueue.push_back(std::make_unique<ICMPEvent>());
for(const auto& e : eventQueue) {
cout << e->getDescription() << endl;
}
}