summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);