n2n/tools/tests-wire.c
Hamish Coleman 4438f1aa2a
added mingw test platform (#829)
* Provide a minimal reimplementation of our autoconf, to try windows builds

* Try building with windows

* Fix thinko in spelling

* Ensure shell script runs inside a shell

* Add a hack to aid include discovery

* Just keep adding tech debt...

* Assume that we will have slashes in some of the replacement strings and avoid that char with sed

* Restore one slash

* Hack around the tools makefile interdependancy bug

* A correct cflags include hack for each compile dir

* Ensure we link against winsock (note, even though this says 32bit, it should link the 64bit library ... I think)

* Bad link ordering if we dont use LDLIBS

* Remove unused make variable

* Remove makefile duplication using inheritance (this does mean you can no longer cd tools; make, but must do make tools)

* Add missing library for win32

* Show OS variable

* Make hack autoconf more robust for tests on non gitlab runners

* Remove no longer used substitutions from hack autoconf

* Add missing include path to tools under win32

* Build the win32 subdir when the compiler is Msys

* The different subdirs have different dependancies

* Ensure we can find the include files

* Fix library link ordering

* Ensure the tools dir can find the special win32 lib

* Deal with the differing basic type sizes on both linux/64bit and windows/64bit

* Document the steps to mimic the github windows/mingw build locally - to allow for simpler debugging

* Ensure branch name in instructions matches my test branch name

* Clarify the shell needed to build with mingw

* Since the makefile depends on knowing the OS, raise a fatal error if we cannot determine this

* Handling different compile environments is hard.

- Linux: sane and reasonable results for both uname -s (=Linux) and
  uname -o (=GNU/Linux)
- Windows/Mingw: insane results for uname -s
  (=MSYS_NT-$MAJOR.$MINOR-$BUILDNR) but sane results for uname -o (Msys)
- Macos: sane results for uname -s (=Darwin) but does not support
  uname -o at all

* Revamp the way that Mingw is detected

* Avoid attempting to generate gcovr report when running under windows

* Whoops, isolate the right step

* Fix spelling mistake

* win32/Makefile: Remove unused setting and add comment

* ensure that all win32 includes use the same expected path

* Allow simpler cross compilation by letting configure pass the CC and AR environment through

* Avoid multiple '_CRT_SECURE_NO_WARNINGS redefined' warnings

* Convert to a consolidated CONFIG_TARGET variable to select any different compile options

* Use the more generic printf defines to avoid warnings on mingw

* Update mingw build docs

* English better for reader happy make

* Address a number of mingw compiler warnings

* Fix Visual C compile

* Be sure to document some of the hacky nature of the mingw build
2021-10-06 00:52:15 +05:45

85 lines
2.7 KiB
C

/*
* (C) 2007-21 - ntop.org and contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include <inttypes.h>
#include "n2n.h"
#include "hexdump.h"
void test_REGISTER(n2n_common_t *common) {
char *test_name = "REGISTER";
common->pc = n2n_register;
printf("%s: common.pc = %i\n", test_name, common->pc);
n2n_REGISTER_t reg;
memset( &reg, 0, sizeof(reg) );
n2n_mac_t dummysrcMac={0,1,2,3,4,5};
memcpy( reg.srcMac, dummysrcMac, sizeof(dummysrcMac));
n2n_mac_t dummydstMac={0x10,0x11,0x12,0x13,0x14,0x15};
memcpy( reg.dstMac, dummydstMac, sizeof(dummydstMac));
reg.dev_addr.net_addr = 0x20212223;
reg.dev_addr.net_bitlen = 25;
strcpy( (char *)reg.dev_desc, "Dummy_Dev_Desc" );
printf("%s: reg.cookie = %i\n", test_name, reg.cookie);
// TODO: print reg.srcMac, reg.dstMac
// TODO: print reg.sock
printf("%s: reg.dev_addr.net_addr = 0x%08x\n", test_name, reg.dev_addr.net_addr);
printf("%s: reg.dev_addr.net_bitlen = %i\n", test_name, reg.dev_addr.net_bitlen);
printf("%s: reg.dev_desc = \"%s\"\n", test_name, reg.dev_desc);
printf("\n");
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
size_t idx = 0;
size_t retval = encode_REGISTER( pktbuf, &idx, common, &reg);
printf("%s: output retval = 0x%"PRIx64"\n", test_name, retval);
printf("%s: output idx = 0x%"PRIx64"\n", test_name, idx);
fhexdump(0, pktbuf, idx, stdout);
// TODO: decode_REGISTER() and print
fprintf(stderr, "%s: tested\n", test_name);
printf("\n");
}
int main(int argc, char * argv[]) {
char *test_name = "environment";
n2n_community_t c;
strncpy((char *)c, "abc123def456z", sizeof(c));
n2n_common_t common;
memset( &common, 0, sizeof(common) );
common.ttl = N2N_DEFAULT_TTL;
common.flags = 0;
memcpy( common.community, c, N2N_COMMUNITY_SIZE );
printf("%s: common.ttl = %i\n", test_name, common.ttl);
printf("%s: common.flags = %i\n", test_name, common.flags);
printf("%s: common.community = \"%s\"\n", test_name, common.community);
printf("\n");
test_REGISTER(&common);
// TODO: add more wire tests
return 0;
}