logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

commit 9c73cee6b4ca71eb7e90d39200be5f9b1a87a357
parent a0367958c432efe3908e014fea710e6beac5c3c3
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date:   Thu, 18 Jun 2015 23:57:03 +0200

Initial GeoIP support (IPv4 only at the moment)

Diffstat:
MCMakeLists.txt | 5+++++
Msrc/logswan.c | 13+++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -11,6 +11,11 @@ cmake_minimum_required (VERSION 2.6) project (logswan C) +find_library(LIB_GEOIP NAMES GeoIP REQUIRED) +include_directories(/usr/local/include) + add_definitions(-Wall -Wextra -Werror -std=c99 -pedantic) add_executable(logswan src/logswan.c) + +target_link_libraries(logswan ${LIB_GEOIP}) diff --git a/src/logswan.c b/src/logswan.c @@ -22,9 +22,13 @@ #include <string.h> #include <time.h> +#include <GeoIP.h> + #define VERSION "Logswan" #define LINE_MAX_LENGTH 4096 +GeoIP *geoip; + clock_t begin, end; double runtime; char timeStamp[20]; @@ -37,6 +41,7 @@ uint64_t bandwidth = 0; uint64_t hits = 0; uint64_t hitsIPv4 = 0; uint64_t hitsIPv6 = 0; +uint64_t countries[255]; struct sockaddr_in ipv4; struct sockaddr_in6 ipv6; @@ -70,6 +75,9 @@ int main (int argc, char *argv[]) { /* Starting timer */ begin = clock(); + /* Initializing GeoIP */ + geoip = GeoIP_open("GeoIP.dat", GEOIP_MEMORY_CACHE); + /* Get log file size */ stat(argv[1], &logFileSize); @@ -93,6 +101,11 @@ int main (int argc, char *argv[]) { } if (isIPv4 || isIPv6) { + /* Increment countries array */ + if (geoip && isIPv4) { + countries[GeoIP_id_by_addr(geoip, token)]++; + } + /* User-identifier */ token = strtok(NULL, " ");