mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
added more comments, fixed a small bug, and refactored code in route_dst
This commit is contained in:
30
tcpip.cc
30
tcpip.cc
@@ -3070,12 +3070,16 @@ bool route_dst(const struct sockaddr_storage *const dst, struct route_nfo *rnfo)
|
|||||||
|
|
||||||
if (o.spoofsource) {
|
if (o.spoofsource) {
|
||||||
o.SourceSockAddr(&spoofss, &spoofsslen);
|
o.SourceSockAddr(&spoofss, &spoofsslen);
|
||||||
|
//throughout the rest of this function we only change rnfo->srcaddr if the source isnt spoofed
|
||||||
|
memcpy(&rnfo->srcaddr, &spoofss, sizeof(rnfo->srcaddr));
|
||||||
/* The device corresponding to this spoofed address should already have been
|
/* The device corresponding to this spoofed address should already have been
|
||||||
set elsewhere. */
|
set elsewhere. */
|
||||||
assert(o.device[0] != '\0');
|
assert(o.device[0] != '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
//dont use this method for user specified devices
|
//first we check to see if the host is directly connected,
|
||||||
|
//if not, we have to check the routing table
|
||||||
|
//also, if the user specified a device we have to check the routing table
|
||||||
if(!*o.device) {
|
if(!*o.device) {
|
||||||
ifaces = getinterfaces(&numifaces);
|
ifaces = getinterfaces(&numifaces);
|
||||||
/* I suppose that I'll first determine whether it is a direct connect
|
/* I suppose that I'll first determine whether it is a direct connect
|
||||||
@@ -3094,9 +3098,7 @@ bool route_dst(const struct sockaddr_storage *const dst, struct route_nfo *rnfo)
|
|||||||
rnfo->direct_connect = true;
|
rnfo->direct_connect = true;
|
||||||
memcpy(&rnfo->ii, &ifaces[i], sizeof(rnfo->ii));
|
memcpy(&rnfo->ii, &ifaces[i], sizeof(rnfo->ii));
|
||||||
/* But the source address we want to use is the target addy */
|
/* But the source address we want to use is the target addy */
|
||||||
if (o.spoofsource)
|
if (!o.spoofsource)
|
||||||
memcpy(&rnfo->srcaddr, &spoofss, sizeof(rnfo->srcaddr));
|
|
||||||
else
|
|
||||||
memcpy(&rnfo->srcaddr, &ifaces[ifnum].addr, sizeof(rnfo->srcaddr));
|
memcpy(&rnfo->srcaddr, &ifaces[ifnum].addr, sizeof(rnfo->srcaddr));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3105,7 +3107,7 @@ bool route_dst(const struct sockaddr_storage *const dst, struct route_nfo *rnfo)
|
|||||||
}
|
}
|
||||||
mask = htonl((unsigned long) (0-1) << (32 - ifaces[ifnum].netmask_bits));
|
mask = htonl((unsigned long) (0-1) << (32 - ifaces[ifnum].netmask_bits));
|
||||||
if ((ifsin->sin_addr.s_addr & mask) == (dstsin->sin_addr.s_addr & mask)) {
|
if ((ifsin->sin_addr.s_addr & mask) == (dstsin->sin_addr.s_addr & mask)) {
|
||||||
rnfo->direct_connect = 1;
|
rnfo->direct_connect = true;
|
||||||
memcpy(&rnfo->ii, &ifaces[ifnum], sizeof(rnfo->ii));
|
memcpy(&rnfo->ii, &ifaces[ifnum], sizeof(rnfo->ii));
|
||||||
if (!o.spoofsource) {
|
if (!o.spoofsource) {
|
||||||
memcpy(&rnfo->srcaddr, &ifaces[ifnum].addr, sizeof(rnfo->srcaddr));
|
memcpy(&rnfo->srcaddr, &ifaces[ifnum].addr, sizeof(rnfo->srcaddr));
|
||||||
@@ -3115,6 +3117,10 @@ bool route_dst(const struct sockaddr_storage *const dst, struct route_nfo *rnfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//assume the device isnt directly connected until we know it is
|
||||||
|
//the only case it could be is if the user specified an interface
|
||||||
|
rnfo->direct_connect = false;
|
||||||
|
|
||||||
if (*o.device) {
|
if (*o.device) {
|
||||||
iface = getInterfaceByName(o.device);
|
iface = getInterfaceByName(o.device);
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
@@ -3123,16 +3129,15 @@ bool route_dst(const struct sockaddr_storage *const dst, struct route_nfo *rnfo)
|
|||||||
/* Is it directly connected? */
|
/* Is it directly connected? */
|
||||||
mask = htonl((unsigned long) (0-1) << (32 - iface->netmask_bits));
|
mask = htonl((unsigned long) (0-1) << (32 - iface->netmask_bits));
|
||||||
ifsin = (struct sockaddr_in *) &(iface->addr);
|
ifsin = (struct sockaddr_in *) &(iface->addr);
|
||||||
if ((ifsin->sin_addr.s_addr & mask) == (dstsin->sin_addr.s_addr & mask))
|
if ((ifsin->sin_addr.s_addr & mask) == (dstsin->sin_addr.s_addr & mask)){
|
||||||
rnfo->direct_connect = 1;
|
rnfo->direct_connect = true;
|
||||||
else {
|
memcpy(&rnfo->ii, iface, sizeof(rnfo->ii));
|
||||||
rnfo->direct_connect = 0;
|
if (!o.spoofsource)
|
||||||
|
memcpy(&rnfo->srcaddr, &(iface->addr), sizeof(rnfo->srcaddr));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
rnfo->direct_connect = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
routes = getsysroutes(&numroutes);
|
routes = getsysroutes(&numroutes);
|
||||||
/* Now we simply go through the list and take the first match */
|
/* Now we simply go through the list and take the first match */
|
||||||
for(i=0; i < numroutes; i++) {
|
for(i=0; i < numroutes; i++) {
|
||||||
@@ -3143,6 +3148,7 @@ bool route_dst(const struct sockaddr_storage *const dst, struct route_nfo *rnfo)
|
|||||||
//ignore routes that arent on the device we specified!
|
//ignore routes that arent on the device we specified!
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
if (!o.spoofsource)
|
||||||
memcpy(&rnfo->srcaddr, &(iface->addr), sizeof(rnfo->srcaddr));
|
memcpy(&rnfo->srcaddr, &(iface->addr), sizeof(rnfo->srcaddr));
|
||||||
memcpy(&rnfo->ii, iface, sizeof(rnfo->ii));
|
memcpy(&rnfo->ii, iface, sizeof(rnfo->ii));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user