Skip to content

Commit

Permalink
test / fix cl
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 29, 2024
1 parent c1d2854 commit ffdeb38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 8 additions & 4 deletions tunnels/adapters/connector/tcp/tcp_connector.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
11 changes: 10 additions & 1 deletion ww/utils/mathutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ffdeb38

Please sign in to comment.