drsuapi_SupportedExtensionsExt
[wireshark-sm.git] / epan / maxmind_db.h
blob79a9d7772614fb2810e35dd95f21e4bc1c811955
1 /** @file
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"
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
24 typedef struct _mmdb_lookup_t {
25 bool found;
26 const char *country;
27 const char *country_iso;
28 const char *city;
29 uint32_t as_number;
30 const char *as_org;
31 double latitude;
32 double longitude;
33 uint16_t accuracy; /** Accuracy radius in kilometers. */
34 } mmdb_lookup_t;
36 /**
37 * Init / reset function called from prefs_reset
39 WS_DLL_LOCAL void maxmind_db_pref_init(module_t *nameres);
41 /**
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);
48 /**
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);
57 /**
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);
66 /**
67 * Get all configured paths
69 * @return String with all paths separated by a path separator. The string
70 * must be freed.
72 WS_DLL_PUBLIC char *maxmind_db_get_paths(void);
74 /**
75 * Process outstanding requests.
77 * @return True if any new addresses were resolved.
79 WS_DLL_LOCAL bool maxmind_db_lookup_process(void);
81 /**
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;
90 /**
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);
102 #ifdef __cplusplus
104 #endif /* __cplusplus */
106 #endif /* __MAXMIND_DB_H__ */
109 * Editor modelines
111 * Local Variables:
112 * c-basic-offset: 4
113 * tab-width: 8
114 * indent-tabs-mode: nil
115 * End:
117 * ex: set shiftwidth=4 tabstop=8 expandtab:
118 * :indentSize=4:tabSize=8:noTabs=true: