From a7b2ee81dfc78d0f9b17e93a3ed9ce9fbe220eba Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 12 Aug 2016 13:57:57 +0100 Subject: [PATCH] [Feature] Print radix duplicate keys as IP addresses --- src/libutil/radix.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libutil/radix.c b/src/libutil/radix.c index b165401f7..7827d41ac 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -67,6 +67,7 @@ radix_insert_compressed (radix_compressed_t * tree, { guint keybits = keylen * NBBY; uintptr_t old; + gchar ip_str[INET6_ADDRSTRLEN + 1]; int ret; g_assert (tree != NULL); @@ -81,8 +82,24 @@ radix_insert_compressed (radix_compressed_t * tree, (gconstpointer)value); if (ret != BTRIE_OKAY) { - msg_err_radix ("cannot insert %p with mask %z, key: %*xs, duplicate value", + memset (ip_str, 0, sizeof (ip_str)); + + if (keybits == 32) { + msg_err_radix ("cannot insert %p, key: %s/%d, duplicate value", + (gpointer)value, + inet_ntop (AF_INET, key, ip_str, sizeof (ip_str) - 1), + keybits - masklen); + } + else if (keybits == 128) { + msg_err_radix ("cannot insert %p, key: [%s]/%d, duplicate value", + (gpointer)value, + inet_ntop (AF_INET6, key, ip_str, sizeof (ip_str) - 1), + keybits - masklen); + } + else { + msg_err_radix ("cannot insert %p with mask %z, key: %*xs, duplicate value", (gpointer)value, keybits - masklen, (int)keylen, key); + } } else { tree->size ++; -- 2.39.5