Compare commits

..

No commits in common. "606069df824a535e1ee759246c47d6823dc4c1ef" and "ce8883d6cd37bc14bb2f7aaf9ae4bd03ed4a64ab" have entirely different histories.

11 changed files with 21 additions and 87 deletions

View file

@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
net-tools Copyright (C) 2026 lohhiiccc
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

View file

@ -109,14 +109,6 @@ enum {
OPT_ARG_NONE, \
"Set the Don't Fragment bit" \
) \
X( \
'l', \
"preload", \
required_argument, \
cli_handle_preload, \
OPT_ARG_UINT, \
"Send N packets in burst before normal loop" \
) \
X( \
'p', \
"pattern", \

View file

@ -6,7 +6,6 @@
extern const struct option_descriptor g_options[];
int cli_handle_count(const char *arg, void *config);
int cli_handle_preload(const char *arg, void *config);
int cli_handle_pattern(const char *arg, void *config);
int cli_handle_dont_fragment(const char *arg, void *config);
int cli_handle_deadline(const char *arg, void *config);

View file

@ -3,7 +3,6 @@
/* Default configuration values */
#define DEFAULT_COUNT 0
#define DEFAULT_PRELOAD 1
#define DEFAULT_INTERVAL 1.0
#define DEFAULT_TTL 64
#define DEFAULT_PACKET_SIZE 56

View file

@ -16,7 +16,6 @@ struct ping_config
/* Options */
uint64_t count;
uint64_t preload;
double interval;
uint8_t ttl;
size_t packet_size;

2
libcli

@ -1 +1 @@
Subproject commit d39210fe74135e806adba7a6ea18696a901ba2d0
Subproject commit ad6a542969dda29afe5431d0e674eca8d8794141

@ -1 +1 @@
Subproject commit e6693c97cc22b82adc3be85c72a5d5f655c69eb1
Subproject commit a9bdaf33f22b60b8643871b2522721cd041ac885

View file

@ -44,7 +44,6 @@ FORCE:
libping_core_la_SOURCES = \
cli/parse.c \
cli/handlers/handle_count.c \
cli/handlers/handle_preload.c \
cli/handlers/handle_pattern.c \
cli/handlers/handle_dont_fragment.c \
cli/handlers/handle_deadline.c \

View file

@ -1,14 +0,0 @@
#include "ping/cli.h"
#include "internal/cli/parse_utils.h"
int
cli_handle_preload(const char *arg, void *config_void)
{
struct ping_config *config = (struct ping_config *)config_void;
uint64_t preload;
if (0 != cli_parse_uint64(arg, &preload))
return CLI_ERROR;
config->preload = preload;
return CLI_SUCCESS;
}

View file

@ -31,7 +31,6 @@ init_config(struct ping_config *config)
{
memset(config, 0, sizeof(struct ping_config));
config->count = DEFAULT_COUNT;
config->preload = DEFAULT_PRELOAD;
config->interval = DEFAULT_INTERVAL;
config->ttl = DEFAULT_TTL;
config->packet_size = DEFAULT_PACKET_SIZE;

View file

@ -1,4 +1,3 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
@ -10,59 +9,47 @@
#include "internal/ping/loop.h"
/* Forward declarations */
static icmp_handle_t *ping_create_handle(const struct ping_config *config);
static int ping_one(const struct ping_config *config, struct destinations
*dest, icmp_handle_t *handle);
static int ping_one(const struct ping_config *config,
struct destinations *dest, icmp_handle_t *handle);
static void ping_init_state(struct ping_state *state, struct ping_stats *stats,
struct ping_tracker *tracker, const struct ping_config *config,
struct in_addr dest, icmp_handle_t *handle);
static int ping_preload(struct ping_state *state, size_t payload_len);
/* -------------------- */
int
ping_run(const struct ping_config *config)
{
icmp_handle_t *handle;
int ret = 0;
size_t i = 0;
int ret = 0 ;
size_t i = 0 ;
if (0 == config->nb_destinations)
return 1;
handle = ping_create_handle(config);
handle = icmp_create();
if (NULL == handle)
{
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
g_prog_name);
return 1;
}
if (HAS_FLAG(config->flags, FLAG_DONT_FRAGMENT)
&& 0 != icmp_set_dont_fragment(handle))
{
ret = 1;
goto cleanup;
}
while (i < config->nb_destinations)
{
if (0 != ping_one(config, &config->destinations[i], handle))
ret = 1;
i++;
}
cleanup:
icmp_destroy(handle);
return ret;
}
static icmp_handle_t *
ping_create_handle(const struct ping_config *config)
{
icmp_handle_t *handle;
handle = icmp_create();
if (NULL == handle)
{
dprintf(STDERR_FILENO, "%s: requires CAP_NET_RAW or root privileges\n",
g_prog_name);
return NULL;
}
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;
}
return handle;
}
static int
ping_one(const struct ping_config *config, struct destinations *dest,
icmp_handle_t *handle)
@ -75,14 +62,9 @@ ping_one(const struct ping_config *config, struct destinations *dest,
ping_init_state(&state, &stats, &tracker, config, dest->ip, handle);
payload_len = config->packet_size;
if (0 != ping_scheduler_init(&state))
{
dprintf(STDERR_FILENO, "%s: sigaction: %s\n",
g_prog_name, strerror(errno));
return 1;
}
ping_output_start(config, dest, payload_len);
if (0 != ping_preload(&state, payload_len))
return 1;
do_send(&state, payload_len);
ping_loop(&state, payload_len);
ping_output_summary(&state, dest);
return tracker.nb_recv <= state.nb_errors;
@ -104,24 +86,3 @@ ping_init_state(struct ping_state *state, struct ping_stats *stats,
state->handle = handle;
icmp_get_time(&state->start_time);
}
static int
ping_preload(struct ping_state *state, size_t payload_len)
{
const struct ping_config *config = state->config;
uint64_t i = 0;
while (i < config->preload && (0 == config->count ||
state->tracker->nb_sent < config->count))
{
do_send(state, payload_len);
i++;
}
if (0 == config->preload && 0 != ping_scheduler_arm(config))
{
dprintf(STDERR_FILENO, "%s: setitimer: %s\n",
g_prog_name, strerror(errno));
return 1;
}
return 0;
}