diff options
author | Robert Gustafsson <robg@student.chalmers.se> | 2017-09-26 09:10:55 +0200 |
---|---|---|
committer | Robert Gustafsson <robg@student.chalmers.se> | 2017-09-26 09:10:55 +0200 |
commit | 24145fa0d3f33141ac074d022891b07e249f4582 (patch) | |
tree | a1ee8889e3b42cae4d7e3f27337493868f162efb | |
parent | 46f518825c4e934b950c1ce0c9936fd106798408 (diff) | |
download | midbro-24145fa0d3f33141ac074d022891b07e249f4582.tar.gz midbro-24145fa0d3f33141ac074d022891b07e249f4582.tar.bz2 |
Add first test of broccoli
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | pasad.c | 64 | ||||
-rw-r--r-- | pasad_bro.bro | 26 |
3 files changed, 104 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c8484f9 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +CC=gcc +CFLAGS = -c -Wall -I/usr/local/include -I/usr/local/include -DBROCCOLI +LDFLAGS = -L/usr/local/lib -lbroccoli + +all: pasad + +pasad: pasad.o + $(CC) pasad.o -o pasad $(LDFLAGS) + +pasad.o: pasad.c + $(CC) $(CFLAGS) pasad.c + +clean: + rm *.o pasad @@ -0,0 +1,64 @@ +#ifdef BROCCOLI +#include <broccoli.h> +#endif + +char *host_default = "127.0.0.1"; +char *port_default = "47760"; + + static void +bro_pasad_response(BroConn *conn, void *data, uint64* registers, uint64* uid) +{ + printf("Received value %"PRIu64" from uid=%"PRIu64"\n",*registers,*uid); + + conn = NULL; + data = NULL; +} + + int +main(int argc, char **argv) +{ + BroConn *bc; + char hostname[512]; + int fd = -1; + + bro_init(NULL); + + bro_debug_calltrace = 0; + bro_debug_messages = 0; + + 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_event_registry_add(bc, "response",(BroEventFunc) bro_pasad_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(1) + { + 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); + + return 0; +} diff --git a/pasad_bro.bro b/pasad_bro.bro new file mode 100644 index 0000000..c324856 --- /dev/null +++ b/pasad_bro.bro @@ -0,0 +1,26 @@ +@load frameworks/communication/listen +module Pasad; + +redef Communication::listen_port = 47760/tcp; + +redef Communication::listen_ssl = F; + +global response: event(register: count, uid: count); + +redef Communication::nodes += { + ["pasad"] = [$host = 127.0.0.1, $events = /pasad/, $connect=F, $ssl=F] +}; + +event modbus_read_holding_registers_request(c: connection, headers: ModbusHeaders, start_adress: count, quantity: count) + +{ + print fmt("Request: %d", quantity); +} + +event modbus_read_holding_registers_response(c: connection, headers: ModbusHeaders, registers: ModbusRegisters) + +{ + print fmt("Response: %d", registers[0]); + event response(registers[0],headers$uid); +} + |