n2n/include/n2n_wire.h

227 lines
7.6 KiB
C
Raw Normal View History

/**
2021-01-13 10:05:26 +01:00
* (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 see <http://www.gnu.org/licenses/>
2016-10-23 10:46:15 +02:00
*
*/
#if !defined( N2N_WIRE_H_ )
#define N2N_WIRE_H_
#include <stdlib.h>
#ifndef _MSC_VER
/* Not included in Visual Studio 2008 */
2016-10-23 10:46:15 +02:00
#include <stdint.h>
#endif
2016-10-23 10:46:15 +02:00
#if defined(WIN32)
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-05 21:07:15 +02:00
#include "n2n_win32.h"
#else /* #if defined(WIN32) */
#include <netinet/in.h>
#include <sys/socket.h> /* AF_INET and AF_INET6 */
#endif /* #if defined(WIN32) */
#include "sn_selection.h"
2020-12-19 12:28:39 +01:00
int encode_uint8 (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
2020-12-19 12:28:39 +01:00
const uint8_t v);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_uint8 (uint8_t * out,
2016-10-23 10:46:15 +02:00
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_uint16 (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
2020-12-19 12:28:39 +01:00
const uint16_t v);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_uint16 (uint16_t * out,
2016-10-23 10:46:15 +02:00
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_uint32 (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
2020-12-19 12:28:39 +01:00
const uint32_t v);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_uint32 (uint32_t * out,
2016-10-23 10:46:15 +02:00
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_uint64 (uint8_t * base,
size_t * idx,
2020-12-19 12:28:39 +01:00
const uint64_t v);
2020-12-19 12:28:39 +01:00
int decode_uint64 (uint64_t * out,
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2020-12-19 12:28:39 +01:00
int encode_buf (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
const void * p,
2016-10-23 10:46:15 +02:00
size_t s);
2020-12-19 12:28:39 +01:00
int decode_buf (uint8_t * out,
2016-10-23 10:46:15 +02:00
size_t bufsize,
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_mac (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
2020-12-19 12:28:39 +01:00
const n2n_mac_t m);
2016-10-23 10:46:15 +02:00
2021-01-13 10:05:26 +01:00
int decode_mac (n2n_mac_t out,
2016-10-23 10:46:15 +02:00
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
int encode_cookie (uint8_t * base,
size_t * idx,
const n2n_cookie_t c);
int decode_cookie (n2n_cookie_t * out,
const uint8_t * base,
size_t * rem,
size_t * idx);
2020-12-19 12:28:39 +01:00
int encode_common (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
2020-12-19 12:28:39 +01:00
const n2n_common_t * common);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_common (n2n_common_t * out,
2016-10-23 10:46:15 +02:00
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_sock (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
2020-12-19 12:28:39 +01:00
const n2n_sock_t * sock);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_sock (n2n_sock_t * sock,
2016-10-23 10:46:15 +02:00
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_REGISTER (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
const n2n_common_t * common,
2020-12-19 12:28:39 +01:00
const n2n_REGISTER_t * reg);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_REGISTER (n2n_REGISTER_t * pkt,
2016-10-23 10:46:15 +02:00
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_REGISTER_SUPER (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
const n2n_common_t * common,
2020-12-19 12:28:39 +01:00
const n2n_REGISTER_SUPER_t * reg);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_REGISTER_SUPER (n2n_REGISTER_SUPER_t * pkt,
2016-10-23 10:46:15 +02:00
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_UNREGISTER_SUPER (uint8_t *base,
size_t *idx,
const n2n_common_t *common,
const n2n_UNREGISTER_SUPER_t *unreg);
2020-12-19 12:28:39 +01:00
int decode_UNREGISTER_SUPER (n2n_UNREGISTER_SUPER_t *unreg,
const n2n_common_t *cmn, /* info on how to interpret it */
const uint8_t *base,
size_t *rem,
size_t *idx);
2020-12-19 12:28:39 +01:00
int encode_REGISTER_ACK (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
const n2n_common_t * common,
2020-12-19 12:28:39 +01:00
const n2n_REGISTER_ACK_t * reg);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_REGISTER_ACK (n2n_REGISTER_ACK_t * pkt,
2016-10-23 10:46:15 +02:00
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_REGISTER_SUPER_ACK (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
const n2n_common_t * cmn,
const n2n_REGISTER_SUPER_ACK_t * reg,
uint8_t * tmpbuf);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_REGISTER_SUPER_ACK (n2n_REGISTER_SUPER_ACK_t * reg,
2016-10-23 10:46:15 +02:00
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
size_t * idx,
uint8_t * tmpbuf);
2020-12-19 12:28:39 +01:00
int encode_REGISTER_SUPER_NAK (uint8_t * base,
size_t * idx,
const n2n_common_t * cmn,
const n2n_REGISTER_SUPER_NAK_t * nak);
2020-12-19 12:28:39 +01:00
int decode_REGISTER_SUPER_NAK (n2n_REGISTER_SUPER_NAK_t * nak,
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
size_t * idx);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int fill_sockaddr (struct sockaddr * addr,
size_t addrlen,
2020-12-19 12:28:39 +01:00
const n2n_sock_t * sock);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int encode_PACKET (uint8_t * base,
2016-10-23 10:46:15 +02:00
size_t * idx,
const n2n_common_t * common,
2020-12-19 12:28:39 +01:00
const n2n_PACKET_t * pkt);
2016-10-23 10:46:15 +02:00
2020-12-19 12:28:39 +01:00
int decode_PACKET (n2n_PACKET_t * pkt,
2016-10-23 10:46:15 +02:00
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
2020-12-19 12:28:39 +01:00
size_t * idx);
int encode_PEER_INFO (uint8_t * base,
size_t * idx,
const n2n_common_t * common,
const n2n_PEER_INFO_t * pkt);
int decode_PEER_INFO (n2n_PEER_INFO_t * pkt,
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
size_t * idx);
int encode_QUERY_PEER (uint8_t * base,
size_t * idx,
const n2n_common_t * common,
const n2n_QUERY_PEER_t * pkt);
int decode_QUERY_PEER (n2n_QUERY_PEER_t * pkt,
const n2n_common_t * cmn, /* info on how to interpret it */
const uint8_t * base,
size_t * rem,
size_t * idx);
2016-10-23 10:46:15 +02:00
#endif /* #if !defined( N2N_WIRE_H_ ) */