From a3a745010418b8f1c1e7f9530bbd2bbfc145e724 Mon Sep 17 00:00:00 2001 From: redraincatching <99604494+redraincatching@users.noreply.github.com> Date: Tue, 1 Jul 2025 11:41:22 +0100 Subject: [PATCH] refactored tri-state to bools (#1709) refactored random tri-state to use two random booleans for clarity --- src/apps/uclient/startuclient.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apps/uclient/startuclient.c b/src/apps/uclient/startuclient.c index d580359..ca977c0 100644 --- a/src/apps/uclient/startuclient.c +++ b/src/apps/uclient/startuclient.c @@ -655,14 +655,14 @@ beg_allocate: } if (dual_allocation && !mobility) { - // TODO: This could be reworked - // it's using t as a tri-state to determine whether to add the requested address family field - // it should be two seperate bools for readability purposes though. - uint8_t t = ((uint8_t)turn_random()) % 3; - if (t) { + uint8_t rand = (uint8_t)turn_random(); + bool add_requested_family = rand & 0x01; + bool use_ipv4 = rand & 0x03; + + if (add_requested_family) { uint8_t field[4]; - field[0] = (t == 1) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 - : (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6; + field[0] = (use_ipv4) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 + : (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6; field[1] = 0; field[2] = 0; field[3] = 0;