From 66bd9d19932219914fc26bc08cd467de235b8a0b Mon Sep 17 00:00:00 2001 From: david Date: Sat, 9 Feb 2013 18:55:46 +0000 Subject: [PATCH] Enforce device name only after choosing loopback in route_dst_generic. Nping calls route_dst at least twice: once with a NULL device, and again with the device learned from the first time. This interfered with the code that automatically chooses a loopback interface for dests that are the same as an interface address. For example, if you are 192.168.0.1, and you are scanning 192.168.0.1, route_dst will tell you to use interface "lo0" even though the interface of 192.168.0.1 may be "eth0". route_dst was returning failure because the device name check was being done before "eth0" got changed to "lo0". This problem didn't show up on Linux because Linux uses route_dst_netlink, which delegates the work to the kernel. But I could reproduce on Linux by forcing the use of route_dst_generic. --- libnetutil/netutil.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index be5ee8c61..fef42801c 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -3344,8 +3344,6 @@ static int route_dst_generic(const struct sockaddr_storage *dst, if (!sockaddr_equal(dst, &ifaces[i].addr)) continue; - if (iface != NULL && strcmp(ifaces[i].devname, iface->devname) != 0) - continue; if (ifaces[i].device_type == devt_loopback) loopback = &ifaces[i]; @@ -3355,6 +3353,9 @@ static int route_dst_generic(const struct sockaddr_storage *dst, /* Hmmm ... no localhost -- move on to the routing table. */ break; + if (iface != NULL && strcmp(loopback->devname, iface->devname) != 0) + continue; + rnfo->ii = *loopback; rnfo->direct_connect = 1; /* But the source address we want to use is the target address. */