diff --git a/parser.c b/parser.c index fc7f4d89..2fe9df60 100644 --- a/parser.c +++ b/parser.c @@ -13,7 +13,7 @@ char *resolveHostname(const char *addr); void extracttimestamp(const char *readbuffer, int *querytimestamp, int *overTimetimestamp); -int getforwardID(const char * str); +int getforwardID(const char * str, bool count); int findDomain(const char *domain); int findClient(const char *client); int detectStatus(const char *domain); @@ -402,7 +402,7 @@ void process_pihole_log(int file) status = 2; // Get ID of forward destination, create new forward destination record // if not found in current data structure - forwardID = getforwardID(readbuffer2); + forwardID = getforwardID(readbuffer2, false); if(forwardID == -2) continue; break; @@ -614,7 +614,7 @@ void process_pihole_log(int file) // Get ID of forward destination, create new forward destination record // if not found in current data structure - int forwardID = getforwardID(readbuffer); + int forwardID = getforwardID(readbuffer, true); if(forwardID == -2) continue; @@ -853,7 +853,7 @@ void extracttimestamp(const char *readbuffer, int *querytimestamp, int *overTime *overTimetimestamp = *querytimestamp-(*querytimestamp%600)+300; } -int getforwardID(const char * str) +int getforwardID(const char * str, bool count) { // Get forward destination // forwardstart = pointer to | in "forwarded domain.name| to www.xxx.yyy.zzz\n" @@ -898,7 +898,8 @@ int getforwardID(const char * str) if(strcmp(forwarded[i].ip, forward) == 0) { forwardID = i; - forwarded[forwardID].count++; + if(count) + forwarded[forwardID].count++; processed = true; break; } @@ -918,8 +919,11 @@ int getforwardID(const char * str) validate_access("forwarded", forwardID, false, __LINE__, __FUNCTION__, __FILE__); // Set magic byte forwarded[forwardID].magic = MAGICBYTE; - // Set its counter to 1 - forwarded[forwardID].count = 1; + // Initialize its counter + if(count) + forwarded[forwardID].count = 1; + else + forwarded[forwardID].count = 0; // Save IP forwarded[forwardID].ip = strdup(forward); memory.forwardedips += (forwardlen + 1) * sizeof(char);