/
Service.cpp
48 lines (39 loc) · 1.2 KB
/
Service.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
#include "Service.h"
#include <unordered_map>
using namespace std;
Service::Service(const Service& service)
: address(service.address), port(service.port), protocol(service.protocol),
alive(service.alive), reason(service.reason), banner(service.banner),
cpe(service.cpe), date(service.date), host(service.host), data(service.data)
{
}
Service::Service(const string& address, unsigned short port, IPPROTO protocol)
: address(address), port(port), protocol(protocol),
alive(false), reason(AR_NotScanned), banner(""), cpe(), date(), host(nullptr), data(nullptr)
{
}
string Service::ReasonString(AliveReason reason)
{
static unordered_map<int, string> reasons = {
{ AR_ScanFailed, "ScanFailed" },
{ AR_NotScanned, "NotScanned" },
{ AR_InProgress, "InProgress" },
{ AR_InProgress_Extra, "InProgressExtra" },
{ AR_TimedOut, "TimedOut" },
{ AR_IcmpUnreachable, "IcmpUnreachable" },
{ AR_ReplyReceived, "ReplyReceived" }
};
auto iter = reasons.find(reason);
return iter != reasons.end() ? iter->second : "Unkown";
}
Service::~Service()
{
}
void freeServices(Services& services)
{
for (auto& service : services)
{
delete service;
}
services.clear();
}