From 985496222ae8787cdba13b4bd31103dce8a34203 Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Thu, 11 Apr 2019 08:20:48 +0200 Subject: [PATCH] chg: [pibs] Split up inititalization process --- bin/pibs.c | 25 +++---------------------- bin/pibs.h | 2 +- bin/synseen.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/bin/pibs.c b/bin/pibs.c index c146b4e..72b7b29 100644 --- a/bin/pibs.c +++ b/bin/pibs.c @@ -92,33 +92,14 @@ pibs_t* init(void) wtap_init(FALSE); pibs=calloc(sizeof(pibs_t),1); + //TODO error handling //TODO check if size is correct - pibs->data_size = sizeof(pibs_header_t) + NBINSCALE * NBINS * SZBIN * NBINITEMS * sizeof(item_t); - pibs->data = calloc(pibs->data_size,1); pibs->filename = calloc(FILENAME_MAX,1); pibs->uuid = calloc(SZUUID,1); pibs->key = calloc(SZKEY,1); pibs->server = calloc(SZSERVER,1); - printf("#Internal look up structure size in bytes: %ld\n", pibs->data_size); - // Build header - pibs->data[0]='P'; - pibs->data[1] = 'I'; - pibs->data[2] = 'B'; - pibs->data[3] = 'S'; - pibs->data[4] = 1; //version 1 - pibs->next_block = sizeof(pibs_header_t); - pibs->bin_offset = pibs->next_block; - printf("#data address is %p\n",pibs->data); - pibs->bin_table = (uint32_t*)(pibs->data+pibs->bin_offset); - printf("#bin_table address is %p\n", pibs->bin_table); - // Create bins - pibs->next_block+=SZBIN * NBINS; - printf("#next block %d\n", pibs->next_block); - pibs->items = (item_t*)(pibs->data+pibs->next_block); - pibs->next_item = 0; - printf("#items are address %p\n", pibs->items); - pibs->max_item = NBINS * NBINITEMS; - printf("#max_item: %d\n", pibs->max_item); + // Initialize the various processors + synseen_init(pibs); return pibs; } diff --git a/bin/pibs.h b/bin/pibs.h index b6ffd87..4129c45 100644 --- a/bin/pibs.h +++ b/bin/pibs.h @@ -125,5 +125,5 @@ void pibs_dump_stats(pibs_t* pibs); void process_redis_list(pibs_t* pibs); void synseen_process_frame(pibs_t *pibs, wtap *wth, uint8_t* eth, struct ip* ipv4, struct tcphdr* tcp); - +int synseen_init(pibs_t* pibs); #endif diff --git a/bin/synseen.c b/bin/synseen.c index 838dc43..c8340fa 100644 --- a/bin/synseen.c +++ b/bin/synseen.c @@ -175,3 +175,31 @@ void synseen_process_frame(pibs_t *pibs, wtap *wth, uint8_t* eth, pcap_dump((u_char*)pibs->dumper, &pchdr, eth); } } + +int synseen_init(pibs_t* pibs) +{ + pibs->data_size = sizeof(pibs_header_t) + NBINSCALE * NBINS * SZBIN * NBINITEMS * sizeof(item_t); + pibs->data = calloc(pibs->data_size,1); + printf("#Internal look up structure size in bytes: %ld\n", pibs->data_size); + // Build header + pibs->data[0]='P'; + pibs->data[1] = 'I'; + pibs->data[2] = 'B'; + pibs->data[3] = 'S'; + pibs->data[4] = 1; //version 1 + + pibs->next_block = sizeof(pibs_header_t); + pibs->bin_offset = pibs->next_block; + printf("#data address is %p\n",pibs->data); + pibs->bin_table = (uint32_t*)(pibs->data+pibs->bin_offset); + printf("#bin_table address is %p\n", pibs->bin_table); + // Create bins + pibs->next_block+=SZBIN * NBINS; + printf("#next block %d\n", pibs->next_block); + pibs->items = (item_t*)(pibs->data+pibs->next_block); + pibs->next_item = 0; + printf("#items are address %p\n", pibs->items); + pibs->max_item = NBINS * NBINITEMS; + printf("#max_item: %d\n", pibs->max_item); + return 1; +}