From 5a83c3cd4d5f4442b5ee57e96fcd276b3d178c65 Mon Sep 17 00:00:00 2001 From: k4be Date: Thu, 26 Aug 2021 18:57:48 +0200 Subject: [PATCH] geoip_classic: use more efficient calls --- src/modules/geoip_classic.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modules/geoip_classic.c b/src/modules/geoip_classic.c index 5a71668c3..743b2e93b 100644 --- a/src/modules/geoip_classic.c +++ b/src/modules/geoip_classic.c @@ -240,6 +240,9 @@ GeoIPResult *geoip_lookup_classic(char *ip) { static char buf[256]; const char *country_code, *country_name; + GeoIPLookup gl; + GeoIP *gi; + int geoid; GeoIPResult *r; if (!ip) @@ -249,18 +252,24 @@ GeoIPResult *geoip_lookup_classic(char *ip) { if (!gi6) return NULL; - country_code = GeoIP_country_code_by_name_v6(gi6, ip); - country_name = GeoIP_country_name_by_name_v6(gi6, ip); + geoid = GeoIP_id_by_addr_v6_gl(gi6, ip, &gl); + gi = gi6; } else { if (!gi4 || !strcmp(ip, "255.255.255.255")) return NULL; - country_code = GeoIP_country_code_by_name(gi4, ip); - country_name = GeoIP_country_name_by_name(gi4, ip); + geoid = GeoIP_id_by_addr_gl(gi4, ip, &gl); + gi = gi4; } + if (geoid == 0) + return NULL; + + country_code = GeoIP_code_by_id(geoid); + country_name = GeoIP_country_name_by_id(gi, geoid); + if (!country_code || !country_name) - return NULL; + return NULL; r = safe_alloc(sizeof(GeoIPResult)); safe_strdup(r->country_code, country_code);