Skip to content

Commit a0ca954

Browse files
committed
network: do not use IPv4-mapped IPv6-addresses
Fixes: #11560 Signed-off-by: Per von Zweigbergk <pvz@pvz.pp.se>
1 parent b94a025 commit a0ca954

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/flb_network.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ static int net_address_ip_str(flb_sockfd_t fd,
21452145
size_t *output_data_size)
21462146
{
21472147
void *address_data;
2148+
int family;
21482149
int result;
21492150

21502151
errno = 0;
@@ -2184,7 +2185,22 @@ static int net_address_ip_str(flb_sockfd_t fd,
21842185
return -1;
21852186
}
21862187

2187-
if ((inet_ntop(address->ss_family,
2188+
family = address->ss_family;
2189+
2190+
/*
2191+
* For IPv4-mapped IPv6 addresses (e.g. ::ffff:127.0.0.1),
2192+
* emit a plain IPv4 literal instead.
2193+
*/
2194+
if (address->ss_family == AF_INET6) {
2195+
struct in6_addr *addr6 = (struct in6_addr *) address_data;
2196+
2197+
if (IN6_IS_ADDR_V4MAPPED(addr6)) {
2198+
family = AF_INET;
2199+
address_data = &addr6->s6_addr[12];
2200+
}
2201+
}
2202+
2203+
if ((inet_ntop(family,
21882204
address_data,
21892205
output_buffer,
21902206
output_buffer_size)) == NULL) {

0 commit comments

Comments
 (0)