Skip to content

Commit

Permalink
gsockaddr: V4-mapped addresses should be formatted as an IPv4 address
Browse files Browse the repository at this point in the history
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:<ipv4>" 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 <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Oct 16, 2023
1 parent 1312aed commit d3aaede
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/gsockaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d3aaede

Please sign in to comment.