diff options
author | Robert Gustafsson <robg@student.chalmers.se> | 2017-09-28 14:25:01 +0200 |
---|---|---|
committer | Robert Gustafsson <robg@student.chalmers.se> | 2017-09-28 14:25:01 +0200 |
commit | 733ad771621e6a43866e9686481609ed9ce6f860 (patch) | |
tree | 8bdab7c7a6955e3762856f36bbe7d1b3709f6dff /broccoli/broevent.c | |
parent | 03bb5c1c6ddf0f6ea9ef3381769cc41969fc2a5d (diff) | |
download | midbro-733ad771621e6a43866e9686481609ed9ce6f860.tar.gz midbro-733ad771621e6a43866e9686481609ed9ce6f860.tar.bz2 |
Some renaming
Diffstat (limited to 'broccoli/broevent.c')
-rw-r--r-- | broccoli/broevent.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/broccoli/broevent.c b/broccoli/broevent.c new file mode 100644 index 0000000..a2b7a28 --- /dev/null +++ b/broccoli/broevent.c @@ -0,0 +1,71 @@ +#ifdef BROCCOLI +#include <broccoli.h> +#endif +#include "includes/fifoqueue.h" + +char *host_default = "127.0.0.1"; +char *port_default = "47760"; + + static void +bro_response(BroConn *conn, void *data, uint64* registers, uint64* uid) +{ + printf("Received value %"PRIu64" from uid=%"PRIu64"\n",*registers,*uid); + + conn = NULL; + data = NULL; +} + + void +bro_event_listener() +{ + + int fd = -1; + BroConn *bc = NULL; + bro_init(NULL); + char hostname[512]; + + snprintf(hostname, 512, "%s:%s", host_default, port_default); + if (! (bc = bro_conn_new_str(hostname, BRO_CFLAG_RECONNECT | BRO_CFLAG_ALWAYS_QUEUE))) + { + printf("Could not get Bro connection handle.\n"); + exit(-1); + } + bro_debug_calltrace = 0; + bro_debug_messages = 0; + + bro_event_registry_add(bc, "response",(BroEventFunc) bro_response, NULL); + + if (! bro_conn_connect(bc)) + { + printf("Could not connect to Bro at %s:%s.\n", host_default, + port_default); + exit(-1); + } + + fd =bro_conn_get_fd(bc); + fd_set rfds; + setbuf(stdout,NULL); + + while(true) + { + FD_ZERO(&rfds); + FD_SET(fd,&rfds); + if(select(fd+1,&rfds,NULL,NULL,NULL) == -1){ + perror("select()"); + break; + } + + bro_conn_process_input(bc); + } + + bro_conn_delete(bc); +} + + int +main(int argc, char **argv) +{ + Fifo_q * q = init_queue(5); + + free(q); + return 0; +} |