diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/maxmind_db.c | 9 | ||||
-rw-r--r-- | epan/maxmind_db.h | 10 |
2 files changed, 18 insertions, 1 deletions
diff --git a/epan/maxmind_db.c b/epan/maxmind_db.c index 9acf8e047e..a0086b3569 100644 --- a/epan/maxmind_db.c +++ b/epan/maxmind_db.c @@ -119,6 +119,7 @@ static void mmdb_resolve_stop(void); #define RES_ASN_NUMBER "autonomous_system_number" #define RES_LOCATION_LATITUDE "location.latitude" #define RES_LOCATION_LONGITUDE "location.longitude" +#define RES_LOCATION_ACCURACY "location.accuracy_radius" #define RES_END "# End " // Interned strings and v6 addresses, similar to GLib's string chunks. @@ -145,7 +146,7 @@ static const void *chunkify_v6_addr(const ws_in6_addr *addr) { } static void init_lookup(mmdb_lookup_t *lookup) { - mmdb_lookup_t empty_lookup = { FALSE, NULL, NULL, NULL, 0, NULL, DBL_MAX, DBL_MAX }; + mmdb_lookup_t empty_lookup = { FALSE, NULL, NULL, NULL, 0, NULL, DBL_MAX, DBL_MAX, 0 }; *lookup = empty_lookup; } @@ -311,6 +312,12 @@ read_mmdbr_stdout_worker(gpointer data _U_) { } else if (val_start && g_str_has_prefix(line, RES_LOCATION_LONGITUDE)) { response->mmdb_val.found = TRUE; response->mmdb_val.longitude = g_ascii_strtod(val_start, NULL); + } else if (val_start && g_str_has_prefix(line, RES_LOCATION_ACCURACY)) { + if (ws_strtou16(val_start, NULL, &response->mmdb_val.accuracy)) { + response->mmdb_val.found = TRUE; + } else { + MMDB_DEBUG("Invalid accuracy radius: %s", val_start); + } } else if (g_str_has_prefix(line, RES_END)) { if (response->mmdb_val.found && cur_addr[0]) { if (country_iso->len) { diff --git a/epan/maxmind_db.h b/epan/maxmind_db.h index 251bf558e8..c7404a12a8 100644 --- a/epan/maxmind_db.h +++ b/epan/maxmind_db.h @@ -31,6 +31,7 @@ typedef struct _mmdb_lookup_t { const char *as_org; double latitude; double longitude; + guint16 accuracy; /** Accuracy radius in kilometers. */ } mmdb_lookup_t; /** @@ -75,6 +76,15 @@ WS_DLL_PUBLIC gchar *maxmind_db_get_paths(void); */ WS_DLL_LOCAL gboolean maxmind_db_lookup_process(void); +/** + * Checks whether the lookup result was successful and has valid coordinates. + */ +static inline gboolean maxmind_db_has_coords(const mmdb_lookup_t *result) +{ + return result && result->found && + result->longitude != DBL_MAX && result->latitude != DBL_MAX; +} + #ifdef __cplusplus } #endif /* __cplusplus */ |