summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2018-10-24 23:38:58 +0100
committerSami Kerola <kerolasa@iki.fi>2018-10-24 23:38:58 +0100
commit4082ba9e780320e3c6e31a21c7d7ad164c229b5b (patch)
tree791f157c66e9f8abafe51b4e6ad5c402ec77ff6a
parentd52fa39545bfa8dd6656a5bfc6cf119c1d57381e (diff)
downloadiputils-issue-104.tar.gz
ping: do not bind to device when destination IP is on deviceissue-104
Commit f455fee41c077d4b700a473b2f5b3487b8febc1d made ping to bind to device when a device argument was given. But that to does not work if destination IP on device that socket binds to. See below how to reproduce this issue. # ip addr show dev eth0 | grep 'inet ' inet 192.168.122.100/24 brd 192.168.122.255 scope global eth0 # ping -I eth0 192.168.122.100 PING 192.168.122.100 (192.168.122.100) from 192.168.122.100 eth0: 56(84) bytes of data. <nothing... loops forever> Easiest workaround is to cancel bind to device socket option when source and destination IPs are the same and device option is defined. Addresses: https://github.com/iputils/iputils/issues/104 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r--ping.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ping.c b/ping.c
index 791a48e..965c854 100644
--- a/ping.c
+++ b/ping.c
@@ -652,6 +652,12 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock)
&source.sin_addr, sizeof(source.sin_addr)))
break;
}
+ if (ifa && !memcmp(&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr,
+ &dst.sin_addr, sizeof(source.sin_addr))) {
+ enable_capability_raw();
+ setsockopt(sock->fd, SOL_SOCKET, SO_BINDTODEVICE, "", 0);
+ disable_capability_raw();
+ }
freeifaddrs(ifa0);
if (!ifa)
error(0, 0, "Warning: source address might be selected on device other than: %s", device);