Changeset View
Changeset View
Standalone View
Standalone View
plugins/process/network/helper/ConnectionMapping.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of KSysGuard. | ||||
3 | * Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License as | ||||
7 | * published by the Free Software Foundation; either version 2 of | ||||
8 | * the License or (at your option) version 3 or any later version | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | * defined in Section 14 of version 3 of the license. | ||||
12 | * | ||||
13 | * This program is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | * GNU General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU General Public License | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | */ | ||||
21 | | ||||
22 | #ifndef CONNECTIONMAPPING_H | ||||
23 | #define CONNECTIONMAPPING_H | ||||
24 | | ||||
25 | #include <unordered_map> | ||||
26 | #include <unordered_set> | ||||
27 | #include <regex> | ||||
28 | | ||||
29 | // #include <QRegularExpression> | ||||
30 | | ||||
31 | #include "Packet.h" | ||||
32 | | ||||
33 | /** | ||||
34 | * @todo write docs | ||||
35 | */ | ||||
36 | class ConnectionMapping | ||||
37 | { | ||||
38 | public: | ||||
39 | struct PacketResult { | ||||
40 | int pid = 0; | ||||
41 | Packet::Direction direction; | ||||
42 | }; | ||||
43 | | ||||
44 | ConnectionMapping(); | ||||
45 | | ||||
46 | void parseProc(); | ||||
47 | | ||||
48 | PacketResult pidForPacket(const Packet &packet); | ||||
49 | | ||||
50 | private: | ||||
51 | bool parseSockets(); | ||||
52 | void parsePid(); | ||||
53 | void parseSocketFile(const char* fileName); | ||||
54 | | ||||
55 | std::unordered_map<Packet::Address, int> m_localToINode; | ||||
56 | std::unordered_map<int, int> m_inodeToPid; | ||||
57 | std::unordered_set<int> m_inodes; | ||||
58 | std::unordered_set<int> m_pids; | ||||
59 | | ||||
60 | // QRegularExpression m_socketFileMatch; | ||||
61 | std::regex m_socketFileMatch; | ||||
62 | }; | ||||
63 | | ||||
64 | #endif // CONNECTIONMAPPING_H |