Hi,

When applying hex transform to an IPv6 in unique-id-format, the result is an 
string full of zeros. unique-id-format %{+X}o\ 
%ci:%cp_%fi:%fp_%Ts_%rt:%pid"00000000:D142_00000000:01BB_5B348110_0000:0FC3"
When hex transform is disabled, the IPv6 is printed.

Here is a patch that only applies hex transformation to IPv4 addresses.

mildis
From 203d477265b8e0138c201e8380fd531edea51b05 Mon Sep 17 00:00:00 2001
From: mildis <m...@mildis.org>
Date: Thu, 28 Jun 2018 11:15:32 +0200
Subject: [PATCH] BUG/MINOR: log: don't apply HEX to IPv6 unique-id-format

Forcing hexa transformation in unique-id-format with an IPv6 involved
results in a serie of zeros being wrote instead of the IPv6.
This patch only applies transformation if it is an IPv4.
IPv6 are outputted as-is with their colons.
IPv4 part of IPv4-mapped IPv6 are not transformed.
---
 src/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/log.c b/src/log.c
index b2d4367..b20da33 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1112,7 +1112,7 @@ char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_
 	int iret;
 	char pn[INET6_ADDRSTRLEN];
 
-	if (node->options & LOG_OPT_HEXA) {
+	if ((node->options & LOG_OPT_HEXA) && (sockaddr->sa_family == AF_INET)) {
 		const unsigned char *addr = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_addr.s_addr;
 		iret = snprintf(dst, size, "%02X%02X%02X%02X", addr[0], addr[1], addr[2], addr[3]);
 		if (iret < 0 || iret > size)
-- 
2.4.5

Reply via email to