From 8e5b5cf46b710950cb8b3b0c763de82766a3ed4b Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Tue, 27 Nov 2018 23:14:23 +0100 Subject: [PATCH] rough and incomplete working processing program --- client/d4.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- client/d4.h | 2 ++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/client/d4.c b/client/d4.c index 9df584b..ab4afcb 100644 --- a/client/d4.c +++ b/client/d4.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "d4.h" // @@ -83,6 +84,46 @@ d4_t* d4_init(char* confdir) return out; } + +//FIXME split in prepare and update. Do not copy uuid each time +void d4_update_header(d4_t* d4, ssize_t nread) { + bzero(&d4->header,sizeof(d4_update_header)); + //TODO Check format + d4->header.version = atoi(d4->conf[VERSION]); + //TODO set type + d4->header.timestamp = time(NULL); + //FIXME length handling + strncpy((char*)&(d4->header.uuid), d4->conf[UUID], SZUUID); + //TODO hmac + d4->header.size=nread; +} + +//Core routine. Transfers data from the source to the destinations +void d4_transfert(d4_t* d4) +{ + ssize_t nread; + char* buf; + + buf = calloc(1, d4->snaplen); + //TODO error handling -> insert error message + if (!buf) + return; + + while ( 1 ) { + //In case of errors see block of 0 bytes + bzero(buf, d4->snaplen); + nread = read(d4->source.fd, buf, d4->snaplen); + if ( nread > 0 ) { + d4_update_header(d4, nread); + write(d4->destination.fd, &d4->header, sizeof(d4->header)); + write(d4->destination.fd,buf,nread); + } else{ + //FIXME no data available, sleep, abort, retry + break; + } + } +} + int main (int argc, char* argv[]) { int opt; @@ -113,9 +154,9 @@ int main (int argc, char* argv[]) d4 = d4_init(confdir); free(confdir); - d4_load_config(d4); - - + if (d4_load_config(d4)) { + d4_transfert(d4); + } return EXIT_SUCCESS; } diff --git a/client/d4.h b/client/d4.h index cc33295..71a7e58 100644 --- a/client/d4.h +++ b/client/d4.h @@ -9,6 +9,7 @@ #define STDIN "stdin" #define STDOUT "stdout" #define MAXSNAPLEN 65535 +#define SZUUID 128 #define INSERT_ERROR(...) do { \ if (d4->err_idx < NERRORS) \ @@ -47,6 +48,7 @@ typedef struct d4_s { char conf[ND4PARAMS][SZCONFVALUE]; char errors[NERRORS][SZERRVALUE]; int err_idx; + d4_header_t header; } d4_t;