From c3f7c26011f019140d2642a068a1d7213035a1b0 Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Wed, 2 Oct 2019 17:13:38 +0200 Subject: [PATCH] chg: [pibs] fixed segfault in callback --- bin/pibs-BGP-Ranking.c | 34 ++++++++++++++++++++++++++++++++-- bin/synseen.c | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/bin/pibs-BGP-Ranking.c b/bin/pibs-BGP-Ranking.c index 2a2be19..df0a51f 100644 --- a/bin/pibs-BGP-Ranking.c +++ b/bin/pibs-BGP-Ranking.c @@ -22,6 +22,7 @@ #define __USE_XOPEN #include #include "pibs.h" +#include void usage(void) { @@ -69,13 +70,24 @@ struct ip* ipv4, struct tcphdr* tcp) } } +gint cmp_ips(gconstpointer a, gconstpointer b) +{ + uint32_t* x; + uint32_t* y; + x = (uint32_t*)a; + y = (uint32_t*)b; + return *x<*y; +} + int main(int argc, char* argv[]) { pibs_t* pibs; int opt; - - + GTree *ip_tree; pibs = init(); + uint32_t *y; + ip_tree = NULL; + while ((opt = getopt(argc, argv, "hr:d:")) != -1) { printf("%d\n", opt); switch (opt) { @@ -93,6 +105,24 @@ int main(int argc, char* argv[]) } } + //sorted array insert operations -> o(n) not good if we have a lot of inserts + //Problem: memalloc per each ip address + //Problem: duplicates are added + + // Gtree insert IP value several times + + y = calloc(1,sizeof(uint32_t)); + *y = 34; +// ip_list = g_list_insert_sorted_with_data (ip_list,y,&cmp_ips,NULL); +// y = calloc(1,sizeof(uint32_t)); +// *y = 34; +// ip_list = g_list_insert_sorted_with_data (ip_list,y,&cmp_ips,NULL); +// y = calloc(1,sizeof(uint32_t)); +// *y = 99; +// ip_list = g_list_insert_sorted_with_data (ip_list,y,&cmp_ips,NULL); + + + return EXIT_SUCCESS; //Set call back function pibs->synseen_callback = &frame_to_bgpr; diff --git a/bin/synseen.c b/bin/synseen.c index 1c38b13..7c03aa4 100644 --- a/bin/synseen.c +++ b/bin/synseen.c @@ -177,7 +177,7 @@ void synseen_process_frame(pibs_t *pibs, wtap *wth, uint8_t* eth, } if (pibs->synseen_callback) { synseen_callback = pibs->synseen_callback; - synseen_callback(pibs, wth, eth, ip, tcp); + synseen_callback(pibs, wth, eth, ipv4, tcp); } }