Not a clue then. You'll have to instrument the comparison function to show
the actual comparisons. I'd suggest adding the {}s and traceEvent() calls
so it reads as shown below. Then look at the log messages:
May 19 11:53:49 tigger ntop[24097]: TEMP: cmpHostsFctn(0x853cb1c,
0x853cb20) col 4 a_ 19906 b_ 0 rc=-1
May 19 11:53:49 tigger ntop[24097]: TEMP: cmpHostsFctn(0x853cb18,
0x853cb1c) col 4 a_ 14661 b_ 19906 rc=1
May 19 11:53:49 tigger ntop[24097]: TEMP: cmpHostsFctn(0x853cb18,
0x853cb20) col 4 a_ 14661 b_ 0 rc=-1
Those make sense... 19906 vs. 0 returns -1 (b smaller)
14661 vs 19906 returns 1 (b larger)
14661 vs 0 returns -1 (b smaller)
which is enough for a quick sort.
What we're looking for is junk, such as NULL values (0) on the parameters,
etc. This compare function hasn't been hardened against that.
-----Burton
int cmpHostsFctn(const void *_a, const void *_b) {
struct hostTraffic **a = (struct hostTraffic **)_a;
struct hostTraffic **b = (struct hostTraffic **)_b;
Counter a_=0, b_=0;
switch(myGlobals.columnSort) {
case 2: /* IP Address */
if(isFcHost((*a)) && isFcHost((*b))) {
traceEvent(CONST_TRACE_NOISY, "TEMP: cmpHostsFctn(0x%x, 0x%x) col %d
memcmp()=%d",
_a, _b, myGlobals.columnSort, memcmp(((u_int8_t *)&(*a)->hostFcAddress),
((u_int8_t *)&(*b)->hostFcAddress),
LEN_FC_ADDRESS));
return(memcmp(((u_int8_t *)&(*a)->hostFcAddress),
((u_int8_t *)&(*b)->hostFcAddress),
LEN_FC_ADDRESS));
}
else {
traceEvent(CONST_TRACE_NOISY, "TEMP: cmpHostsFctn(0x%x, 0x%x) col %d
addrcmp()=%d",
_a, _b, myGlobals.columnSort, addrcmp(&(*a)->hostIpAddress,
&(*b)->hostIpAddress));
return(addrcmp(&(*a)->hostIpAddress, &(*b)->hostIpAddress));
}
break;
case 3: /* Data Sent */
if (isFcHost((*a)) && isFcHost((*b))) {
a_ = (*a)->fcBytesSent.value;
b_ = (*b)->fcBytesSent.value;
}
else {
switch(myGlobals.sortFilter) {
case FLAG_REMOTE_TO_LOCAL_ACCOUNTING:
a_ = (*a)->bytesSentLoc.value;
b_ = (*b)->bytesSentLoc.value;
break;
case FLAG_LOCAL_TO_REMOTE_ACCOUNTING:
a_ = (*a)->bytesSentRem.value;
b_ = (*b)->bytesSentRem.value;
break;
case FLAG_LOCAL_TO_LOCAL_ACCOUNTING:
a_ = (*a)->bytesSentLoc.value;
b_ = (*b)->bytesSentLoc.value;
break;
}
}
traceEvent(CONST_TRACE_NOISY, "TEMP: cmpHostsFctn(0x%x, 0x%x) col %d a_ %llu
b_ %llu rc=%d",
_a, _b, myGlobals.columnSort, a_, b_, (a_ < b_) ? 1 : (a_ > b_) ? -1 : 0);
if(a_ < b_) return(1); else if (a_ > b_) return(-1); else return(0);
break;
case 4: /* Data Rcvd */
if(isFcHost((*a)) && isFcHost((*b))) {
a_ = (*a)->fcBytesRcvd.value;
b_ = (*b)->fcBytesRcvd.value;
}
else {
switch(myGlobals.sortFilter) {
case FLAG_REMOTE_TO_LOCAL_ACCOUNTING:
a_ = (*a)->bytesRcvdLoc.value;
b_ = (*b)->bytesRcvdLoc.value;
break;
case FLAG_LOCAL_TO_REMOTE_ACCOUNTING:
a_ = (*a)->bytesRcvdFromRem.value;
b_ = (*b)->bytesRcvdFromRem.value;
break;
case FLAG_LOCAL_TO_LOCAL_ACCOUNTING:
a_ = (*a)->bytesRcvdLoc.value;
b_ = (*b)->bytesRcvdLoc.value;
break;
}
}
traceEvent(CONST_TRACE_NOISY, "TEMP: cmpHostsFctn(0x%x, 0x%x) col %d a_ %llu
b_ %llu rc=%d",
_a, _b, myGlobals.columnSort, a_, b_, (a_ < b_) ? 1 : (a_ > b_) ? -1 : 0);
if(a_ < b_) return(1); else if (a_ > b_) return(-1); else return(0);
break;
case 5: /* VSAN */
if(isFcHost((*a)) && isFcHost((*b))) {
a_ = (*a)->vsanId, b_ = (*b)->vsanId;
return((a_ < b_) ? -1 : (a_ > b_) ? 1 : 0);
}
break;
default: /* Host Name */
traceEvent(CONST_TRACE_NOISY, "TEMP: cmpHostsFctn(0x%x, 0x%x) col %d
cmpFctnResolvedName()",
_a, _b, myGlobals.columnSort);
return(cmpFctnResolvedName(a, b));
}
return(-1);
}
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Ralf
> Stodt
> Sent: Wednesday, May 19, 2004 10:50 AM
> To: [EMAIL PROTECTED]
> Subject: [Ntop] Re: Re: sorting problems (long post)
>
>
> Burton M. Strauss III wrote:
> > The code - in cmpHostsFctn() in reportUtils.c - is pretty simple,
> > unless - is there ANY FibreChannel traffic on this network?
>
> None FC-traffic as far as i know ...
>
> rs
>
>
>
>
> _______________________________________________
> Ntop mailing list
> [EMAIL PROTECTED]
> http://listgateway.unipi.it/mailman/listinfo/ntop
_______________________________________________
Ntop mailing list
[EMAIL PROTECTED]
http://listgateway.unipi.it/mailman/listinfo/ntop