From 1fdcbdf1a8ff5c1af2a252262ca8380c44a8bfec Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Tue, 27 Nov 2018 12:47:18 +0100 Subject: [PATCH] started to write a test d4 client --- client/Makefile | 2 ++ client/d4.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ client/d4.h | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 client/Makefile create mode 100644 client/d4.c create mode 100644 client/d4.h diff --git a/client/Makefile b/client/Makefile new file mode 100644 index 0000000..c60d46c --- /dev/null +++ b/client/Makefile @@ -0,0 +1,2 @@ +d4: d4.c + gcc -Wall -o d4 d4.c diff --git a/client/d4.c b/client/d4.c new file mode 100644 index 0000000..55546d5 --- /dev/null +++ b/client/d4.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include + +#include "d4.h" +//Returns -1 on error, 0 otherwise +int d4_load_config(d4_t* d4) +{ + return -1; +} + +void usage(void) +{ + printf("d4 client help\n"); +} + +d4_t* d4_init(char* confdir) +{ + d4_t* out; + out = calloc(1,sizeof(d4_t)); + if (out) { + strncpy(out->confdir, confdir, FILENAME_MAX); + } + // Do other inititalization stuff here + return out; +} + +int main (int argc, char* argv[]) +{ + int opt; + char* confdir; + d4_t* d4; + + confdir=calloc(1,FILENAME_MAX); + if (!confdir) + return EXIT_FAILURE; + + while ((opt = getopt(argc, argv, "c:h")) != -1) { + switch (opt) { + case 'h': + usage(); + return EXIT_SUCCESS; + case 'c': + strncpy(confdir, optarg, FILENAME_MAX); + break; + default: + fprintf(stderr,"An invalid command line argument was specified\n"); + } + } + if (!confdir[0]){ + fprintf(stderr,"A config directory must be specified\n"); + return EXIT_FAILURE; + } + + + d4_init(confdir); + free(confdir); + d4_load_config(d4); + return EXIT_SUCCESS; +} diff --git a/client/d4.h b/client/d4.h new file mode 100644 index 0000000..f223e44 --- /dev/null +++ b/client/d4.h @@ -0,0 +1,52 @@ +#ifndef D4_H +#define D4_H + +typedef struct d4_header_s { + uint8_t version; + uint8_t type; + uint8_t uuid[128]; + uint64_t timestamp; + uint8_t hmac[256]; + uint32_t size; +} d4_header_t; + +// Information about the source +typedef struct source_s { + int fd; +} source_t; + +//Information about the destination +//Write data to stdout, fifo, shared memory segment +typedef struct destination_s { + int fd; +} destination_t; + +typedef struct d4_s { + source_t source; + destination_t destination; + char confdir[FILENAME_MAX]; + int snaplen; + int caplen; + int d4_error; + int errno_copy; +} d4_t; + + + +/* D4 configuration is a directory structure shown below (like proc filesytem) + * d4-conf/snaplen + * d4-conf/caplen + * d4-conf/uuid + * d4-conf/collector + */ + +const char* d4params[] = {"uuid", "snaplen", "caplen", "timestamp", "collector"}; +#define ND4PARAMS 5 + +#define UUID 0 +#define SNAPLEN 1 +#define CAPLEN 2 +#define TIMESTAMP 3 +#define COLLECTOR 4 + +#endif