From ffdeb38ae03fb4fcc8ff357639d2a2e3ee68355e Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Sat, 29 Jun 2024 13:47:14 +0000 Subject: [PATCH] test / fix cl --- tunnels/adapters/connector/tcp/tcp_connector.c | 12 ++++++++---- ww/utils/mathutils.h | 11 ++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tunnels/adapters/connector/tcp/tcp_connector.c b/tunnels/adapters/connector/tcp/tcp_connector.c index 96c0a4c1..d051d86f 100644 --- a/tunnels/adapters/connector/tcp/tcp_connector.c +++ b/tunnels/adapters/connector/tcp/tcp_connector.c @@ -1,3 +1,7 @@ +// Remember to define _CRT_RAND_S before you include +// stdlib.h. +#define _CRT_RAND_S + #include "tcp_connector.h" #include "basic_types.h" #include "frand.h" @@ -264,9 +268,9 @@ static void upStream(tunnel_t *self, context_t *c) unsigned int seed = fastRand(); // no probelm if overflows #ifdef OS_UNIX - const uint32_t large_random = 1 + (((uint32_t) rand_r(&seed)) % state->outbound_ip_range); + const uint32_t large_random = (((uint32_t) rand_r(&seed)) % state->outbound_ip_range); #else - const uint32_t large_random = 1 + (((uint32_t) rand_s(&seed)) % state->outbound_ip_range); + const uint32_t large_random = (((uint32_t) rand_s(&seed)) % state->outbound_ip_range); #endif uint32_t calc = htonl(ntohl((uint32_t) dest_ctx->address.sin.sin_addr.s_addr) + large_random); memcpy(&(dest_ctx->address.sin.sin_addr), &calc, sizeof(struct in_addr)); @@ -279,9 +283,9 @@ static void upStream(tunnel_t *self, context_t *c) unsigned int seed = fastRand(); // no probelm if overflows #ifdef OS_UNIX - const uint64_t large_random = 1 + (((uint64_t) rand_r(&seed)) % state->outbound_ip_range); + const uint64_t large_random = (((uint64_t) rand_r(&seed)) % state->outbound_ip_range); #else - const uint64_t large_random = 1 + (((uint64_t) rand_s(&seed)) % state->outbound_ip_range); + const uint64_t large_random = (((uint64_t) rand_s(&seed)) % state->outbound_ip_range); #endif uint64_t *addr_ptr = (uint64_t *) &dest_ctx->address.sin6.sin6_addr; addr_ptr += 64 / (sizeof(uint64_t)); diff --git a/ww/utils/mathutils.h b/ww/utils/mathutils.h index dc47706e..e3c2cfff 100644 --- a/ww/utils/mathutils.h +++ b/ww/utils/mathutils.h @@ -23,10 +23,19 @@ static inline ssize_t max(ssize_t x, ssize_t y) #define MAXOF(t) ((unsigned long long) (ISSIGNED(t) ? SMAXOF(t) : UMAXOF(t))) -#if __BIG_ENDIAN__ + +#if __BIG_ENDIAN__ +#ifndef htonll #define htonll(x) (x) +#endif +#ifndef ntohll #define ntohll(x) (x) +#endif #else +#ifndef htonll #define htonll(x) (((uint64_t) htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32)) // NOLINT +#endif +#ifndef ntohll #define ntohll(x) (((uint64_t) ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) // NOLINT #endif +#endif