Skip to content

Commit

Permalink
Fixed LocalHostStats initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Jun 21, 2024
1 parent 611c7a7 commit 542f910
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
3 changes: 2 additions & 1 deletion include/LocalHostStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class LocalHostStats : public HostStats {
#if defined(NTOPNG_PRO)
void resetTrafficStats();
#endif

void init();

public:
LocalHostStats(Host *_host);
LocalHostStats(LocalHostStats &s);
Expand Down
48 changes: 19 additions & 29 deletions src/LocalHostStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,9 @@ LocalHostStats::LocalHostStats(Host *_host) : HostStats(_host) {
dns = new (std::nothrow) DnsStats();
http = new (std::nothrow) HTTPstats(_host);
icmp = new (std::nothrow) ICMPstats();
peers = new (std::nothrow)
PeerStats(MAX_DYNAMIC_STATS_VALUES /* 10 as default */);

nextPeriodicUpdate = 0;
num_contacts_as_cli = num_contacts_as_srv = 0;

num_contacted_hosts_as_client.init(8); /* 128 bytes */
num_host_contacts_as_server.init(8); /* 128 bytes */
num_contacted_services_as_client.init(8); /* 128 bytes */
num_contacted_hosts.init(4); /* 16 bytes */
num_contacted_countries.init(4); /* 16 bytes */
contacts_as_cli.init(4); /* 16 bytes */
contacts_as_srv.init(4); /* 16 bytes */
peers = new (std::nothrow) PeerStats(MAX_DYNAMIC_STATS_VALUES /* 10 as default */);

num_dns_servers.init(5);
num_smtp_servers.init(5);
num_ntp_servers.init(5);
num_imap_servers.init(5);
num_pop_servers.init(5);
num_contacted_domain_names.init(4);
init();
}

/* *************************************** */
Expand All @@ -62,6 +45,23 @@ LocalHostStats::LocalHostStats(LocalHostStats &s) : HostStats(s) {
dns = s.getDNSstats() ? new (std::nothrow) DnsStats(*s.getDNSstats()) : NULL;
http = NULL;
icmp = NULL;

init();
}

/* *************************************** */

LocalHostStats::~LocalHostStats() {
if (top_sites) delete top_sites;
if (dns) delete dns;
if (http) delete http;
if (icmp) delete icmp;
if (peers) delete (peers);
}

/* *************************************** */

void LocalHostStats::init() {
nextPeriodicUpdate = 0;
num_contacts_as_cli = num_contacts_as_srv = num_reset_flow = 0;

Expand All @@ -83,16 +83,6 @@ LocalHostStats::LocalHostStats(LocalHostStats &s) : HostStats(s) {

/* *************************************** */

LocalHostStats::~LocalHostStats() {
if (top_sites) delete top_sites;
if (dns) delete dns;
if (http) delete http;
if (icmp) delete icmp;
if (peers) delete (peers);
}

/* *************************************** */

void LocalHostStats::incrVisitedWebSite(char *hostname) {
u_int ip4_0 = 0, ip4_1 = 0, ip4_2 = 0, ip4_3 = 0;
char *firstdot = NULL, *nextdot = NULL;
Expand Down

0 comments on commit 542f910

Please sign in to comment.