mirror of https://github.com/D4-project/d4-core
started to write a test d4 client
parent
bf87982cb4
commit
1fdcbdf1a8
|
@ -0,0 +1,2 @@
|
|||
d4: d4.c
|
||||
gcc -Wall -o d4 d4.c
|
|
@ -0,0 +1,62 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue