/src/wireshark/epan/maxmind_db.h
Line | Count | Source |
1 | | /** @file |
2 | | * Maxmind database support |
3 | | * |
4 | | * Copyright 2018, Gerald Combs <gerald@wireshark.org> |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | #pragma once |
13 | | #include <epan/prefs.h> |
14 | | #include <wsutil/inet_addr.h> |
15 | | #include "ws_symbol_export.h" |
16 | | |
17 | | #ifdef __cplusplus |
18 | | extern "C" { |
19 | | #endif /* __cplusplus */ |
20 | | |
21 | | /** |
22 | | * @brief Holds the result of a MaxMind database (MMDB) geolocation and ASN lookup for a single IP address. |
23 | | */ |
24 | | typedef struct _mmdb_lookup_t { |
25 | | bool found; /**< True if the lookup produced a result; false if the IP address was not found in the database. */ |
26 | | const char* country; /**< Full name of the country associated with the IP address, or NULL if unavailable. */ |
27 | | const char* country_iso; /**< ISO 3166-1 alpha-2 country code (e.g. "US", "DE"), or NULL if unavailable. */ |
28 | | const char* city; /**< City name associated with the IP address, or NULL if unavailable. */ |
29 | | uint32_t as_number; /**< Autonomous System (AS) number associated with the IP address, or 0 if unavailable. */ |
30 | | const char* as_org; /**< Name of the organization owning the AS, or NULL if unavailable. */ |
31 | | double latitude; /**< Geographic latitude of the IP address location in decimal degrees. */ |
32 | | double longitude; /**< Geographic longitude of the IP address location in decimal degrees. */ |
33 | | uint16_t accuracy; /**< Estimated accuracy radius of the geolocation result, in kilometers. */ |
34 | | } mmdb_lookup_t; |
35 | | |
36 | | /** |
37 | | * @brief Init / reset function called from prefs_reset. |
38 | | * |
39 | | * @param nameres The name resolution preferences module. |
40 | | */ |
41 | | WS_DLL_LOCAL void maxmind_db_pref_init(module_t *nameres); |
42 | | |
43 | | /** |
44 | | * @brief Cleanup function called from prefs_cleanup. |
45 | | */ |
46 | | WS_DLL_LOCAL void maxmind_db_pref_cleanup(void); |
47 | | |
48 | | /** |
49 | | * @brief Apply preferences for MaxMind database resolution. |
50 | | */ |
51 | | WS_DLL_LOCAL void maxmind_db_pref_apply(void); |
52 | | |
53 | | /** |
54 | | * @brief Look up an IPv4 address in a database |
55 | | * |
56 | | * @param addr IPv4 address to look up |
57 | | * |
58 | | * @return The database entry if found, else NULL. |
59 | | */ |
60 | | WS_DLL_PUBLIC WS_RETNONNULL const mmdb_lookup_t *maxmind_db_lookup_ipv4(const ws_in4_addr *addr); |
61 | | |
62 | | /** |
63 | | * @brief Look up an IPv6 address in a database |
64 | | * |
65 | | * @param addr IPv6 address to look up |
66 | | * |
67 | | * @return The database entry if found, else NULL. |
68 | | */ |
69 | | WS_DLL_PUBLIC WS_RETNONNULL const mmdb_lookup_t *maxmind_db_lookup_ipv6(const ws_in6_addr *addr); |
70 | | |
71 | | /** |
72 | | * @brief Get all configured paths |
73 | | * |
74 | | * @return String with all paths separated by a path separator. The string |
75 | | * must be freed. |
76 | | */ |
77 | | WS_DLL_PUBLIC char *maxmind_db_get_paths(void); |
78 | | |
79 | | /** |
80 | | * @brief Process outstanding requests. |
81 | | * |
82 | | * @return True if any new addresses were resolved. |
83 | | */ |
84 | | WS_DLL_LOCAL bool maxmind_db_lookup_process(void); |
85 | | |
86 | | /** |
87 | | * @brief Checks whether the lookup result was successful and has valid coordinates. |
88 | | * |
89 | | * @param result The lookup result to check. |
90 | | * @return True if the lookup was successful and has valid coordinates, false otherwise. |
91 | | */ |
92 | | static inline bool maxmind_db_has_coords(const mmdb_lookup_t *result) |
93 | 0 | { |
94 | 0 | return result && result->found && |
95 | 0 | result->longitude != DBL_MAX && result->latitude != DBL_MAX; |
96 | 0 | } Unexecuted instantiation: prefs.c:maxmind_db_has_coords Unexecuted instantiation: addr_resolv.c:maxmind_db_has_coords Unexecuted instantiation: maxmind_db.c:maxmind_db_has_coords Unexecuted instantiation: packet-ip.c:maxmind_db_has_coords Unexecuted instantiation: packet-ipv6.c:maxmind_db_has_coords |
97 | | |
98 | | /** |
99 | | * @brief Select whether lookups should be performed synchronously. |
100 | | * |
101 | | * Default is asynchronous lookups. |
102 | | * |
103 | | * @param synchronous Whether maxmind lookups should be synchronous. |
104 | | * |
105 | | * XXX - if we ever have per-session host name etc. information, we |
106 | | * should probably have the "resolve synchronously or asynchronously" |
107 | | * flag be per-session, set with an epan API. |
108 | | */ |
109 | | WS_DLL_PUBLIC void maxmind_db_set_synchrony(bool synchronous); |
110 | | |
111 | | #ifdef __cplusplus |
112 | | } |
113 | | #endif /* __cplusplus */ |
114 | | |
115 | | /* |
116 | | * Editor modelines |
117 | | * |
118 | | * Local Variables: |
119 | | * c-basic-offset: 4 |
120 | | * tab-width: 8 |
121 | | * indent-tabs-mode: nil |
122 | | * End: |
123 | | * |
124 | | * ex: set shiftwidth=4 tabstop=8 expandtab: |
125 | | * :indentSize=4:tabSize=8:noTabs=true: |
126 | | */ |