summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 22:54:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 22:54:21 +0000
commit5ad1048c3d139a11df61392b82d76221ef1576f2 (patch)
tree580007a6d5d06e8d48a5e9209fa23da52d98fb76
parenta19faf8bb7fc1db51f863fea4233639851ba7789 (diff)
ping: fix incorrect handling of -I (Iouri Kharon <bc-info@styx.cabel.net>)
-rw-r--r--networking/ping.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/networking/ping.c b/networking/ping.c
index c4a498cd8..6945abb4a 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -530,8 +530,12 @@ static void ping4(len_and_sockaddr *lsa)
pingsock = create_icmp_socket();
pingaddr.sin = lsa->sin;
- if (source_lsa)
- xbind(pingsock, &lsa->sa, lsa->len);
+ if (source_lsa) {
+ if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF,
+ &source_lsa->sa, source_lsa->len))
+ bb_error_msg_and_die("can't set multicast source interface");
+ xbind(pingsock, &source_lsa->sa, source_lsa->len);
+ }
/* enable broadcast pings */
setsockopt_broadcast(pingsock);
@@ -578,7 +582,7 @@ static void ping6(len_and_sockaddr *lsa)
pingaddr.sin6 = lsa->sin6;
/* untested whether "-I addr" really works for IPv6: */
if (source_lsa)
- xbind(pingsock, &lsa->sa, lsa->len);
+ xbind(pingsock, &source_lsa->sa, source_lsa->len);
#ifdef ICMP6_FILTER
{
@@ -659,7 +663,7 @@ static void ping(len_and_sockaddr *lsa)
printf("PING %s (%s)", hostname, dotted);
if (source_lsa) {
printf(" from %s",
- xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len));
+ xmalloc_sockaddr2dotted_noport(&source_lsa->sa, source_lsa->len));
}
printf(": %d data bytes\n", datalen);
@@ -691,7 +695,6 @@ int ping_main(int argc, char **argv)
if_index = if_nametoindex(opt_I);
if (!if_index) {
/* TODO: I'm not sure it takes IPv6 unless in [XX:XX..] format */
- /* (ping doesn't support source IPv6 addresses yet anyway) */
source_lsa = xdotted2sockaddr(opt_I, 0);
}
}