/src/ntopng/include/UsedPorts.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2013-25 - ntop.org |
4 | | * |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #ifndef _USED_PORTS_H_ |
23 | | #define _USED_PORTS_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | class UsedPorts { |
28 | | private: |
29 | | Host* h; |
30 | | /* Used for both TCP and UDP */ |
31 | | std::unordered_map<u_int16_t /* port */, ndpi_protocol> udp_server_ports, tcp_server_ports; |
32 | | std::unordered_map<u_int16_t /* port */, ndpi_protocol> udp_client_contacted_ports, tcp_client_contacted_ports; |
33 | | |
34 | | ServerPortsBitmap *bitmap_server_ports; |
35 | | |
36 | | void setLuaArray(lua_State *vm, NetworkInterface *iface, bool isTCP, |
37 | | std::unordered_map<u_int16_t, ndpi_protocol> *ports); |
38 | | char* getRedisKey(char *redis_key, size_t key_len); |
39 | | void restore(); |
40 | | |
41 | | public: |
42 | | UsedPorts(Host* h); |
43 | | UsedPorts(); |
44 | | ~UsedPorts(); |
45 | | |
46 | | void reset(); |
47 | | |
48 | | void lua(lua_State *vm, NetworkInterface *iface); |
49 | | |
50 | 0 | inline std::unordered_map<u_int16_t, ndpi_protocol>* getUDPServerPorts() { return(&udp_server_ports); }; |
51 | 0 | inline std::unordered_map<u_int16_t, ndpi_protocol>* getTCPServerPorts() { return(&tcp_server_ports); }; |
52 | 0 | inline std::unordered_map<u_int16_t, ndpi_protocol>* getUDPClientContactedPorts() { return(&udp_client_contacted_ports); }; |
53 | 0 | inline std::unordered_map<u_int16_t, ndpi_protocol>* getTCPClientContactedPorts() { return(&tcp_client_contacted_ports); }; |
54 | | |
55 | | bool setServerPort(bool isTCP, u_int16_t port, ndpi_protocol *proto); |
56 | | void setContactedPort(bool isTCP, u_int16_t port, ndpi_protocol *proto); |
57 | 0 | void setLuaArrayUDPServerPorts(lua_State *vm, NetworkInterface *iface) {setLuaArray(vm, iface, false, &udp_server_ports);}; |
58 | 0 | void setLuaArrayTCPServerPorts(lua_State *vm, NetworkInterface *iface) {setLuaArray(vm, iface, true, &tcp_server_ports);}; |
59 | | |
60 | 0 | std::unordered_map<u_int16_t, ndpi_protocol> *getServerPorts(bool isTCP) { |
61 | 0 | return (isTCP ? &tcp_server_ports : &udp_server_ports); |
62 | 0 | } |
63 | | }; |
64 | | |
65 | | #endif /* _USED_PORTS_H_ */ |