Interesting idea but fundamentally flawed. If you're trying to figure out what a string represents as a name to be able to decide how to sort it, you're in for a lot of trouble.
1.2.3 is a legal (albeit unusual) IP address - it's equivalent to 0.1.2.3 - and possibly other things. The special casing to catch everything will kill you. The right thing to do is to add another flag that tells what type of item is stored in the symHostIpAddress field. Then you KNOW how to sort it. I've got it partly working - well, more than partly - needs to be adjusted for some of the odder items and newer stuff FC, iSCSI. But it essentially works. Why it works is that the sort has access to the full HostTraffic structure, so all of the underlying fields are available (e.g. IPv4 and IPv6 addresses as numbers, etc.) Here's a sample output -- resolved names sort first (alpha), then IPs (numeric) then other kinds of 'names'... Host 3c16950-closet 3c16985-cart e4-7.columbia1-sr1.bbnplanet.net pooh.burtonstrauss.us roo.burtonstrauss.us vnsc-pri.sys.gtei.net zebra.burtonstrauss.us 4.2.3.1 12.244.69.22 12.244.114.1 12.244.114.2 12.244.114.3 12.244.114.4 -----Burton > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Arnt > Gulbrandsen > Sent: Friday, February 20, 2004 6:32 AM > To: [EMAIL PROTECTED] > Subject: Re: [Ntop] Sorting <snip /> > So, I suggest using a comparison wrapper such as compare() below rather > than calling strcasecmp() directly. When qsort() is used with this > compare function, the sort result should be rather good: > > 1) strcasecmp() is never called with an unspecified argument > 2) there is a stable, easily predictable sort order > 3) all zero-valued items are first > 4) IPv4 addresses are sorted numerically correctly > 5) IPv4 addresses are listed between the zero-valued items and the > resolved addresses > > Regrettably, it doesn't handle IPv6 addresses. > > (The idea behind the " 4 " prefix is that since host names contain no > spaces, the massaged IPv4 address is sorted before all host names. IPv6 > addresses should have a " 6 " prefix and thus be sorted between IPv4 > addresses and resolved host names.) <snip /> _______________________________________________ Ntop mailing list [EMAIL PROTECTED] http://listgateway.unipi.it/mailman/listinfo/ntop
