aboutsummaryrefslogtreecommitdiff
path: root/example/ndpiReader.c
diff options
context:
space:
mode:
authorVitaly Lavrov <vel21ripn@gmail.com>2017-09-29 12:46:27 +0300
committerVitaly Lavrov <vel21ripn@gmail.com>2017-09-29 12:46:27 +0300
commitb2f0558080d767ed0680c16b68aa35449aef91dc (patch)
tree89969412561b3ef7a9671734937aa42e67abc86f /example/ndpiReader.c
parent662ef2f65bc9b5864e6ac1b7080e43d3d576463f (diff)
A more predictable sorting of the flows list.
It is necessary for correct testing.
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r--example/ndpiReader.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index e527255fd..a8a767214 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -334,10 +334,22 @@ int cmpProto(const void *_a, const void *_b) {
}
int cmpFlows(const void *_a, const void *_b) {
- struct flow_info *a = (struct flow_info*)_a;
- struct flow_info *b = (struct flow_info*)_b;
-
- return((a->flow->src2dst_bytes + a->flow->dst2src_bytes) < (b->flow->src2dst_bytes + b->flow->dst2src_bytes) ? 1 : -1);
+ struct ndpi_flow_info *fa = ((struct flow_info*)_a)->flow;
+ struct ndpi_flow_info *fb = ((struct flow_info*)_b)->flow;
+ uint64_t a_size = fa->src2dst_bytes + fa->dst2src_bytes;
+ uint64_t b_size = fb->src2dst_bytes + fb->dst2src_bytes;
+ if(a_size != b_size)
+ return a_size < b_size ? 1 : -1;
+
+// copy from ndpi_workflow_node_cmp();
+
+ if(fa->ip_version < fb->ip_version ) return(-1); else { if(fa->ip_version > fb->ip_version ) return(1); }
+ if(fa->protocol < fb->protocol ) return(-1); else { if(fa->protocol > fb->protocol ) return(1); }
+ if(htonl(fa->src_ip) < htonl(fb->src_ip) ) return(-1); else { if(htonl(fa->src_ip) > htonl(fb->src_ip) ) return(1); }
+ if(htons(fa->src_port) < htons(fb->src_port)) return(-1); else { if(htons(fa->src_port) > htons(fb->src_port)) return(1); }
+ if(htonl(fa->dst_ip) < htonl(fb->dst_ip) ) return(-1); else { if(htonl(fa->dst_ip) > htonl(fb->dst_ip) ) return(1); }
+ if(htons(fa->dst_port) < htons(fb->dst_port)) return(-1); else { if(htons(fa->dst_port) > htons(fb->dst_port)) return(1); }
+ return(0);
}
void extcap_config() {