Patchwork iputils: ping.c - using -I for both interface and address

login
register
mail settings
Submitter Nadav Shemer
Date Sept. 18, 2008, 5 p.m.
Message ID <a60ec8830809181000s928a4drbd0b166be23abcee@mail.gmail.com>
Download mbox | patch
Permalink /patch/538/
State Not Applicable
Headers show

Comments

Nadav Shemer - Sept. 18, 2008, 5 p.m.
When I use 'ping 1.2.3.4 -I eth1 -I 2.3.4.5' the packets come out with
eth1's address anyway.
It seems to me that IP_PKTINFO is set for every packet, with
ipi_spec_dst set to 0. This overrides the inet->saddr set by bind.

Here's a fix:

Patch

--- ping.c	2007-11-27 02:57:27.000000000 +0200
+++ ping.c.patched	2008-09-18 19:59:45.000000000 +0300
@@ -350,6 +350,8 @@ 
 			fprintf(stderr, "ping: unknown iface %s\n", device);
 			exit(2);
 		}
+		if (options & F_STRICTSOURCE)
+			cmsg.ipi.ipi_spec_dst.s_addr = source.sin_addr.s_addr;
 		cmsg.ipi.ipi_ifindex = ifr.ifr_ifindex;
 		cmsg_len = sizeof(cmsg);
 	}