commit 401d17e12362c89b291af91b651c166beeccc850
parent 33f9913cc055c24e81bde116aa9f423ea26cc93d
Author: Frederic Cambus <fred@statdns.com>
Date: Fri, 25 Oct 2019 17:54:14 +0200
Add a switch (-d) to allow specifying path to a GeoIP2 database file.
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -80,11 +80,13 @@ int8_t getoptFlag;
struct HLL uniqueIPv4, uniqueIPv6;
char *intputFile;
+char *db = NULL;
void
displayUsage() {
printf("USAGE: logswan [options] inputfile\n\n" \
"Options are:\n\n" \
+ " -d Specify path to a GeoIP database\n" \
" -g Enable GeoIP lookups\n" \
" -h Display usage\n" \
" -v Display version\n");
@@ -107,8 +109,12 @@ main(int argc, char *argv[]) {
hll_init(&uniqueIPv4, HLL_BITS);
hll_init(&uniqueIPv6, HLL_BITS);
- while ((getoptFlag = getopt(argc, argv, "ghv")) != -1) {
+ while ((getoptFlag = getopt(argc, argv, "d:ghv")) != -1) {
switch (getoptFlag) {
+ case 'd':
+ db = optarg;
+ break;
+
case 'g':
geoip = true;
break;
@@ -138,8 +144,10 @@ main(int argc, char *argv[]) {
/* Initializing GeoIP */
if (geoip) {
- if (MMDB_open(GEOIP2DIR GEOIP2DB,
- MMDB_MODE_MMAP, &geoip2) != MMDB_SUCCESS) {
+ if (!db)
+ db = GEOIP2DIR GEOIP2DB;
+
+ if (MMDB_open(db, MMDB_MODE_MMAP, &geoip2) != MMDB_SUCCESS) {
perror("Can't open database");
return EXIT_FAILURE;
}