Skip to content

Commit

Permalink
strip the prefix from ipv4-mapped addresses
Browse files Browse the repository at this point in the history
This allows to have plain IPv4 addresses in log, even if listening
on an IPv6 socket.

Before:

    ::ffff:10.7.7.72 - - [24/Jan/2025:22:15:54 +0100] "GET /archive.tar.zst HTTP/1.1" 200 72194 "" "pacredir/0.4.8 (arch/x86_64)"

After:

    10.7.7.72 - - [24/Jan/2025:22:15:54 +0100] "GET /archive.tar.zst HTTP/1.1" 200 72194 "" "pacredir/0.4.8 (arch/x86_64)"
  • Loading branch information
eworm-de committed Jan 27, 2025
1 parent 0d4c444 commit 9e5738c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions darkhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ static const char *get_address_text(const void *addr) {
static char text_addr[INET6_ADDRSTRLEN];
const struct in6_addr *in6_addr = addr;
inet_ntop(AF_INET6, in6_addr, text_addr, INET6_ADDRSTRLEN);
/* IPv4 addresses via dual stack result in mapped IPv6 addresses.
Strip the prefix (::ffff:) for plain IPv4 addresses. */
if (IN6_IS_ADDR_V4MAPPED(in6_addr))
return text_addr + 7;
return text_addr;
} else
#endif
Expand Down

0 comments on commit 9e5738c

Please sign in to comment.