style: cleanup

This commit is contained in:
lohhiiccc 2026-04-27 16:08:56 +02:00
parent b75f2964e5
commit 93857f1ab0
3 changed files with 22 additions and 23 deletions

View file

@ -7,12 +7,13 @@
#include "internal/ping/scheduler.h"
/* Forward declarations */
static int timeout_expired(const struct ping_state *state);
static int linger_expired(const struct ping_state *state);
static int should_stop(const struct ping_state *state);
static int can_send_more(const struct ping_state *state);
static void try_recv(struct ping_state *state);
static void handle_send_trigger(struct ping_state *state, size_t payload_len);
static int timeout_expired(const struct ping_state *state);
static int linger_expired(const struct ping_state *state);
static int should_stop(const struct ping_state *state);
static inline int can_send_more(const struct ping_state *state);
static void try_recv(struct ping_state *state);
static void handle_send_trigger(struct ping_state *state, size_t
payload_len);
/* -------------------- */
void
@ -48,9 +49,8 @@ linger_expired(const struct ping_state *state)
struct timespec now;
double elapsed;
if (0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
return 0;
if (0 != icmp_get_time(&now))
if ((0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
|| 0!= icmp_get_time(&now))
return 0;
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
@ -62,11 +62,9 @@ should_stop(const struct ping_state *state)
{
size_t count;
if (state->stop_flag)
return 1;
if (timeout_expired(state))
return 1;
if (linger_expired(state))
if (state->stop_flag
|| timeout_expired(state)
|| linger_expired(state))
return 1;
count = state->config->count;
if (0 != count && state->tracker->nb_recv >= count)
@ -74,7 +72,7 @@ should_stop(const struct ping_state *state)
return 0;
}
static int
static inline int
can_send_more(const struct ping_state *state)
{
size_t count;

View file

@ -52,22 +52,24 @@ ping_create_handle(const struct ping_config *config)
{
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
g_prog_name);
return NULL;
goto cleanup;
}
if (HAS_FLAG(config->flags, FLAG_DONT_FRAGMENT)
&& 0 != icmp_set_dont_fragment(handle))
{
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
icmp_destroy(handle);
return NULL;
goto cleanup;
}
if (0 != config->tos && 0 != icmp_set_tos(handle, config->tos))
{
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
icmp_destroy(handle);
return NULL;
goto cleanup;
}
return handle;
cleanup:
icmp_destroy(handle);
return NULL;
}
static int

View file

@ -47,9 +47,8 @@ extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
uint16_t id;
uint16_t seq;
if (0 > icmp_reply_id_seq(reply, &id, &seq))
return 0;
if (our_id != id || reply->from.s_addr != dest.s_addr)
if ((0 > icmp_reply_id_seq(reply, &id, &seq))
|| ((our_id != id || reply->from.s_addr != dest.s_addr)))
return 0;
*seq_out = seq;
return 1;