style: cleanup
This commit is contained in:
parent
b75f2964e5
commit
93857f1ab0
3 changed files with 22 additions and 23 deletions
|
|
@ -7,12 +7,13 @@
|
||||||
#include "internal/ping/scheduler.h"
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int timeout_expired(const struct ping_state *state);
|
static int timeout_expired(const struct ping_state *state);
|
||||||
static int linger_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 should_stop(const struct ping_state *state);
|
||||||
static int can_send_more(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 try_recv(struct ping_state *state);
|
||||||
static void handle_send_trigger(struct ping_state *state, size_t payload_len);
|
static void handle_send_trigger(struct ping_state *state, size_t
|
||||||
|
payload_len);
|
||||||
/* -------------------- */
|
/* -------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -48,9 +49,8 @@ linger_expired(const struct ping_state *state)
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
double elapsed;
|
double elapsed;
|
||||||
|
|
||||||
if (0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
|
if ((0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
|
||||||
return 0;
|
|| 0!= icmp_get_time(&now))
|
||||||
if (0 != icmp_get_time(&now))
|
|
||||||
return 0;
|
return 0;
|
||||||
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
||||||
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
||||||
|
|
@ -62,11 +62,9 @@ should_stop(const struct ping_state *state)
|
||||||
{
|
{
|
||||||
size_t count;
|
size_t count;
|
||||||
|
|
||||||
if (state->stop_flag)
|
if (state->stop_flag
|
||||||
return 1;
|
|| timeout_expired(state)
|
||||||
if (timeout_expired(state))
|
|| linger_expired(state))
|
||||||
return 1;
|
|
||||||
if (linger_expired(state))
|
|
||||||
return 1;
|
return 1;
|
||||||
count = state->config->count;
|
count = state->config->count;
|
||||||
if (0 != count && state->tracker->nb_recv >= count)
|
if (0 != count && state->tracker->nb_recv >= count)
|
||||||
|
|
@ -74,7 +72,7 @@ should_stop(const struct ping_state *state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static inline int
|
||||||
can_send_more(const struct ping_state *state)
|
can_send_more(const struct ping_state *state)
|
||||||
{
|
{
|
||||||
size_t count;
|
size_t count;
|
||||||
|
|
|
||||||
|
|
@ -52,22 +52,24 @@ ping_create_handle(const struct ping_config *config)
|
||||||
{
|
{
|
||||||
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
|
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
|
||||||
g_prog_name);
|
g_prog_name);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (HAS_FLAG(config->flags, FLAG_DONT_FRAGMENT)
|
if (HAS_FLAG(config->flags, FLAG_DONT_FRAGMENT)
|
||||||
&& 0 != icmp_set_dont_fragment(handle))
|
&& 0 != icmp_set_dont_fragment(handle))
|
||||||
{
|
{
|
||||||
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
|
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
|
||||||
icmp_destroy(handle);
|
goto cleanup;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
if (0 != config->tos && 0 != icmp_set_tos(handle, config->tos))
|
if (0 != config->tos && 0 != icmp_set_tos(handle, config->tos))
|
||||||
{
|
{
|
||||||
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
|
dprintf(STDERR_FILENO, "%s: %s\n", g_prog_name, icmp_strerror(handle));
|
||||||
icmp_destroy(handle);
|
goto cleanup;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
return handle;
|
return handle;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
icmp_destroy(handle);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,8 @@ extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
uint16_t seq;
|
uint16_t seq;
|
||||||
|
|
||||||
if (0 > icmp_reply_id_seq(reply, &id, &seq))
|
if ((0 > icmp_reply_id_seq(reply, &id, &seq))
|
||||||
return 0;
|
|| ((our_id != id || reply->from.s_addr != dest.s_addr)))
|
||||||
if (our_id != id || reply->from.s_addr != dest.s_addr)
|
|
||||||
return 0;
|
return 0;
|
||||||
*seq_out = seq;
|
*seq_out = seq;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue