Change maxmind_db_lookup_ipv4 to look more like maxmind_db_lookup_ipv6

Both functions accept an address in network byte order, but
maxmind_db_lookup_ipv4 does not accept a pointer. Add an indirection and
remove unnecessary memcpy calls. This removes some confusion for me.

Change-Id: I291c54c8c55bc8048ca011b84918c8a5d3ed1398
Reviewed-on: https://code.wireshark.org/review/31951
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2019-02-09 23:25:17 +01:00 committed by Anders Broman
parent 426107f2b5
commit 5c4458345c
5 changed files with 13 additions and 15 deletions

View File

@ -570,9 +570,9 @@ capture_ip(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo,
}
static void
add_geoip_info_entry(proto_tree *tree, tvbuff_t *tvb, gint offset, guint32 ip, int isdst)
add_geoip_info_entry(proto_tree *tree, tvbuff_t *tvb, gint offset, ws_in4_addr ip, int isdst)
{
const mmdb_lookup_t *lookup = maxmind_db_lookup_ipv4(ip);
const mmdb_lookup_t *lookup = maxmind_db_lookup_ipv4(&ip);
if (!lookup->found) return;
wmem_strbuf_t *summary = wmem_strbuf_new(wmem_packet_scope(), "");

View File

@ -630,16 +630,16 @@ gboolean maxmind_db_lookup_process(void)
}
const mmdb_lookup_t *
maxmind_db_lookup_ipv4(guint32 addr) {
mmdb_lookup_t *result = (mmdb_lookup_t *) wmem_map_lookup(mmdb_ipv4_map, GUINT_TO_POINTER(addr));
maxmind_db_lookup_ipv4(const ws_in4_addr *addr) {
mmdb_lookup_t *result = (mmdb_lookup_t *) wmem_map_lookup(mmdb_ipv4_map, GUINT_TO_POINTER(*addr));
if (!result) {
result = &mmdb_not_found;
wmem_map_insert(mmdb_ipv4_map, GUINT_TO_POINTER(addr), result);
wmem_map_insert(mmdb_ipv4_map, GUINT_TO_POINTER(*addr), result);
if (mmdbr_pipe_valid()) {
char addr_str[WS_INET_ADDRSTRLEN];
ws_inet_ntop4(&addr, addr_str, WS_INET_ADDRSTRLEN);
ws_inet_ntop4(addr, addr_str, WS_INET_ADDRSTRLEN);
MMDB_DEBUG("looking up %s", addr_str);
g_async_queue_push(mmdbr_request_q, g_strdup_printf("%s\n", addr_str));
}
@ -707,7 +707,7 @@ maxmind_db_lookup_process(void)
}
const mmdb_lookup_t *
maxmind_db_lookup_ipv4(guint32 addr _U_) {
maxmind_db_lookup_ipv4(const ws_in4_addr *addr _U_) {
return &mmdb_not_found;
}

View File

@ -17,8 +17,9 @@
extern "C" {
#endif /* __cplusplus */
#include <epan/ipv6.h>
#include <epan/prefs.h>
#include <wsutil/inet_ipv4.h>
#include <wsutil/inet_ipv6.h>
#include "ws_symbol_export.h"
typedef struct _mmdb_lookup_t {
@ -49,7 +50,7 @@ WS_DLL_LOCAL void maxmind_db_pref_cleanup(void);
*
* @return The database entry if found, else NULL.
*/
WS_DLL_PUBLIC WS_RETNONNULL const mmdb_lookup_t *maxmind_db_lookup_ipv4(guint32 addr);
WS_DLL_PUBLIC WS_RETNONNULL const mmdb_lookup_t *maxmind_db_lookup_ipv4(const ws_in4_addr *addr);
/**
* Look up an IPv6 address in a database

View File

@ -1223,10 +1223,9 @@ sharkd_session_geoip_addr(address *addr, const char *suffix)
if (addr->type == AT_IPv4)
{
guint32 ip;
const ws_in4_addr *ip4 = (const ws_in4_addr *) addr->data;
memcpy(&ip, addr->data, 4);
lookup = maxmind_db_lookup_ipv4(ip);
lookup = maxmind_db_lookup_ipv4(ip4);
}
else if (addr->type == AT_IPv6)
{

View File

@ -210,9 +210,7 @@ public:
const mmdb_lookup_t *mmdb_lookup = NULL;
if (endp_item->myaddress.type == AT_IPv4) {
guint32 ip;
memcpy(&ip, endp_item->myaddress.data, 4);
mmdb_lookup = maxmind_db_lookup_ipv4(ip);
mmdb_lookup = maxmind_db_lookup_ipv4((ws_in4_addr *) endp_item->myaddress.data);
} else if (endp_item->myaddress.type == AT_IPv6) {
mmdb_lookup = maxmind_db_lookup_ipv6((ws_in6_addr *) endp_item->myaddress.data);
}