-# Messaging over raw Ethernet Packets communication library
-
-MDIR = $(shell pwd)
-
-PACKAGE = morep
-
-IFLAGS += -I. -I../src/debug -I../src/gpio
-OFLAGS = -O4 -minline-all-stringops -fsingle-precision-constant
-#OFLAGS += -msse -msse2
-CFLAGS += -Wall -W -Wextra -g $(OFLAGS) $(IFLAGS) -fpic
-LFLAGS += -g -L$(MDIR) -Wl,-rpath=$(MDIR)
-
-LIBDEP = $(wildcard *.ld)
-NAMES = $(LIBDEP:.ld=)
-DEBIAN = $(addprefix debian-,$(NAMES))
-PACKS = $(addprefix pack-,$(NAMES))
-LIBPRE = lib
-LIBEXT = so
-LIBFUL = $(shell cat $(wildcard *.ld) | sed 's/:.*//')
-LIBNIC = $(shell cat $(wildcard *.ld) | sed 's/\(\.$(LIBEXT)\.[0-9]*\)\..*:.*/\1/')
-LIBNAM = $(shell cat $(wildcard *.ld) | sed 's/\(\.$(LIBEXT)\)\..*:.*/\1/')
-LIBSTA = $(shell cat $(wildcard *.ld) | sed 's/\(\.$(LIBEXT)\)\..*:.*/.a/')
-
-TESTS += $(shell [ "$(wildcard test/*.c)" ] && grep -l '/\* *linker:' test/*.c | sed 's/\.c//g')
+# Default flags
+
+CC = gcc
+
+#INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
+INCLUDES =
+OFLAGS = -O4 -Os
+#OFLAGS = -O0
+#OFLAGS = -O4 -ffast-math -finline-functions
+#OFLAGS = -O4 -finline-functions
+#OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
+#OFLAGS += -minline-all-stringops -fsingle-precision-constant
+#OFLAGS += -malign-double
+CFLAGS += -W -Wall -Wextra -g
+#CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
+CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
+LDFLAGS += -g $(LDOPTS) $(OPTIONS)
+
+LDOPT = linker
+MV = mv
+ifneq (, $(findstring linux, $(MAKE_HOST)))
+# Linux
+else ifneq (, $(findstring mingw, $(MAKE_HOST)))
+# Windows MinGw
+CFLAGS += -DWIN32
+#LDLIBS += -lws2_32
+LDOPT = winlnk
+else ifneq (, $(findstring cygwin, $(MAKE_HOST)))
+CFLAGS += -DWIN32
+# Windows CygWin
+LDOPT = winlnk
+else ifneq (, $(findstring msdos, $(MAKE_HOST)))
+# MSDOS
+LDOPT = doslnk
+MV = move
+endif
-TARBALL = $(PACKAGE)_$(shell date +%F).tgz
+# Targets
-ALLDOC = $(wildcard *.3) $(wildcard $(addprefix README.,$(NAMES)))
-ALLHEA = $(wildcard *.h) $(wildcard test/*.h)
-ALLSRC = $(wildcard *.c) $(wildcard test/*.c)
-ALLDEP = $(ALLSRC:.c=.d) $(addprefix $(LIBPRE),$(LIBDEP:.ld=.d))
-ALLTST = $(subst /,_,$(TESTS))
+ALLEXE =
+ALLEXE += more_server
+ALLEXE += more_test
SHELL = bash
+#MAKE = mingw32-make
MAKEFLAGS += -s
-
-DEBPKG = ../debian-pkg
-
-# Install
-
-DOCS = $(wildcard $(addprefix README.,$(NAMES))) COPYING makefile
-INCS = $(wildcard *.h)
-LIBS = $(LIBFUL) $(LIBNIC) $(LIBNAM) $(LIBSTA)
-MANS = $(wildcard *.3)
-TESS = $(wildcard test/*.c) $(wildcard test/*.h) test/makefile
-
-ifeq ($(DESTDIR),)
-DESTDIR = /usr/local
-endif
-
-BINDIR = $(DESTDIR)/bin
-LIBDIR = $(DESTDIR)/lib
-INCDIR = $(DESTDIR)/include/thales
-DOCDIR = $(DESTDIR)/share/doc/$(PACKAGE)
-MANDIR = $(DESTDIR)/share/man/man3
-TESDIR = $(DESTDIR)/share/doc/$(PACKAGE)/test
-
-INSTBIN = $(addprefix $(BINDIR)/, $(EXECS))
-INSTDOC = $(addprefix $(DOCDIR)/, $(DOCS))
-INSTINC = $(addprefix $(INCDIR)/, $(INCS))
-INSTLIB = $(addprefix $(LIBDIR)/, $(LIBS))
-INSTMAN = $(addprefix $(MANDIR)/, $(MANS))
-INSTTES = $(addprefix $(DOCDIR)/, $(TESS))
-
-FILES = $(INSTBIN) $(INSTDOC) $(INSTINC) $(INSTLIB) $(INSTMAN) $(INSTTES)
+include $(wildcard .makefile)
# Functions
-TITLE = { tput colors 2>/dev/null | grep -qE '8|256' && echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t" || echo -en "$(strip $(1)):\t"; }
-INFO = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;34m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; }
-PASS = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;32m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; }
-WARN = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;33m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; }
-FAIL = { tput colors 2>/dev/null | grep -qE '8|256' && echo -e "\033[1;31m$(strip $(1))\033[0;0m" || echo -e "$(strip $(1))"; }
-
-_GET = awk '{sub(/\/\/.*/,"")} /\/\* *$(1):.*\*\// { sub(/^.*\/\* *$(1): */, ""); sub(/ *\*\/.*$$/, ""); print }' $(2)
-GET = $(shell $(call _GET,$(1),$(2)))
-# $(shell ./getcomments.pl -p='$(1):\s' -f='%' $(2))
-
-_VER = sed 's/.*\.$(LIBEXT)\.\([0-9.]*\):.*/\1/' $(1)
-VER = $(shell $(call _VER,$(1)))
-PVER = $(shell $(call _VER,$(subst pack-,,$(1).ld)))
+TITLE = echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t"
+PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m"
+WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m"
+FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m"
MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1)
-INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && { chmod a+rX,go-w -f $(2); true; }
+INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2)
+
+VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
-VALID = $(call TITLE, $(1)) && { $(2); } && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
+GETCOMMENTS = awk '/\/\*\s*$(1):/,/\*\// { sub(/.*\/\*\s*$(1):/, ""); sub (/\s*\*\/.*/, ""); print } /\/\/\s*$(1):/ {sub (/.*\/\/\s*$(1):/, ""); print }' $(2)
+#GETCOMMENTS = perl -- getcomments.pl -p='$(1):\s' -f='%' $(2)
## Generic rules
all: depends
- make $(LIBNAM) $(LIBNIC) $(LIBSTA) $(TESTS)
-
-archive:
- $(call VALID, "Archiving $(TARBALL)", hg archive $(PACKAGE) && tar cfz ../$(TARBALL) $(PACKAGE); rm -rf $(PACKAGE))
-
-depends: $(ALLDEP)
+ $(MAKE) $(ALLEXE:%=%.exe)
count:
- $(call TITLE, "Counting")
- echo
- wc $(ALLHEA) $(ALLSRC) makefile $(ALLDOC)
+ wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
clean:
$(call TITLE, "Cleaning")
touch clean
- rm -f $(wildcard *.[do] *.ho *~ test/*.[do] test/*.ho test/*~ web/*~ $(TESTS:=.log) $(TESTS:=.test)) clean
+ rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out _)
$(call PASS, SUCCESS)
-documentation: doxygen.conf $(wildcard *.[ch])
- $(call TITLE, "Publishing $@")
- doxygen $<; true
- $(call PASS, SUCCESS)
-
-gcov:
- make purge
- CFLAGS="-O0 -fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs" make
-
-headers: $(ALLHEA:.h=.ho)
+depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
-install: $(FILES)
+gcovs:
+ $(MAKE) $(addprefix gcov_,$(ALLEXE))
-$(INSTBIN):$(BINDIR)/%:%
- $(call VALID, "File [$@]", $(call INSTALL, $<, $@))
-
-$(INSTDOC):$(DOCDIR)/%:%
- $(call VALID, "Documentation [$@]", $(call INSTALL, $<, $@))
-
-$(INSTINC):$(INCDIR)/%:%
- $(call VALID, "Include [$@]", $(call INSTALL, $<, $@))
-
-$(INSTLIB):$(LIBDIR)/%:%
- $(call VALID, "Library [$@]", $(call INSTALL, $<, $@))
-
-$(INSTMAN):$(MANDIR)/%:%
- $(call VALID, "Manpage [$@]", $(call INSTALL, $<, $@))
-
-$(INSTTES):$(TESDIR)/%:test/%
- $(call VALID, "Test file [$@]", $(call INSTALL, $<, $@))
- $(call VALID, "Adapt test [$@]", sed -i 's/"..\/\(.*\)"/<snd\/\1>/;/depend:/ s/: .* /: /' $@)
+gprofs:
+ $(MAKE) $(addprefix gprof_,$(ALLEXE))
purge: clean
$(call TITLE, "Purging")
touch purge
- rm -rf $(TESTS) $(LIBFUL) $(LIBNIC) $(LIBNAM) $(LIBSTA) $(wildcard *.gcda *.gcno *.gcov test/*.gcda test/*.gcno test/*.gcov) documentation purge
+ rm -f purge $(ALLEXE:%=%.exe)
$(call PASS, SUCCESS)
-%.test: %.c makefile
- $(call VALID, "Extracting $@", $(call _GET,test, $<) | sed 's;{};${<:.c=};g' > $@)
-
-test_%: test/%.test test/%
- $(call WARN, "Testing ${@:test_=}");
- IFS=$$'\n'; \
- LOGFILE=${<:.test=.log}; \
- rm -f $$LOGFILE; \
- for test in `cat $<`; do \
- $(call INFO, "=== $$test"); \
- eval $(VALGRIND) $$test 2>>$$LOGFILE; \
- done; \
- [ "`cat $<`" ] || { $(call INFO, "=== ${<:.test=}"); eval $(VALGRIND) ${<:.test=} 2>>$$LOGFILE; }; \
- true
+valgrinds:
+ $(MAKE) all
+ $(MAKE) $(addprefix valgrind_,$(ALLEXE))
-tests: $(ALLTST)
+wipe: purge
+ $(call TITLE, "Wiping")
+ touch wipe
+ rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog)
+ $(call PASS, SUCCESS)
-valgrind_%:
- $(call WARN, "Activate valgrind")
- VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \
+tests:
+ -rm -f $(ALLEXE)
+ $(MAKE) all
+ $(MAKE) $(addprefix test_,$(ALLEXE))
+
+## Main rules
+
+include $(wildcard *.d)
+include $(wildcard *.ld)
+
+gcov_%:
+ $(MAKE) purge
+ $(MAKE) depends
+ OPTIONS="-coverage -O0" $(MAKE) ${@:gcov_%=%}.exe
+ $(MAKE) test_$(@:gcov_%=%)
+ gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
+ touch gcov
+ rm -f gcov $(wildcard *.gcda *.gcno)
+ $(MAKE) purge
+ grep '^ *#####' *.c.gcov || true
+
+gprof_%:
+ $(MAKE) purge
+ $(MAKE) depends
+ OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe
+ $(MAKE) ${@:gprof_%=%}.test
+ IFS=$$'\n'; id=1; \
+ for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \
+ log=${@:gprof_%=%}.prof-$$id.glog; \
+ $(call TITLE, test: $$test); \
+ echo $$test > $$log; \
+ eval $$test >> $$log; \
+ [ $$? -eq 0 ] \
+ && echo -e "\033[1;32mSUCCESS\033[0;0m" \
+ || echo -e "\033[1;31mFAILED\033[0;0m"; \
+ [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \
+ let id++; \
+ done;
+ $(MAKE) purge
+
+%.test: %.c
+ $(call TITLE, "Building $@")
+ $(call GETCOMMENTS,test, $<) > $@
+ $(call PASS, SUCCESS)
+ -rm -f _
+
+test_%: %.test %.exe
+ IFS=$$'\n'; RC=0; \
+ for test in `cat $< | sed 's,${<:.test=.exe},$(VALGRIND) ./${<:.test=.exe},g'`; do \
+ echo "=== $$test ==="; \
+ eval $$test; \
+ [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
+ || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
+ test "$$RC" = 1 -a "$(STOP)" = 1 && break; \
+ done; \
+ test "$$RC" -ne 1
+
+valgrind_%: %.exe
+ VALGRIND="valgrind -v --leak-check=full --log-fd=3"; \
export VALGRIND; \
- make ${@:valgrind_%=test_%}
+ $(MAKE) $(@:valgrind_%=test_%) 3>$@.log
%.d: %.c
- $(call VALID, "Creating $@", { \
- $(CC) $(IFLAGS) -MM $< -o - | sed "s;^`basename $(<:.c=.o)`;$(<:.c=.o);"; \
- echo $(call GET,depend, $<) | sed "s;^;$(<:.c=): $(<:.c=.o) ;"; \
- } > $@)
-
-lib%.d: %.ld
- $(call VALID, "Creating $@", sed 's/-l[^ ]*//g;s/\(.*\)\.$(LIBEXT)\.\([0-9]*\)\.\(.*\): \(.*\)/.\1.$(LIBEXT): \4\n\1.a: \4\n\1.$(LIBEXT).\2.\3: .\1.$(LIBEXT)\n\t$$(call VALID, "Assembling $$@", cp -f $$< $$@ \&\& rm $$<)\n\1.$(LIBEXT) \1.$(LIBEXT).\2: \1.$(LIBEXT).\2.\3\n\t$$(call VALID, "Assembling $$@", ln -sf $$< $$@)/' $< > $@)
-
-%.o: %.c
- $(call VALID, "Building $@", $(CC) $(CFLAGS) $(call GET,cflags, $<) -c $< -o $@)
-
-%.ho: %.h
- $(call VALID, "Building $@", $(CC) $(CFLAGS) $(call GET,cflags, $<) -x c -c $< -o $@)
-
-%.a:
- $(call VALID, "Archive $@", $(AR) -rc $@ $^)
-
-.$(LIBPRE)%:
- $(call TITLE, "Linking `echo $@ | sed 's/^\.//'`")
- $(CC) $(LDFLAGS) $$(cat `echo $@ | sed 's/\.$(LIBPRE)\(.*\)\.$(LIBEXT)/\1.ld/'` | sed 's/.*://') -shared -Wl,-soname=$$(cat `echo $@ | sed 's/\.$(LIBPRE)\(.*\)\.$(LIBEXT)/\1.ld/'` | sed 's/^\(.*\.$(LIBEXT)\.[0-9]*\)\..*/\1/') -o $@ || { $(call FAIL, FAILED); test; }
+ $(call TITLE, "Building $@")
+ $(CC) $(INCLUDES) -MM $< -o $@~
+ echo ${<:.c=.o}: $(shell $(call GETCOMMENTS,depends, $<)) >> $@~
+ $(MV) $@~ $@
$(call PASS, SUCCESS)
-$(PACKS):pack-%: %.ld depends
- $(call TITLE, "Packing $@-$(call VER,$<).tgz")
- [ ! -e $@ ] || rm -rf $@
- mkdir $@
- awk 'function alength(A, n, val) { n = 0; for (val in A) n++; return n } function a_sort(A, hold, i, j, n) { n = alength(A); for (i = 2; i <= n ; i++) { hold = A[j = i]; while (A[j-1] > hold) { j--; A[j+1] = A[j] } A[j] = hold } delete A[0 ]; return n } /\.o:/ { sub(/.*: */, ""); gsub (/\.o/, ".d"); t=t" "$$0 } END { split(t, a); a_sort(a); for (k in a) { if (prev != a[k]) print a[k]; prev=a[k] } }' `sed 's/.*://;s/\.o/.d/g;s/-l[^ ]*//' $<` | xargs -i% cp % $@
- cp $< makefile COPYING $(wildcard ${<:.ld=.3} README.${<:.ld=}) $@
- mkdir $@/test
- awk 'function alength(A, n, val) { n = 0; for (val in A) n++; return n } function a_sort(A, hold, i, j, n) { n = alength(A); for (i = 2; i <= n ; i++) { hold = A[j = i]; while (A[j-1] > hold) { j--; A[j+1] = A[j] } A[j] = hold } delete A[0 ]; return n } /$(LIBPRE)$(<:.ld=.$(LIBEXT))/ && ! /^$(LIBPRE)$(<:.ld=.$(LIBEXT))/ { sub(/.*: */, ""); gsub (/\.o/, ".d"); t=t" "$$0 } END { split(t, a); a_sort(a); for (k in a) { if ((prev != a[k]) && (a[k] != "$(LIBPRE)$(<:.ld=.$(LIBEXT))")) print a[k]; prev=a[k] } }' test/*.d | xargs awk 'function alength(A, n, val) { n = 0; for (val in A) n++; return n } function a_sort(A, hold, i, j, n) { n = alength(A); for (i = 2; i <= n ; i++) { hold = A[j = i]; while (A[j-1] > hold) { j--; A[j+1] = A[j] } A[j] = hold } delete A[0 ]; return n } /\.o:/ { sub(/.*: */, ""); gsub (/\.o/, ".d"); t=t" "$$0 } END { split(t, a); a_sort(a); for (k in a) { if ((prev != a[k]) && (a[k] != "\\") && !(a[k] ~ /\.\./)) print a[k]; prev=a[k] } }' | xargs -i% cp % $@/test
- cp test/makefile $@/test
- tar czf $@-$(call VER,$<).tgz $@
- rm -rf $@
+%.ld: %.c
+ $(call TITLE, "Building $@")
+ echo ${<:.c=.exe}: $(shell $(call GETCOMMENTS,$(LDOPT), $<) | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
$(call PASS, SUCCESS)
-packages: $(PACKS)
+%.o: %.c
+ $(call TITLE, "Building $@")
+ $(CC) $(CFLAGS) $(INCLUDES) $(shell $(call GETCOMMENTS,cflags, $<)) -c $< -o $@
+ $(call PASS, SUCCESS)
-$(DEBIAN):debian-%: pack-%
- $(call TITLE, "Debian package: $(<:pack-%=%) "$(call PVER,$<))
- [ -d $(DEBPKG) ] || mkdir $(DEBPKG)
- [ ! -d $(DEBPKG)/$<-$(call PVER,$<) ] || rm -rf $(DEBPKG)/$<-$(call PVER,$<)
- [ ! -d $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) ] || rm -rf $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<)
- tar xfz $<-$(call PVER,$<).tgz -C $(DEBPKG)
- mv $(DEBPKG)/$< $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<)
- cd $(DEBPKG); tar czf $(<:pack-%=%)_$(call PVER,$<).orig.tar.gz $(<:pack-%=%)-$(call PVER,$<)
- cp -par debian $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<)
- for f in $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<)/debian/*.$(<:pack-%=%); do mv $$f $${f/.$(<:pack-%=%)}; done
- cd $(DEBPKG)/$(<:pack-%=%)-$(call PVER,$<) && { echo; debuild; }
-debian: $(DEBIAN)
+%.exe: %.o %.d
+ $(call TITLE, "Building $@")
+ $(CC) $(LDFLAGS) $< $(shell $(call GETCOMMENTS,$(LDOPT), ${<:.o=.c})) $(LDLIBS) -o $@
+ $(call PASS, SUCCESS)
-test/%: test/%.o test/%.d
- $(call VALID, "Linking $@", $(CC) $(LDFLAGS) $(LFLAGS) $< $(call GET,linker, $(<:.o=.c)) -o $@)
+## Phony
-include $(wildcard *.d) $(wildcard test/*.d)
+.PHONY: all clean count depends gcovs purge tests
-## Phony
+## Precious
-.PHONY: all archive clean count depends headers install packages purge
+.PRECIOUS: %.d %.o
--- /dev/null
+/*
+ File name : morep_server.c
+ Projet : MERLIN
+ Date of creation : 2025/03/18
+ Version : 1.0
+ Copyright : Thales SIX
+ Author : Laurent Mazet <laurent.mazet@thalesgroup.com>
+
+ Description : Raw Ethernet packet server for MOREP library
+
+ History :
+ - initial version
+*/
+
+/* depend: */
+/* cflags: */
+/* linker: morep.o */
+/* winlnk: morep.o */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+#include <pthread.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "debug.h"
+
+#include "morep.h"
+
+int stop = 0;
+
+void sig_handler (int sig)
+{
+ switch (sig) {
+ case SIGINT:
+ stop = 1;
+ break;
+ case SIGTERM:
+ exit (0);
+ break;
+ }
+}
+
+int morep_server (char *url) {
+{
+ VERBOSE (morep, TRACE, PRINTF ("morep_server\n"));
+
+ int fd = MOREP_connect (url);
+
+ VERBOSE (morep, INFO, PRINTF ("server started at '%s'\n", url));
+
+ int morep = MOREP_Connect (local_address, remote_address);
+ if (morep < 0) {
+ VERBOSE (morep, ERROR, PRINTF ("can't connect on url '%s'\n", url));
+ return -1;
+ }
+
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+
+ int i = 0;
+ char *words[] = {"Quo", "cognito", "Constantius", "ultra", "mortalem", "modum", "exarsit", "ac", "nequo", "casu", "idem", "Gallus", "de", "futuris", "incertus", "agitare", "quaedam", "conducentia", "saluti", "suae", "per", "itinera", "conaretur,", "remoti", "sunt", "omnes", "de", "industria", "milites", "agentes", "in", "civitatibus", "perviis.", NULL};
+ while (stop) {
+
+ int len = MOREP_Receive (fd)
+ VERBOSE (morep, INFO, PRINTF ("receive %d bytes\n", len));
+
+ uint8_t buffer = MOREP_Get_Tx_Buffer (fd);
+ len = strlen (words[i]);
+ memcpy (buffer, words[i++], len);
+ if (words[i] == NULL) {
+ i = 0;
+ }
+ len = MOREP_Send (fd);
+ VERBOSE (morep, INFO, PRINTF ("send %d bytes\n", len));
+
+ }
+
+ return 0;
+}
+
+/**
+ Verbose level
+*/
+DECLARE_VERBOSE_LEVEL (morep, INFO);
+
+int main (int argc, char **argv)
+{
+ char *url = NULL;
+
+ /* 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] != '-') {
+ url = arg[0];
+ }
+ char c = arg[1];
+ switch (c) {
+ case 'v':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "%s: no directory name\n", progname));
+ return usage (1);
+ }
+ CHANGE_VERBOSE_LEVEL (morep, atoi (arg));
+ break;
+ case 'h':
+ default:
+ printf ("usage: %s [-h] [-v int] <url>\n");
+ return (c != 'h');
+ }
+ }
+
+ if (url) {
+ server (url);
+ }
+
+ return (url == NULL);
+}
+
+/* test-depend: morep_valid */
+
+/* test: morep_server */
+/* test: morep_server -h */
+/* test: morep_server -v 4 */
+
+/* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode*/
--- /dev/null
+/*
+ File name : morep_test.c
+ Projet : MERLIN
+ Date of creation : 2025/03/18
+ Version : 1.0
+ Copyright : Thales SIX
+ Author : Laurent Mazet <laurent.mazet@thalesgroup.com>
+
+ Description : Test programm for MOREP library
+
+ History :
+ - initial version
+*/
+
+/* depend: */
+/* cflags: */
+/* linker: morep.o */
+/* winlnk: morep.o */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+#include <pthread.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "debug.h"
+
+#include "morep.h"
+
+int MOREP_Accept_NONBLOCK_OK = 0;
+int MOREP_Receive_NONBLOCK_OK = 0;
+int MOREP_Send_OK = 0;
+int MOREP_Echo_OK = 0;
+
+int test_client (char *local_address, char *remote_address)
+{
+ VERBOSE (morep, TRACE, PRINTF ("test_client\n"));
+
+ int count;
+ unsigned char tx_data[10][8192];
+ unsigned long tx_msgtype[10];
+ int tx_len[10];
+
+ VERBOSE (morep, INFO, PRINTF ("%s started\n", remote_address));
+
+ int morep = MOREP_Connect (local_address, remote_address);
+ if (morep < 0) {
+ VERBOSE (morep, ERROR, PRINTF ("%s MOREP_Connect error\n", remote_address));
+ return -1;
+ }
+
+ VERBOSE (morep, INFO, PRINTF ("%s connected to server, trying to exchange 10 messages\n", remote_address));
+
+ for (count = 0; count < 10; count++) {
+ int i, rc;
+
+ /* to valid non block */
+ if (count == 5)
+ sleep (1);
+
+ tx_len[count] = rand () % sizeof (tx_data[count]);
+ tx_msgtype[count] = rand ();
+ for (i = 0; i < tx_len[count]; i++)
+ tx_data[count][i] = rand () % 256;
+
+ rc = MOREP_Send (morep, tx_msgtype[count], tx_data[count], tx_len[count]);
+ if (rc < 0) {
+ VERBOSE (morep, ERROR, PRINTF ("%s MOREP_Send tx error\n", remote_address));
+ return -1;
+
+ }
+ if (tx_len[count] != rc) {
+ VERBOSE (morep, ERROR, PRINTF ("%s MOREP_Send tx len error tx=%d rc=%d\n", remote_address, tx_len[count], rc));
+ return -1;
+ }
+ }
+
+ for (count = 0; count < 10; count++) {
+ int rx_len;
+ unsigned char rx_data[32768];
+ unsigned long rx_msgtype;
+
+
+ do {
+ rx_len = MOREP_Receive (morep, &rx_msgtype, rx_data, sizeof (rx_data));
+ if (rx_len == 0)
+ sleep (1);
+ } while (rx_len == 0);
+
+ VERBOSE (morep, INFO, PRINTF ("%s echo received count=%d len=%d, morep=%d\n", remote_address, count, rx_len, morep));
+
+ if (tx_len[count] != rx_len) {
+ VERBOSE (morep, WARNING, PRINTF ("%s MOREP_Receive rx len error : tx=%d / rx=%d\n", remote_address, tx_len[count], rx_len));
+ return -1;
+ }
+
+ if (tx_msgtype[count] != rx_msgtype) {
+ VERBOSE (morep, WARNING, PRINTF ("%s MOREP_Receive rx msgtype error : tx=%08lX / rx=%08lX\n", remote_address, tx_msgtype[count], rx_msgtype));
+ return -1;
+ }
+
+ if (memcmp (rx_data, tx_data[count], tx_len[count]) != 0 ) {
+ VERBOSE (morep, WARNING, PRINTF ("%s MOREP_Receive rx corrupted data\n",remote_address));
+ return -1;
+ }
+ }
+
+ MOREP_Close (morep);
+ VERBOSE (morep, INFO, PRINTF ("%s end of test, %d echo processed\n", remote_address, count));
+ return 0;
+}
+
+void *rep_server (UNUSED void *dummy)
+{
+ VERBOSE (morep, TRACE, PRINTF ("rep_server\n"));
+
+ VERBOSE (morep, INFO, PRINTF ("rep_server started\n"));
+
+ int morep = MOREP_Connect ("rep://01:02:03:04:05:06/2064", "rep://07:08:08:0a:0b:0C/2065"); /* 0x0810 / 0x0811 */
+ if (morep < 0) {
+ VERBOSE (morep, ERROR, PRINTF ("MOREP_Connect (%d)", errno);
+ exit (1);
+ }
+
+ VERBOSE (morep, INFO, PRINTF ("rep_server waiting for data\n"));
+
+ while (1) {
+ unsigned char data[1024];
+ unsigned long msgtype;
+
+ int rx_len = MOREP_Receive (morep, &msgtype, data, sizeof (data));
+ if (rx_len == 0) {
+ MOREP_Receive_NONBLOCK_OK = 1;
+ sleep (1);
+ continue;
+ }
+ if (rx_len < 0) {
+ MOREP_Close (morep);
+ break;
+ }
+
+ VERBOSE (morep, INFO, PRINTF ("rep_server receive data len=%d, sending echo\n", rx_len));
+
+ int tx_len = MOREP_Send (morep, msgtype, data, rx_len);
+ if (tx_len == rx_len)
+ MOREP_Send_OK = 1;
+ }
+
+ return NULL;
+}
+
+void *rep_client (UNUSED void *dummy)
+{
+ int i;
+
+ for (i = 0; i < 5; i++) {
+ int rc = test_client ("rep://07:08:08:0a:0b:0C/2065" "rep://01:02:03:04:05:06/2064");
+ if (rc)
+ pthread_exit (&MOREP_Echo_OK);
+ }
+
+ MOREP_Echo_OK = 1;
+ pthread_exit (&MOREP_Echo_OK);
+ return NULL;
+}
+
+/**
+ Dump status macro
+*/
+#define DUMP_STATUS(x) do { \
+ printf (#x " %s\n", (x) ? "OK" : "BAD"); \
+ if (!(x)) \
+ failed = 1; \
+ } while (0) \
+
+/**
+ Verbose level
+*/
+DECLARE_VERBOSE_LEVEL (morep, INFO);
+
+int main (int argc, char **argv)
+{
+
+ /* process arguments */
+ if (argc > 1) {
+ CHANGE_VERBOSE_LEVEL (morep, atoi (argv[1]));
+ argc--;
+ }
+ if (argc > 1) {
+ printf ("usage: %s [verbose level]\n", argv[0]);
+ exit (1);
+ }
+
+ printf ("*** STARTING TEST SEQUENCE ***\n");
+
+ pthread_t rep_thread;
+
+ pthread_create (&rep_thread, NULL, rep_server, NULL);
+
+ /* Give some delay to server to setup there MOREP */
+ sleep (1);
+
+ pthread_t rep_client_thread;
+
+ pthread_create (&rep_client_thread, NULL, rep_client, NULL);
+
+ pthread_join (rep_client_thread, NULL);
+
+ printf ("*** END OF TEST SEQUENCE ***\n");
+
+ int failed = 0;
+ DUMP_STATUS (MOREP_Accept_NONBLOCK_OK);
+ DUMP_STATUS (MOREP_Receive_NONBLOCK_OK);
+ DUMP_STATUS (MOREP_Send_OK);
+ DUMP_STATUS (MOREP_Echo_OK);
+
+ return failed ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
+/* test: morep_test */
+/* test: morep_test 1 */
+
+/* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode*/
+++ /dev/null
-/*
- File name : morep_valid.c
- Projet : MERLIN
- Date of creation : 2025/03/18
- Version : 1.0
- Copyright : Thales SIX
- Author : Laurent Mazet <laurent.mazet@thalesgroup.com>
-
- Description : Validation test suite for MOREP library
-
- History :
- - initial version
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <assert.h>
-#include <pthread.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "debug.h"
-
-#include "morep.h"
-
-int MOREP_Accept_NONBLOCK_OK = 0;
-int MOREP_Receive_NONBLOCK_OK = 0;
-int MOREP_Send_OK = 0;
-int MOREP_Echo_OK = 0;
-
-int test_client (char *local_address, char *remote_address)
-{
- VERBOSE (morep, TRACE, PRINTF ("test_client\n"));
-
- int count;
- unsigned char tx_data[10][8192];
- unsigned long tx_msgtype[10];
- int tx_len[10];
-
- VERBOSE (morep, INFO, PRINTF ("%s started\n", remote_address));
-
- int morep = MOREP_Connect (local_address, remote_address);
- if (morep < 0) {
- VERBOSE (morep, ERROR, PRINTF ("%s MOREP_Connect error\n", remote_address));
- return -1;
- }
-
- VERBOSE (morep, INFO, PRINTF ("%s connected to server, trying to exchange 10 messages\n", remote_address));
-
- for (count = 0; count < 10; count++) {
- int i, rc;
-
- /* to valid non block */
- if (count == 5)
- sleep (1);
-
- tx_len[count] = rand () % sizeof (tx_data[count]);
- tx_msgtype[count] = rand ();
- for (i = 0; i < tx_len[count]; i++)
- tx_data[count][i] = rand () % 256;
-
- rc = MOREP_Send (morep, tx_msgtype[count], tx_data[count], tx_len[count]);
- if (rc < 0) {
- VERBOSE (morep, ERROR, PRINTF ("%s MOREP_Send tx error\n", remote_address));
- return -1;
-
- }
- if (tx_len[count] != rc) {
- VERBOSE (morep, ERROR, PRINTF ("%s MOREP_Send tx len error tx=%d rc=%d\n", remote_address, tx_len[count], rc));
- return -1;
- }
- }
-
- for (count = 0; count < 10; count++) {
- int rx_len;
- unsigned char rx_data[32768];
- unsigned long rx_msgtype;
-
-
- do {
- rx_len = MOREP_Receive (morep, &rx_msgtype, rx_data, sizeof (rx_data));
- if (rx_len == 0)
- sleep (1);
- } while (rx_len == 0);
-
- VERBOSE (morep, INFO, PRINTF ("%s echo received count=%d len=%d, morep=%d\n", remote_address, count, rx_len, morep));
-
- if (tx_len[count] != rx_len) {
- VERBOSE (morep, WARNING, PRINTF ("%s MOREP_Receive rx len error : tx=%d / rx=%d\n", remote_address, tx_len[count], rx_len));
- return -1;
- }
-
- if (tx_msgtype[count] != rx_msgtype) {
- VERBOSE (morep, WARNING, PRINTF ("%s MOREP_Receive rx msgtype error : tx=%08lX / rx=%08lX\n", remote_address, tx_msgtype[count], rx_msgtype));
- return -1;
- }
-
- if (memcmp (rx_data, tx_data[count], tx_len[count]) != 0 ) {
- VERBOSE (morep, WARNING, PRINTF ("%s MOREP_Receive rx corrupted data\n",remote_address));
- return -1;
- }
- }
-
- MOREP_Close (morep);
- VERBOSE (morep, INFO, PRINTF ("%s end of test, %d echo processed\n", remote_address, count));
- return 0;
-}
-
-void *rep_server (UNUSED void *dummy)
-{
- VERBOSE (morep, TRACE, PRINTF ("rep_server\n"));
-
- VERBOSE (morep, INFO, PRINTF ("rep_server started\n"));
-
- int morep = MOREP_Connect ("rep://01:02:03:04:05:06/2064", "rep://07:08:08:0a:0b:0C/2065"); /* 0x0810 / 0x0811 */
- if (morep < 0) {
- VERBOSE (morep, ERROR, PRINTF ("MOREP_Connect (%d)", errno);
- exit (1);
- }
-
- VERBOSE (morep, INFO, PRINTF ("rep_server waiting for data\n"));
-
- while (1) {
- unsigned char data[1024];
- unsigned long msgtype;
-
- int rx_len = MOREP_Receive (morep, &msgtype, data, sizeof (data));
- if (rx_len == 0) {
- MOREP_Receive_NONBLOCK_OK = 1;
- sleep (1);
- continue;
- }
- if (rx_len < 0) {
- MOREP_Close (morep);
- break;
- }
-
- VERBOSE (morep, INFO, PRINTF ("rep_server receive data len=%d, sending echo\n", rx_len));
-
- int tx_len = MOREP_Send (morep, msgtype, data, rx_len);
- if (tx_len == rx_len)
- MOREP_Send_OK = 1;
- }
-
- return NULL;
-}
-
-void *rep_client (UNUSED void *dummy)
-{
- int i;
-
- for (i = 0; i < 5; i++) {
- int rc = test_client ("rep://07:08:08:0a:0b:0C/2065" "rep://01:02:03:04:05:06/2064");
- if (rc)
- pthread_exit (&MOREP_Echo_OK);
- }
-
- MOREP_Echo_OK = 1;
- pthread_exit (&MOREP_Echo_OK);
- return NULL;
-}
-
-/**
- Dump status macro
-*/
-#define DUMP_STATUS(x) do { \
- printf (#x " %s\n", (x) ? "OK" : "BAD"); \
- if (!(x)) \
- failed = 1; \
- } while (0) \
-
-/**
- Verbose level
-*/
-DECLARE_VERBOSE_LEVEL (morep, INFO);
-
-int main (int argc, char **argv)
-{
-
- /* process arguments */
- if (argc > 1) {
- CHANGE_VERBOSE_LEVEL (morep, atoi (argv[1]));
- argc--;
- }
- if (argc > 1) {
- printf ("usage: %s [verbose level]\n", argv[0]);
- exit (1);
- }
-
- printf ("*** STARTING TEST SEQUENCE ***\n");
-
- pthread_t rep_thread;
-
- pthread_create (&rep_thread, NULL, rep_server, NULL);
-
- /* Give some delay to server to setup there MOREP */
- sleep (1);
-
- pthread_t rep_client_thread;
-
- pthread_create (&rep_client_thread, NULL, rep_client, NULL);
-
- pthread_join (rep_client_thread, NULL);
-
- printf ("*** END OF TEST SEQUENCE ***\n");
-
- int failed = 0;
- DUMP_STATUS (MOREP_Accept_NONBLOCK_OK);
- DUMP_STATUS (MOREP_Receive_NONBLOCK_OK);
- DUMP_STATUS (MOREP_Send_OK);
- DUMP_STATUS (MOREP_Echo_OK);
-
- return failed ? EXIT_FAILURE : EXIT_SUCCESS;
-}
-
-/* test-depend: morep_valid */
-
-/* test: morep_valid */
-/* test: morep_valid 1 */
-
-/* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode*/