mirror of
https://github.com/nmap/nmap.git
synced 2026-01-16 11:29:02 +00:00
Sort routes first by netmask, then by metric.
Metric is used to break ties between routes with the same size netmask.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
# Nmap Changelog ($Id$); -*-text-*-
|
||||
|
||||
o Nmap's routing table is now sorted first by netmask, then by metric.
|
||||
Previously it was the other way around, which could cause a very
|
||||
general route with a low metric to be preferred over a specific
|
||||
route with a higher metric.
|
||||
|
||||
o [Ncat] The -i option (idle timeout) now works in listen mode as well
|
||||
as connect mode. [Tomas Hozza]
|
||||
|
||||
|
||||
@@ -1200,7 +1200,7 @@ void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
||||
|
||||
|
||||
|
||||
/* A trivial function used with qsort to sort the routes by metric and netmask */
|
||||
/* A trivial function used with qsort to sort the routes by netmask and metric */
|
||||
static int routecmp(const void *a, const void *b) {
|
||||
struct sys_route *r1 = (struct sys_route *) a;
|
||||
struct sys_route *r2 = (struct sys_route *) b;
|
||||
@@ -1209,16 +1209,16 @@ static int routecmp(const void *a, const void *b) {
|
||||
else if (r1->dest.ss_family > r2->dest.ss_family)
|
||||
return 1;
|
||||
|
||||
if (r1->metric < r2->metric)
|
||||
return -1;
|
||||
else if (r1->metric > r2->metric)
|
||||
return 1;
|
||||
|
||||
if (r1->netmask_bits < r2->netmask_bits)
|
||||
return 1;
|
||||
else if (r1->netmask_bits > r2->netmask_bits)
|
||||
return -1;
|
||||
|
||||
if (r1->metric < r2->metric)
|
||||
return -1;
|
||||
else if (r1->metric > r2->metric)
|
||||
return 1;
|
||||
|
||||
/* Compare addresses of equal elements to make the sort stable, as suggested
|
||||
by the Glibc manual. */
|
||||
if (a < b)
|
||||
@@ -1698,7 +1698,7 @@ struct sys_route *getsysroutes(int *howmany, char *errstr, size_t errstrlen) {
|
||||
return NULL;
|
||||
}else{
|
||||
numroutes = *howmany;
|
||||
/* Ensure that the route array is sorted by metric and netmask */
|
||||
/* Ensure that the route array is sorted by netmask and metric */
|
||||
qsort(routes, numroutes, sizeof(routes[0]), routecmp);
|
||||
}
|
||||
return routes;
|
||||
|
||||
Reference in New Issue
Block a user