diff options
-rw-r--r-- | configure.seed | 4 | ||||
-rw-r--r-- | src/include/ndpi_api.h.in | 7 | ||||
-rw-r--r-- | src/lib/ndpi_geoip.c | 57 |
3 files changed, 53 insertions, 15 deletions
diff --git a/configure.seed b/configure.seed index 9af6b6987..ef84661a2 100644 --- a/configure.seed +++ b/configure.seed @@ -125,6 +125,10 @@ if test -d ../nDPI-custom; then : AC_MSG_RESULT([Compiling with custom nDPI protocols]) fi +if test -d ../ndpi-pro; then : + with_maxminddb=1 +fi + case "$host" in *-*-mingw32*|*-*-msys) CFLAGS="${CFLAGS} -DOS_WIN32" diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index d284807f9..9f7bb23d3 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -1550,8 +1550,11 @@ extern "C" { int ndpi_load_geoip(struct ndpi_detection_module_struct *ndpi_str, const char *ip_city_data, const char *ip_as_data); void ndpi_free_geoip(struct ndpi_detection_module_struct *ndpi_str); - int ndpi_get_geoip(struct ndpi_detection_module_struct *ndpi_str, char *ip, - u_int32_t *asn, char *country_code, u_int8_t country_code_len); + int ndpi_get_geoip_asn(struct ndpi_detection_module_struct *ndpi_str, + char *ip, u_int32_t *asn); +int ndpi_get_geoip_country_continent(struct ndpi_detection_module_struct *ndpi_str, char *ip, + char *country_code, u_int8_t country_code_len, + char *continent, u_int8_t continent_len); #ifdef __cplusplus } diff --git a/src/lib/ndpi_geoip.c b/src/lib/ndpi_geoip.c index 50b1d4b3e..23fb0b752 100644 --- a/src/lib/ndpi_geoip.c +++ b/src/lib/ndpi_geoip.c @@ -68,8 +68,7 @@ void ndpi_free_geoip(struct ndpi_detection_module_struct *ndpi_str) { /* ********************************************************************************* */ -int ndpi_get_geoip(struct ndpi_detection_module_struct *ndpi_str, char *ip, - u_int32_t *asn, char *country_code, u_int8_t country_code_len) { +int ndpi_get_geoip_asn(struct ndpi_detection_module_struct *ndpi_str, char *ip, u_int32_t *asn) { #ifdef HAVE_MAXMINDDB int gai_error, mmdb_error, status; MMDB_lookup_result_s result; @@ -91,9 +90,26 @@ int ndpi_get_geoip(struct ndpi_detection_module_struct *ndpi_str, char *ip, *asn = 0; } } + + return(0); } +#endif + + return(-2); +} + +/* ********************************************************************************* */ - if(ndpi_str->mmdb_city_loaded && (country_code_len > 0)) { +int ndpi_get_geoip_country_continent(struct ndpi_detection_module_struct *ndpi_str, char *ip, + char *country_code, u_int8_t country_code_len, + char *continent, u_int8_t continent_len) { +#ifdef HAVE_MAXMINDDB + int gai_error, mmdb_error; + MMDB_lookup_result_s result; + MMDB_entry_data_s entry_data; + + + if(ndpi_str->mmdb_city_loaded) { int status; result = MMDB_lookup_string(&ndpi_str->mmdb_city, ip, &gai_error, &mmdb_error); @@ -103,20 +119,35 @@ int ndpi_get_geoip(struct ndpi_detection_module_struct *ndpi_str, char *ip, || (!result.found_entry)) country_code[0] = '\0'; else { - status = MMDB_get_value(&result.entry, &entry_data, "country", "iso_code", NULL); - - if((status != MMDB_SUCCESS) || (!entry_data.has_data)) - country_code[0] = '\0'; - else { - int str_len = ndpi_min(entry_data.data_size, country_code_len); + if(country_code_len > 0) { + status = MMDB_get_value(&result.entry, &entry_data, "country", "iso_code", NULL); + + if((status != MMDB_SUCCESS) || (!entry_data.has_data)) + country_code[0] = '\0'; + else { + int str_len = ndpi_min(entry_data.data_size, country_code_len); + + memcpy(country_code, entry_data.utf8_string, str_len); + country_code[str_len] = '\0'; + } + } - memcpy(country_code, entry_data.utf8_string, str_len); - country_code[str_len] = '\0'; + if(continent_len > 0) { + status = MMDB_get_value(&result.entry, &entry_data, "continent", "names", "en", NULL); + + if((status != MMDB_SUCCESS) || (!entry_data.has_data)) + continent[0] = '\0'; + else { + int str_len = ndpi_min(entry_data.data_size, continent_len); + + memcpy(continent, entry_data.utf8_string, str_len); + continent[str_len] = '\0'; + } } } - } - return(0); + return(0); + } #endif return(-2); |