2 * Maxmind database support
4 * Copyright 2018, Gerald Combs <gerald@wireshark.org>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef __MAXMIND_DB_H__
14 #define __MAXMIND_DB_H__
16 #include <epan/prefs.h>
17 #include <wsutil/inet_addr.h>
18 #include "ws_symbol_export.h"
22 #endif /* __cplusplus */
24 typedef struct _mmdb_lookup_t
{
27 const char *country_iso
;
33 uint16_t accuracy
; /** Accuracy radius in kilometers. */
37 * Init / reset function called from prefs_reset
39 WS_DLL_LOCAL
void maxmind_db_pref_init(module_t
*nameres
);
42 * Cleanup function called from prefs_cleanup
44 WS_DLL_LOCAL
void maxmind_db_pref_cleanup(void);
46 WS_DLL_LOCAL
void maxmind_db_pref_apply(void);
49 * Look up an IPv4 address in a database
51 * @param addr IPv4 address to look up
53 * @return The database entry if found, else NULL.
55 WS_DLL_PUBLIC WS_RETNONNULL
const mmdb_lookup_t
*maxmind_db_lookup_ipv4(const ws_in4_addr
*addr
);
58 * Look up an IPv6 address in a database
60 * @param addr IPv6 address to look up
62 * @return The database entry if found, else NULL.
64 WS_DLL_PUBLIC WS_RETNONNULL
const mmdb_lookup_t
*maxmind_db_lookup_ipv6(const ws_in6_addr
*addr
);
67 * Get all configured paths
69 * @return String with all paths separated by a path separator. The string
72 WS_DLL_PUBLIC
char *maxmind_db_get_paths(void);
75 * Process outstanding requests.
77 * @return True if any new addresses were resolved.
79 WS_DLL_LOCAL
bool maxmind_db_lookup_process(void);
82 * Checks whether the lookup result was successful and has valid coordinates.
84 static inline bool maxmind_db_has_coords(const mmdb_lookup_t
*result
)
86 return result
&& result
->found
&&
87 result
->longitude
!= DBL_MAX
&& result
->latitude
!= DBL_MAX
;
91 * Select whether lookups should be performed synchronously.
92 * Default is asynchronous lookups.
94 * @param synchronous Whether maxmind lookups should be synchronous.
96 * XXX - if we ever have per-session host name etc. information, we
97 * should probably have the "resolve synchronously or asynchronously"
98 * flag be per-session, set with an epan API.
100 WS_DLL_PUBLIC
void maxmind_db_set_synchrony(bool synchronous
);
104 #endif /* __cplusplus */
106 #endif /* __MAXMIND_DB_H__ */
114 * indent-tabs-mode: nil
117 * ex: set shiftwidth=4 tabstop=8 expandtab:
118 * :indentSize=4:tabSize=8:noTabs=true: