commit e0ea760286be71f3eedd72cd82873b06c8b99956
parent 9bf13270f7a8964d47b93490a375f7ce3cd16916
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Sun, 12 Jul 2015 22:16:11 +0200
Perform GeoIP lookups for IPv6 addresses
Diffstat:
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
@@ -43,7 +43,7 @@ Currently implemented features :
- Counting number of hits (IPv4 and IPv6 hits)
- Counting bandwidth used
- Counting log file size
-- GeoIP lookups (IPv4 only for now)
+- GeoIP lookups (for both IPv4 and IPv6)
- HTTP status codes distribution
- Hourly hits distribution
- Counting hits per protocol (HTTP/1.0 or HTTP/1.1)
diff --git a/src/logswan.c b/src/logswan.c
@@ -34,7 +34,7 @@
#define VERSION "Logswan"
#define LINE_MAX_LENGTH 4096
-GeoIP *geoip;
+GeoIP *geoip, *geoipv6;
clock_t begin, end;
@@ -100,7 +100,8 @@ int main (int argc, char *argv[]) {
/* Initializing GeoIP */
geoip = GeoIP_open("GeoIP.dat", GEOIP_MEMORY_CACHE);
-
+ geoipv6 = GeoIP_open("GeoIPv6.dat", GEOIP_MEMORY_CACHE);
+
/* Get log file size */
stat(argv[1], &logFileSize);
results.fileSize = (uint64_t)logFileSize.st_size;
@@ -140,6 +141,10 @@ int main (int argc, char *argv[]) {
results.countries[GeoIP_id_by_addr(geoip, parsedLine.remoteHost)]++;
}
+ if (geoipv6 && isIPv6) {
+ results.countries[GeoIP_id_by_addr_v6(geoipv6, parsedLine.remoteHost)]++;
+ }
+
/* Hourly distribution */
parseDate(&parsedDate, parsedLine.date);