Coverage Report

Created: 2024-02-25 06:37

/src/ntopng/include/ICMPstats.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * (C) 2013-24 - 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 _ICMP_STATS_H_
23
#define _ICMP_STATS_H_
24
25
#include "ntop_includes.h"
26
27
typedef struct {
28
  u_int16_t pkt_sent, pkt_rcvd;
29
  char *last_host_sent_peer, *last_host_rcvd_peer;
30
} ICMPstats_t;
31
32
class ICMPstats {
33
 private:
34
  std::map<u_int16_t, ICMPstats_t> stats;
35
  Mutex m;
36
  MonitoredCounter<u_int32_t> num_destination_unreachable;
37
38
  void addToTable(const char *label, lua_State *vm, const ICMPstats_t *curr,
39
                  bool verbose);
40
6.07k
  inline u_int16_t get_typecode(u_int8_t icmp_type, u_int8_t icmp_code) {
41
6.07k
    return ((icmp_type << 8) + icmp_code);
42
6.07k
  }
43
  inline void to_typecode(int type_code, u_int8_t *icmp_type,
44
0
                          u_int8_t *icmp_code) {
45
0
    *icmp_type = (type_code >> 8) & 0xFF, *icmp_code = type_code & 0xFF;
46
0
  }
47
48
 public:
49
  ICMPstats();
50
  ~ICMPstats();
51
52
  void incStats(u_int32_t num_pkts, u_int8_t icmp_type, u_int8_t icmp_code,
53
                bool sent, Host *peer);
54
  void updateStats(const struct timeval *tv);
55
  void lua(bool isV4, lua_State *vm, bool verbose = true);
56
  bool hasAnomalies(time_t when);
57
  void luaAnomalies(lua_State *vm, time_t when);
58
  void sum(ICMPstats *e);
59
  void getTsStats(ts_icmp_stats *s);
60
};
61
62
#endif /* _ICMP_STATS_H_ */