Skip to content

Commit 35d6248

Browse files
udpard_is_valid_endpoint
1 parent bf4772d commit 35d6248

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

libudpard/udpard.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ static int32_t cavl_compare_fragment_end(const void* const user, const udpard_tr
116116
return 0; // clang-format on
117117
}
118118

119-
static bool validate_ep(const udpard_udpip_ep_t ep) { return (ep.port != 0) && (ep.ip != 0) && (ep.ip != UINT32_MAX); }
119+
bool udpard_is_valid_endpoint(const udpard_udpip_ep_t ep)
120+
{
121+
return (ep.port != 0) && (ep.ip != 0) && (ep.ip != UINT32_MAX);
122+
}
120123

121124
udpard_udpip_ep_t udpard_make_subject_endpoint(const uint32_t subject_id)
122125
{
@@ -633,8 +636,9 @@ uint32_t udpard_tx_push(udpard_tx_t* const self,
633636
void* const user_transfer_reference)
634637
{
635638
uint32_t out = 0;
636-
const bool ok = (self != NULL) && (deadline >= now) && (self->local_uid != 0) && validate_ep(remote_ep) &&
637-
(priority <= UDPARD_PRIORITY_MAX) && ((payload.data != NULL) || (payload.size == 0U));
639+
const bool ok = (self != NULL) && (deadline >= now) && (self->local_uid != 0) &&
640+
udpard_is_valid_endpoint(remote_ep) && (priority <= UDPARD_PRIORITY_MAX) &&
641+
((payload.data != NULL) || (payload.size == 0U));
638642
if (ok) {
639643
self->errors_expiration += tx_purge_expired(self, now);
640644
const meta_t meta = {
@@ -1716,7 +1720,7 @@ bool udpard_rx_port_push(udpard_rx_t* const rx,
17161720
const udpard_mem_deleter_t payload_deleter,
17171721
const uint_fast8_t redundant_iface_index)
17181722
{
1719-
const bool ok = (rx != NULL) && (port != NULL) && (timestamp >= 0) && validate_ep(source_ep) &&
1723+
const bool ok = (rx != NULL) && (port != NULL) && (timestamp >= 0) && udpard_is_valid_endpoint(source_ep) &&
17201724
(datagram_payload.data != NULL) && (payload_deleter.free != NULL) &&
17211725
(redundant_iface_index < UDPARD_NETWORK_INTERFACE_COUNT_MAX);
17221726
if (ok) {

libudpard/udpard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ typedef struct udpard_remote_t
139139
udpard_udpip_ep_t endpoints[UDPARD_NETWORK_INTERFACE_COUNT_MAX]; ///< Zeros in unavailable ifaces.
140140
} udpard_remote_t;
141141

142+
/// Returns true if the given UDP/IP endpoint appears to be valid. Zero port or IP are considered invalid.
143+
bool udpard_is_valid_endpoint(const udpard_udpip_ep_t ep);
144+
142145
/// Returns the destination multicast UDP/IP endpoint for the given subject ID.
143146
/// The application should use this function when setting up subscription sockets or sending transfers.
144147
/// If the subject-ID exceeds the allowed range, the excessive bits are masked out.

0 commit comments

Comments
 (0)