All of lore.kernel.org
 help / color / mirror / Atom feed
* [iputils][ping] ip address resolution bug
@ 2013-06-09 22:52 Quentin RAMEAU
  0 siblings, 0 replies; only message in thread
From: Quentin RAMEAU @ 2013-06-09 22:52 UTC (permalink / raw)
  To: netdev

[-- Attachment #1: Type: text/plain, Size: 362 bytes --]

Ping does not ensure it is resolving a hostname to an IPv4 address.
i.e. when setting 'options inet6' in resolv.conf, gethostbyname(3)
returns an IPv6 address, but ping handles it as in IPv4 address.
I attached a simple patch which replaces gethostbyname() with
gethostbyname2(), I'm not sure that is the best way to do it, feel
free to comment.

Quentin Rameau

[-- Attachment #2: ping-address-resolution.diff --]
[-- Type: application/octet-stream, Size: 320 bytes --]

diff --git a/ping.c b/ping.c
index c0366cd..4989760 100644
--- a/ping.c
+++ b/ping.c
@@ -279,7 +279,7 @@ main(int argc, char **argv)
 #else
 			idn = target;
 #endif
-			hp = gethostbyname(idn);
+			hp = gethostbyname2(idn, AF_INET);
 			if (!hp) {
 				fprintf(stderr, "ping: unknown host %s\n", target);
 				exit(2);

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-06-09 22:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-09 22:52 [iputils][ping] ip address resolution bug Quentin RAMEAU

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.