1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-23 06:39:01 +00:00

Honor sin6_scope_id in route_dst_generic.

This is set nonzero when there is a scope identifier at the end of
an IPv6 address, like fe80::a8bb:ccff:fedd:eeff%eth0 or
fe80::a8bb:ccff:fedd:eeff%1 on Windows. When this happens, we look up
the interface by index and then act as if it was the interface given by
-e. (But -e always has precedence over this.)
This commit is contained in:
david
2011-08-30 17:01:51 +00:00
parent 12f4742f0f
commit d759b485ea

View File

@@ -3094,6 +3094,7 @@ static int route_dst_generic(const struct sockaddr_storage *dst,
struct sys_route *routes;
int numroutes = 0;
int i;
char namebuf[32];
char errstr[256];
errstr[0]='\0';
@@ -3107,10 +3108,35 @@ static int route_dst_generic(const struct sockaddr_storage *dst,
assert(device!=NULL && device[0]!='\0');
}
if (device == NULL || device[0] == '\0') {
/* Check if there is an interface scope on the address which we must use. */
if (dst->ss_family == AF_INET6) {
const struct sockaddr_in6 *sin6;
sin6 = (struct sockaddr_in6 *) dst;
if (sin6->sin6_scope_id > 0) {
intf_t *it;
struct intf_entry entry;
int rc;
it = intf_open();
assert(it != NULL);
entry.intf_len = sizeof(entry);
rc = intf_get_index(it, &entry, sin6->sin6_family, sin6->sin6_scope_id);
if (rc == -1)
netutil_fatal("Could not find interface with index %u", (unsigned int) sin6->sin6_scope_id);
intf_close(it);
Strncpy(namebuf, entry.intf_name, sizeof(namebuf));
device = namebuf;
}
}
}
if (device!=NULL && device[0]!='\0'){
iface = getInterfaceByName(device, dst->ss_family);
if (!iface)
netutil_fatal("Could not find interface %s which was specified by -e", device);
netutil_fatal("Could not find interface %s", device);
} else {
iface = NULL;
}