commit 391dfd8b335f65a5226e5e05ce21647c0cc59aff
parent 31b1c7a6531a9c2ef0f4d0ecfd708bfe5a6d1e00
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 6 Dec 2016 15:23:03 +0100
Make GeoIP lookups optional and disabled by default (add a -g switch to enable)
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -20,6 +20,7 @@
#include <err.h>
#include <getopt.h>
#include <inttypes.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -45,11 +46,13 @@
void displayUsage() {
printf("USAGE : logswan [options] inputfile\n\n" \
"Options are :\n\n" \
+ " -g Enable GeoIP lookups\n" \
" -h Display usage\n" \
" -v Display version\n\n");
}
int main (int argc, char *argv[]) {
+ bool geoip = false;
GeoIP *geoipv4, *geoipv6;
clock_t begin, end;
@@ -87,8 +90,12 @@ int main (int argc, char *argv[]) {
hll_init(&uniqueIPv4, HLL_BITS);
hll_init(&uniqueIPv6, HLL_BITS);
- while ((getoptFlag = getopt(argc, argv, "hv")) != -1) {
+ while ((getoptFlag = getopt(argc, argv, "ghv")) != -1) {
switch(getoptFlag) {
+ case 'g':
+ geoip = true;
+ break;
+
case 'h':
displayUsage();
return EXIT_SUCCESS;
@@ -113,8 +120,10 @@ int main (int argc, char *argv[]) {
begin = clock();
/* Initializing GeoIP */
- geoipv4 = GeoIP_open(GEOIPDIR "GeoIP.dat", GEOIP_MEMORY_CACHE);
- geoipv6 = GeoIP_open(GEOIPDIR "GeoIPv6.dat", GEOIP_MEMORY_CACHE);
+ if (geoip) {
+ geoipv4 = GeoIP_open(GEOIPDIR "GeoIP.dat", GEOIP_MEMORY_CACHE);
+ geoipv6 = GeoIP_open(GEOIPDIR "GeoIPv6.dat", GEOIP_MEMORY_CACHE);
+ }
/* Get log file size */
stat(intputFile, &logFileSize);