Skip to content

Commit c3f7c26

Browse files
committed
chg: [pibs] fixed segfault in callback
1 parent 5b2ddf2 commit c3f7c26

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

bin/pibs-BGP-Ranking.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define __USE_XOPEN
2323
#include <time.h>
2424
#include "pibs.h"
25+
#include <gmodule.h>
2526

2627
void usage(void)
2728
{
@@ -69,13 +70,24 @@ struct ip* ipv4, struct tcphdr* tcp)
6970
}
7071
}
7172

73+
gint cmp_ips(gconstpointer a, gconstpointer b)
74+
{
75+
uint32_t* x;
76+
uint32_t* y;
77+
x = (uint32_t*)a;
78+
y = (uint32_t*)b;
79+
return *x<*y;
80+
}
81+
7282
int main(int argc, char* argv[])
7383
{
7484
pibs_t* pibs;
7585
int opt;
76-
77-
86+
GTree *ip_tree;
7887
pibs = init();
88+
uint32_t *y;
89+
ip_tree = NULL;
90+
7991
while ((opt = getopt(argc, argv, "hr:d:")) != -1) {
8092
printf("%d\n", opt);
8193
switch (opt) {
@@ -93,6 +105,24 @@ int main(int argc, char* argv[])
93105
}
94106
}
95107

108+
//sorted array insert operations -> o(n) not good if we have a lot of inserts
109+
//Problem: memalloc per each ip address
110+
//Problem: duplicates are added
111+
112+
// Gtree insert IP value several times
113+
114+
y = calloc(1,sizeof(uint32_t));
115+
*y = 34;
116+
// ip_list = g_list_insert_sorted_with_data (ip_list,y,&cmp_ips,NULL);
117+
// y = calloc(1,sizeof(uint32_t));
118+
// *y = 34;
119+
// ip_list = g_list_insert_sorted_with_data (ip_list,y,&cmp_ips,NULL);
120+
// y = calloc(1,sizeof(uint32_t));
121+
// *y = 99;
122+
// ip_list = g_list_insert_sorted_with_data (ip_list,y,&cmp_ips,NULL);
123+
124+
125+
return EXIT_SUCCESS;
96126
//Set call back function
97127
pibs->synseen_callback = &frame_to_bgpr;
98128

bin/synseen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void synseen_process_frame(pibs_t *pibs, wtap *wth, uint8_t* eth,
177177
}
178178
if (pibs->synseen_callback) {
179179
synseen_callback = pibs->synseen_callback;
180-
synseen_callback(pibs, wth, eth, ip, tcp);
180+
synseen_callback(pibs, wth, eth, ipv4, tcp);
181181
}
182182
}
183183

0 commit comments

Comments
 (0)