From 22d49bd5c9ca1cd5ca89e980e8e897eb7b9a925c Mon Sep 17 00:00:00 2001 From: david Date: Sun, 30 Sep 2012 00:01:14 +0000 Subject: [PATCH] Match against both destination and gateway in sysroutes_dnet_find_interfaces. This commit fixes two different bugs: (1) First in some situations Nmap will only see routes that are attached to the device that handles the default route. (2) On boxes without a default route, Nmap will not see any route. These two bugs are caused by sysroutes_dnet_find_interfaces() logic which will use only the geteway to match interface addresses. To fix this, first check the current route and see if the gateway was set otherwise use the destination address to match the address of an interface. --- libnetutil/netutil.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index 34ed4f46b..8277ea5a2 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -1539,12 +1539,21 @@ static struct dnet_collector_route_nfo *sysroutes_dnet_find_interfaces(struct dn if (dcrn->routes[i].device != NULL) continue; - /* First we match up routes whose gateway address directly matches the - address of an interface. */ + /* First we match up routes whose gateway or destination address + directly matches the address of an interface. */ + struct sys_route *route = &dcrn->routes[i]; + struct sockaddr_storage *routeaddr; + + /* First see if the gateway was set */ + if (sockaddr_equal_zero(&route->gw)) + routeaddr = &dcrn->routes[i].dest; + else + routeaddr = &dcrn->routes[i].gw; + for (j = 0; j < numifaces; j++) { if (!ifaces[j].device_up) continue; - if (sockaddr_equal_netmask(&ifaces[j].addr, &dcrn->routes[i].gw, ifaces[j].netmask_bits)) { + if (sockaddr_equal_netmask(&ifaces[j].addr, routeaddr, ifaces[j].netmask_bits)) { dcrn->routes[i].device = &ifaces[j]; break; }