From: Mazet Laurent Date: Thu, 27 Mar 2025 20:06:06 +0000 (+0100) Subject: initial version of validator X-Git-Tag: v1.0~86 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=0d86ea637c57fd55a040d84827dcf5abf41aae4b;p=morep.git initial version of validator --- diff --git a/makefile b/makefile index 2431ad2..e63ea54 100644 --- a/makefile +++ b/makefile @@ -39,6 +39,7 @@ endif ALLEXE = ALLEXE += morep_test +ALLEXE += morep_valid SHELL = bash diff --git a/morep_valid.c b/morep_valid.c new file mode 100644 index 0000000..92e3746 --- /dev/null +++ b/morep_valid.c @@ -0,0 +1,201 @@ +/* + File name : morep_valid.c + Projet : MERLIN + Date of creation : 2025/03/28 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : Raw Ethernet packet valid program for MOREP library + + History : + - initial version +*/ + +/* depend: */ +/* cflags: */ +/* linker: morep.o */ +/* winlnk: morep.o */ + +#include +#include +#include +#include +#include + +#include "morep.h" +#include "verbose.h" + +char *progname = NULL; + +int stop = 0; + +DECLARE_VERBOSE_LEVEL (morep, INFO); + +#define BUFMAX 4096 + +void sig_handler (int sig) +{ + switch (sig) { + case SIGINT: + //stop = 1; + exit (0); + break; + case SIGTERM: + exit (0); + break; + } +} + +typedef struct { + int morep; + int mode; + char *etype; +} comm_t; + +#define MAXCOMMS 32 + +int main (int argc, char **argv) +{ + char *filename = NULL; + char *url = NULL; + int mode = -1; + int nbcomms = 0; + comm_t comm_list[MAXCOMMS] = {0}; + + /* get basename */ + char *pt = progname = argv[0]; + while (*pt) { + if ((*pt == '/') || (*pt == '\\')) { + progname = pt + 1; + } + pt++; + } + + /* process argument */ + while (argc-- > 1) { + char *arg = *(++argv); + if (arg[0] != '-') { + filename = arg; + continue; + } + char c = arg[1]; + switch (c) { + case 'r': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (morep, ERROR, PRINTF ("%s: receiver url not specified\n", progname)); + return 1; + } + url = arg; + mode = 1; + break; + case 't': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (morep, ERROR, PRINTF ("%s: transmitter url not specified\n", progname)); + return 1; + } + url = arg; + mode = 1; + break; + case 'v': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (morep, ERROR, PRINTF ("%s: verbose level not specified\n", progname)); + return 1; + } + CHANGE_VERBOSE_LEVEL (morep, atoi (arg)); + break; + case 'h': + default: + printf ("usage: %s [-h] [-r url] [-t url] [-v level]\n", progname); + return (c != 'h'); + } + + /* init communication channel */ + if (mode != -1) { + if (nbcomms < MAXCOMMS) { + int morep = MOREP_Connect (url); + if (morep >= 0) { + (comm_list + nbcomms)->morep = morep; + (comm_list + nbcomms)->mode = mode; + (comm_list + nbcomms)->etype = strrchr (url, '/') + 1; + nbcomms++; + } else { + VERBOSE (morep, ERROR, PRINTF ("can't connect on url '%s'\n", url)); + return -1; + } + } else { + VERBOSE (morep, ERROR, PRINTF ("no more communication channel avaliable (%d)\n", nbcomms)); + return -1; + } + mode = -1; + } + } + + /* checks */ + if (nbcomms == 0) { + VERBOSE (morep, ERROR, PRINTF ("no communication channel\n")); + return -1; + } + + /* read file */ + FILE *fid = stdin; + if (filename != NULL) { + fid = fopen (filename, "r"); + if (fid == NULL) { + VERBOSE (morep, ERROR, PRINTF ("can't open file '%s' for reading\n", filename)); + return -1; + } + } + + /* signals */ + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + + /* main loop */ + int rc = 0; + while (!feof (fid)) { + + /* read line */ + char line[BUFMAX] = {0}; + int i = 0; + do { + fread (line + i, 1, 1, fid); + if ((line[i] == '\n') || (line[i] == '\r')) { + line[i] = 0; + } + } while ((line[i] != 0) && (++i < (int)sizeof (line) - 1)); + + /* clean line */ + char *pt = line; + while ((*pt == ' ') || (*pt == '\t')) { + if (*pt == '\0') { + break; + } + pt++; + } + if ((*pt == '\0') || (*pt == '#')) { + continue; + } + + /* analyse line */ + + + } + + /* cleaning */ + if (fid != stdin) { + fclose (fid); + } + while (nbcomms) { + MOREP_Close (--nbcomms); + } + + return rc; +} + +/* test: morep_valid.exe -h | grep usage */ + +/* vim: set ts=4 sw=4 et: */ diff --git a/script.eth b/script.eth new file mode 100644 index 0000000..e13499f --- /dev/null +++ b/script.eth @@ -0,0 +1,10 @@ +# Test script + +TX[0808] MSG=42 PAYLOAD="Hello world" +RX[0808] MSG=43 PAYLOAD="Bye" + +TX[0808] MSG=24 PAYLOAD=42796520776f726c64 +RX[0808] MSG=25 PAYLOAD=48656c6c6f + +TX[0808] MSG=10 PAYLOAD=@makefile +RX[0808] MSG=11 PAYLOAD="OK"