[PATCH 1/1] ping: Add support for IPv4-mapped IPv6 address format

Petr Vorel petr.vorel at gmail.com
Fri Oct 18 18:12:19 UTC 2024


IP addresses with ::ffff: prefix are IPv6 addresses which are mapped to
IPv4. Therefore ping resulting IPv4 address.

Cc: Tj <linux at iam.tj>
Signed-off-by: Petr Vorel <petr.vorel at gmail.com>
---
Based on idea contributed to iputils.
https://github.com/iputils/iputils/commit/8ed7ffc999e2a541e06ee48faf26a323dfe487c2

Kind regards,
Petr

 networking/ping.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/networking/ping.c b/networking/ping.c
index b7e6955a9..7ed58f9d6 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -986,6 +986,14 @@ static int common_ping_main(int opt, char **argv)
 			af = AF_INET;
 		if (opt & OPT_IPV6)
 			af = AF_INET6;
+
+		struct in6_addr a6;
+		if (inet_pton(AF_INET6, hostname, &a6) && IN6_IS_ADDR_V4MAPPED(&a6)) {
+			hostname = strrchr(hostname, ':') + 1;
+			af = AF_INET;
+			printf("IPv4-Mapped-in-IPv6 address, using IPv4 %s\n", hostname);
+		}
+
 		lsa = xhost_and_af2sockaddr(hostname, 0, af);
 	}
 #else
-- 
2.45.2



More information about the busybox mailing list