From d3aaedee2b9961077c25d4c62d3245aeff94eda7 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Sun, 15 Oct 2023 11:40:01 +0200 Subject: [PATCH] gsockaddr: V4-mapped addresses should be formatted as an IPv4 address V4-mapped address space is a compatibility feature of dual-stack TCP/IP stacks, where IPv4 connections can be established to IPv6 capable sockets. When this happens, the client IP address would be a V4-mapped address, as determined by the IN6_IS_ADDR_V4MAPPED() function, which is equivalent to an "::FFFF:" address (see RFC3493) This change would trickle into how we fill $HOST if we didn't find a hostname there, previously these would have the form of "::FFFF:ipv4", with this one they would become "ipv4" just as if we received them using an ipv4 specific source. Signed-off-by: Balazs Scheidler --- lib/gsockaddr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/gsockaddr.c b/lib/gsockaddr.c index 11ad61e4622..ab77a6a1498 100644 --- a/lib/gsockaddr.c +++ b/lib/gsockaddr.c @@ -377,7 +377,10 @@ g_sockaddr_inet6_format(GSockAddr *s, gchar *text, gulong n, gint format) } else if (format == GSA_ADDRESS_ONLY) { - inet_ntop(AF_INET6, &self->sin6.sin6_addr, text, n); + if (IN6_IS_ADDR_V4MAPPED(&self->sin6.sin6_addr)) + inet_ntop(AF_INET, &self->sin6.sin6_addr.s6_addr32[3], text, n); + else + inet_ntop(AF_INET6, &self->sin6.sin6_addr, text, n); } else g_assert_not_reached();