From f86f2dec67210c1ba32e765d071eed8898dd6f81 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 30 Aug 2011 23:55:09 +0000 Subject: [PATCH] Assign scope id in nmap_route_dst. This is done for all IPv6 addresses when the -e option is used. --- tcpip.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tcpip.cc b/tcpip.cc index ad0d0bc81..4e69e6a96 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -1972,16 +1972,34 @@ pcap_if_t *getpcapinterfaces() { +/* Assign the sin6_scope_id member of a sockaddr_in6, based on a device name. + This is used to assign scope to all addresses with the -e option is used. */ +static void assign_scope_id(struct sockaddr_in6 *sin6, const char *devname) { + struct interface_info *ii; + + if (devname == NULL || devname[0] == '\0') + return; + ii = getInterfaceByName(devname, sin6->sin6_family); + if (ii != NULL) + sin6->sin6_scope_id = ii->ifindex; +} + int nmap_route_dst(const struct sockaddr_storage *dst, struct route_nfo *rnfo) { - struct sockaddr_storage spoofss; + struct sockaddr_storage dst_mod, spoofss; size_t spoofsslen; + /* Make a copy that we may modify (only to possibly add a sin6_scope_id). */ + dst_mod = *dst; + + if (dst_mod.ss_family == AF_INET6) + assign_scope_id((struct sockaddr_in6 *) &dst_mod, o.device); + if (o.spoofsource) { o.SourceSockAddr(&spoofss, &spoofsslen); - return route_dst(dst, rnfo, o.device, &spoofss); + return route_dst(&dst_mod, rnfo, o.device, &spoofss); } else { - return route_dst(dst, rnfo, o.device, NULL); + return route_dst(&dst_mod, rnfo, o.device, NULL); } }