minimalistic checks for config

pull/23/head
Gerard Wagener 2018-11-27 22:37:44 +01:00
parent b7c5b8d5bb
commit 5d0c8e4f7f
2 changed files with 34 additions and 1 deletions

View File

@ -10,6 +10,35 @@
#include <errno.h>
#include "d4.h"
//
int d4_check_config(d4_t* d4)
{
// TODO implement other sources, file, fifo, unix_socket ...
if (strlen(d4->conf[SOURCE]) > strlen(STDIN)) {
if (!strncmp(d4->conf[SOURCE],STDIN, strlen(STDIN))) {
d4->source.fd = STDIN_FILENO;
}
}
//TODO implement other destinations file, fifo unix_socket ...
if (strlen(d4->conf[DESTINATION]) > strlen(STDOUT)) {
if (!strncmp(d4->conf[DESTINATION],STDOUT, strlen(STDOUT))) {
d4->destination.fd = STDOUT_FILENO;
}
}
d4->snaplen = atoi(d4->conf[SNAPLEN]);
if ((d4->snaplen < 0) || (d4->snaplen > MAXSNAPLEN)) {
d4->snaplen = 0;
}
printf("TEST snaplen %d stdin %d stdout %d\n", d4->snaplen, STDIN_FILENO, STDOUT_FILENO);
//FIXME Check other parameters
if (( d4->destination.fd > 0 ) && ( d4->snaplen >0 )) {
return 1;
}
return -1;
}
//Returns -1 on error, 0 otherwise
int d4_load_config(d4_t* d4)
{
@ -30,7 +59,7 @@ int d4_load_config(d4_t* d4)
}
}
}
return -1;
return d4_check_config(d4);
}
void usage(void)

View File

@ -6,6 +6,10 @@
#define SZCONFVALUE 1024
#define SZERRVALUE 1024
#define STDIN "stdin"
#define STDOUT "stdout"
#define MAXSNAPLEN 65535
#define INSERT_ERROR(...) do { \
if (d4->err_idx < NERRORS) \
snprintf(d4->errors[d4->err_idx],SZERRVALUE,__VA_ARGS__); \