Skip to content

Commit

Permalink
Revert "ping: fix ping6 name resolution for hostnames with link-local…
Browse files Browse the repository at this point in the history
… addresses"

This reverts commit d217170.

Reverting it allows pinging IPv4-mapped IPv6 address because glibc...

fe80::fc54:ff:fe29:5693%vnet0

Pinging IPv6 link scope address without scope ID still works:
$ ./builddir/ping/ping -v -c1 fe80::fc54:ff:fe29:5693
./builddir/ping/ping: sock4.fd: 3 (socktype: SOCK_RAW), sock6.fd: 4 (socktype: SOCK_RAW), hints.ai_family: AF_UNSPEC

ai->ai_family: AF_INET6, ai->ai_canonname: 'fe80::fc54:ff:fe29:5693'
PING fe80::fc54:ff:fe29:5693 (fe80::fc54:ff:fe29:5693) 56 data bytes
64 bytes from fe80::fc54:ff:fe29:5693%vnet0: icmp_seq=1 ident=53558 ttl=64 time=0.066 ms

--- fe80::fc54:ff:fe29:5693 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.066/0.066/0.066/0.000 ms

Therefore there is no reason to force

Original effort from issue iputils#252 [1] (PR#253 [2])
[1] iputils#252
[2] iputils#253
  • Loading branch information
pevik committed Nov 17, 2024
1 parent dca2358 commit 21a2233
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions ping/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,6 @@ main(int argc, char **argv)
if (rts.tclass)
set_socket_option(&sock6, IPPROTO_IPV6, IPV6_TCLASS, &rts.tclass, sizeof(rts.tclass));

/* getaddrinfo fails to indicate a scopeid when not used in dual-stack mode.
* Work around by always using dual-stack name resolution.
*
* https://github.com/iputils/iputils/issues/252
*/
int target_ai_family = hints.ai_family;
hints.ai_family = AF_UNSPEC;

if (!strchr(target, '%') && sock6.socktype == SOCK_DGRAM &&
inet_pton(AF_INET6, target, buf) > 0 &&
(IN6_IS_ADDR_LINKLOCAL(buf) || IN6_IS_ADDR_MC_LINKLOCAL(buf))) {
Expand All @@ -703,8 +695,8 @@ main(int argc, char **argv)
str_family(ai->ai_family),
ai->ai_canonname ? ai->ai_canonname : "");

if (target_ai_family != AF_UNSPEC &&
target_ai_family != ai->ai_family) {
if (hints.ai_family != AF_UNSPEC &&
hints.ai_family != ai->ai_family) {
if (!ai->ai_next) {
/* An address was found, but not of the family we really want.
* Throw the appropriate gai error.
Expand Down

0 comments on commit 21a2233

Please sign in to comment.