Renaud & crew,
I'm running nessus for a few colleagues, and they've been bugging me
about how nice it would be if the html result files I sent them had
hosts sorted by IP address.
I tried sorting the nbe files by IP before converting them to HTML,
but that didn't work -- the hosts were still listed in random order in
the html file.
So, I hacked together a sorting routine for the arglist containing the
hosts in html_output.c. Now, everytime html output is generated, the
hosts will be given sorted by IP (the comparison falls back on simple
strcmp() if one of the names is not an IP address).
I've attached a patch to 2.0.6a (only nessus/html_output.c is changed).
Let me know if you think this is (not) a good idea... :)
Thanks,
Gabriel
diff -U4 -r nessus-core/nessus/html_output.c nessus-core-sorthtml/nessus/html_output.c
--- nessus-core/nessus/html_output.c 2003-01-29 08:33:21.000000000 -0700
+++ nessus-core-sorthtml/nessus/html_output.c 2003-06-24 14:03:53.000000000 -0600
@@ -227,8 +227,61 @@
return t ;
}
+static int
+compar_hosts(p1, p2)
+ void *p1, *p2;
+{
+ char *n1 = (*(struct arglist **)p1)->name;
+ char *n2 = (*(struct arglist **)p2)->name;
+ struct in_addr in1, in2;
+
+ if( n1 == n2 ) return 0;
+
+ if( !n1 ) return 1;
+ if( !n2 ) return -1;
+
+ if( inet_aton(n1, &in1) && inet_aton(n2, &in2) )
+ return (long)ntohl(in1.s_addr) - (long)ntohl(in2.s_addr);
+
+ return strcmp( n1, n2 );
+}
+
+static void
+sort_arglist(args)
+ struct arglist * args;
+{
+ int n, i;
+ struct arglist sa;
+ struct arglist * a;
+ struct arglist ** table;
+
+ for(a = args, n = 0; a; a = a->next, n++);
+ table = emalloc(n * sizeof(struct arglist *));
+ for(a = args, i = 0; a; a = a->next, i++)
+ table[i] = a;
+
+ qsort(table, n, sizeof(struct arglist *), compar_hosts);
+
+ /* make sure list head remains the same */
+ for(i = 0; i < n && args != table[i]; i++);
+ if( i != 0 ) {
+ a = table[i];
+ table[i] = table[0];
+ table[0] = a;
+ memcpy(&sa, table[i], sizeof(struct arglist));
+ memcpy(table[i], table[0], sizeof(struct arglist));
+ memcpy(table[0], &sa, sizeof(struct arglist));
+ }
+
+ /* redo list links */
+ for(i = 1; i < n; i++)
+ table[i-1]->next = table[i];
+ table[n-1]->next = NULL;
+
+ efree(&table);
+}
int
arglist_to_html(hosts, filename)
@@ -245,8 +298,10 @@
perror("fopen ");
return(-1);
}
+ sort_arglist(hosts);
+
/* Print the Style Sheet Opts and Report Summary */
summary_to_file(file, hosts);
h = hosts;