From d109ff13d8ddf0f5ddb14d06dac5e85b053b58d1 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 12 Mar 2010 00:45:11 +0000 Subject: [PATCH] Consider an address directly connected if the gateway of its matching routing table is exactly the same as the address. This is how it appears to work on Mac OS X. Now there are three ways for an address to be directly connected: 1. Gateway address is 0.0.0.0 (Linux). 2. Gateway address is the same as local interface address (Windows). 3. Gateway address is the same as the destination address (Mac OS X). --- tcpip.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tcpip.cc b/tcpip.cc index d82f04e54..d2f3487a0 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -3668,9 +3668,11 @@ bool route_dst(const struct sockaddr_storage * const dst, rnfo->ii = *routes[i].device; /* At this point we don't whether this route is direct or indirect ("G" flag in netstat). We guess that a route is direct when the gateway address is - 0.0.0.0 or it exactly matches the interface address. */ + 0.0.0.0, when it exactly matches the interface address, or when it + exactly matches the destination address. */ rnfo->direct_connect = (routes[i].gw.s_addr == 0) || - (routes[i].gw.s_addr == ((struct sockaddr_in *) &routes[i].device->addr)->sin_addr.s_addr); + (routes[i].gw.s_addr == ((struct sockaddr_in *) &routes[i].device->addr)->sin_addr.s_addr) || + (routes[i].gw.s_addr == dstsin->sin_addr.s_addr); if (!o.spoofsource) rnfo->srcaddr = routes[i].device->addr; ifsin = (struct sockaddr_in *) &rnfo->nexthop;