commit a56bb2e120629892fe835173f21acb55a80c7614
parent b58764d847c38d6a90f2bd095e23d4ae04edd429
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Mon, 14 Dec 2015 23:46:10 +0100
Small refactor to get country id in a variable
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -4,7 +4,7 @@
/* https://github.com/fcambus/logswan */
/* */
/* Created: 2015/05/31 */
-/* Last Updated: 2015/12/05 */
+/* Last Updated: 2015/12/14 */
/* */
/* Logswan is released under the BSD 3-Clause license. */
/* See LICENSE file for details. */
@@ -53,6 +53,7 @@ int isIPv4, isIPv6;
uint64_t bandwidth;
int statusCode;
int hour;
+int countryId;
struct stat logFileSize;
FILE *logFile;
@@ -128,13 +129,15 @@ int main (int argc, char *argv[]) {
if (isIPv4 || isIPv6) {
/* Increment countries array */
if (geoip && isIPv4) {
- results.countries[GeoIP_id_by_addr(geoip, parsedLine.remoteHost)]++;
+ countryId = GeoIP_id_by_addr(geoip, parsedLine.remoteHost);
}
if (geoipv6 && isIPv6) {
- results.countries[GeoIP_id_by_addr_v6(geoipv6, parsedLine.remoteHost)]++;
+ countryId = GeoIP_id_by_addr_v6(geoipv6, parsedLine.remoteHost);
}
+ results.countries[countryId]++;
+
/* Unique visitors */
if (isIPv4) {
hll_add(&uniqueIPv4, parsedLine.remoteHost, strlen(parsedLine.remoteHost));