Skip to content

Commit

Permalink
Fixed OS implementation for local hosts
Browse files Browse the repository at this point in the history
Tiny change on the pcap interface due to Windows issues
  • Loading branch information
lucaderi committed Dec 20, 2018
1 parent 0fb24ef commit e3e82c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 2 additions & 3 deletions include/LocalHost.h
Expand Up @@ -32,8 +32,7 @@ class LocalHost : public Host {
HTTPstats *http;
ICMPstats *icmp;
FrequentStringItems *top_sites;
char *old_sites;
char os[16];
char *old_sites, *os;
time_t nextSitesUpdate;
bool systemHost;
bool dhcpUpdated;
Expand All @@ -59,7 +58,7 @@ class LocalHost : public Host {
virtual NetworkStats* getNetworkStats(int16_t networkId){ return(iface->getNetworkStats(networkId)); };
virtual u_int32_t getActiveHTTPHosts() { return(http ? http->get_num_virtual_hosts() : 0); };
virtual HTTPstats* getHTTPstats() { return(http); };
virtual char* get_os() { return(os); };
virtual char* get_os() { return(os ? os : (char*)""); };

virtual bool dropAllTraffic() { return(drop_all_host_traffic); };

Expand Down
13 changes: 7 additions & 6 deletions src/LocalHost.cpp
Expand Up @@ -47,8 +47,8 @@ LocalHost::~LocalHost() {
if(dns) delete dns;
if(http) delete http;
if(icmp) delete icmp;

if(ts_ring) delete ts_ring;
if(os) free(os);
if(ts_ring) delete ts_ring;
}

/* *************************************** */
Expand All @@ -64,8 +64,7 @@ void LocalHost::initialize() {
dhcpUpdated = false;
icmp = NULL;
drop_all_host_traffic = false;

os[0] = '\0';
os = NULL;

ip.isLocalHost(&local_network_id);
networkStats = getNetworkStats(local_network_id);
Expand Down Expand Up @@ -517,8 +516,10 @@ void LocalHost::setOS(char *_os) {
|| (mac->getDeviceType() == device_networking)
) return;

if(os[0] == '\0')
snprintf(os, sizeof(os), "%s", _os);
if(os == NULL)
os = strdup(_os);

if (!os) return;

if(strcasestr(os, "iPhone")
|| strcasestr(os, "Android")
Expand Down
2 changes: 1 addition & 1 deletion src/PcapInterface.cpp
Expand Up @@ -285,7 +285,7 @@ void PcapInterface::shutdown() {

u_int32_t PcapInterface::getNumDroppedPackets() {
#ifndef WIN32
/* For some reson it crashes under Windows: maybe a lock is needed ?*/
/* It seems this leads to crashes on Windows */
struct pcap_stat pcapStat;

if(pcap_handle && (pcap_stats(pcap_handle, &pcapStat) >= 0)) {
Expand Down

0 comments on commit e3e82c6

Please sign in to comment.