refactor: remove typedefs, use struct/enum directly, fix 80-col violations
This commit is contained in:
parent
e6a2b2b2d4
commit
07cd155f3a
60 changed files with 193 additions and 183 deletions
6
Makefile
6
Makefile
|
|
@ -66,13 +66,13 @@ update-version-header:
|
|||
echo "#define PING_GIT_COMMIT \"$(GIT_COMMIT)\"" >> $$NEW_HEADER; \
|
||||
echo "#define PING_HAS_GIT_COMMIT $(HAS_GIT_COMMIT)" >> $$NEW_HEADER; \
|
||||
echo "" >> $$NEW_HEADER; \
|
||||
echo "typedef struct s_prog_name" >> $$NEW_HEADER; \
|
||||
echo "struct prog_name" >> $$NEW_HEADER; \
|
||||
echo "{" >> $$NEW_HEADER; \
|
||||
echo " char *alloc;" >> $$NEW_HEADER; \
|
||||
echo " const char *name;" >> $$NEW_HEADER; \
|
||||
echo "} t_prog_name;" >> $$NEW_HEADER; \
|
||||
echo "};" >> $$NEW_HEADER; \
|
||||
echo "" >> $$NEW_HEADER; \
|
||||
echo "extern t_prog_name g_prog_name;" >> $$NEW_HEADER; \
|
||||
echo "extern struct prog_name g_prog_name;" >> $$NEW_HEADER; \
|
||||
echo "" >> $$NEW_HEADER; \
|
||||
echo "#endif" >> $$NEW_HEADER; \
|
||||
if [ ! -f $(VERSION_HEADER) ] || ! cmp -s $$NEW_HEADER $(VERSION_HEADER); then \
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
#include <stddef.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
enum e_cli_code {
|
||||
enum cli_code {
|
||||
CLI_EXIT_SUCCESS = -1,
|
||||
CLI_SUCCESS = 0,
|
||||
CLI_ERROR = 1
|
||||
|
|
@ -14,7 +12,7 @@ enum e_cli_code {
|
|||
|
||||
typedef int (*t_option_handler)(const char *arg, void *config);
|
||||
|
||||
typedef enum e_option_arg_type
|
||||
enum option_arg_type
|
||||
{
|
||||
OPT_ARG_NONE = 0,
|
||||
OPT_ARG_INT,
|
||||
|
|
@ -23,20 +21,20 @@ typedef enum e_option_arg_type
|
|||
OPT_ARG_BYTES,
|
||||
OPT_ARG_TTL,
|
||||
OPT_ARG_STRING
|
||||
} t_option_arg_type;
|
||||
};
|
||||
|
||||
typedef struct s_option_descriptor
|
||||
struct option_descriptor
|
||||
{
|
||||
char short_opt;
|
||||
const char *long_opt;
|
||||
int has_arg;
|
||||
t_option_handler handler;
|
||||
t_option_arg_type arg_type;
|
||||
enum option_arg_type arg_type;
|
||||
const char *description;
|
||||
} t_option_descriptor;
|
||||
};
|
||||
|
||||
enum e_cli_code cli_parse(int argc, char **argv, void *config,
|
||||
const t_option_descriptor *opts, size_t nb_opts,
|
||||
enum cli_code cli_parse(int argc, char **argv, void *config,
|
||||
const struct option_descriptor *opts, size_t nb_opts,
|
||||
char *opt_str, struct option *long_opts);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
void print_help(void);
|
||||
void print_version(void);
|
||||
|
||||
enum e_cli_code error_unknown_opt(const char *current_opt);
|
||||
enum e_cli_code error_invalid_arg(const char *current_opt);
|
||||
enum e_cli_code error_invalid_opt(const char *current_opt);
|
||||
enum e_cli_code error_duplicate_opt(const char *current_opt);
|
||||
enum e_cli_code error_missing_dest(void);
|
||||
enum e_cli_code error_invalid_dest(void);
|
||||
enum cli_code error_unknown_opt(const char *current_opt);
|
||||
enum cli_code error_invalid_arg(const char *current_opt);
|
||||
enum cli_code error_invalid_opt(const char *current_opt);
|
||||
enum cli_code error_duplicate_opt(const char *current_opt);
|
||||
enum cli_code error_missing_dest(void);
|
||||
enum cli_code error_invalid_dest(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "cli.h"
|
||||
|
||||
extern const t_option_descriptor g_options[];
|
||||
extern const struct option_descriptor g_options[];
|
||||
|
||||
int cli_handle_count(const char *arg, void *config);
|
||||
int cli_handle_deadline(const char *arg, void *config);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@
|
|||
#include <stddef.h>
|
||||
#include "internal/ping/ping_state.h"
|
||||
|
||||
void ping_loop(t_ping_state *state, size_t payload_len);
|
||||
void ping_loop(struct ping_state *state, size_t payload_len);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@
|
|||
#include "ping/ft_ping.h"
|
||||
#include "internal/ping/ping_state.h"
|
||||
|
||||
void ping_output_start(const t_ping_config *config,
|
||||
void ping_output_start(const struct ping_config *config,
|
||||
struct in_addr dest, size_t payload_bytes);
|
||||
void ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
||||
int64_t rtt_ns, size_t payload_bytes, const t_ping_config *config);
|
||||
int64_t rtt_ns, size_t payload_bytes, const struct ping_config *config);
|
||||
void ping_output_error(const icmp_reply_t *reply,
|
||||
const icmp_offending_packet_t *offending,
|
||||
uint16_t seq, const t_ping_config *config);
|
||||
void ping_output_summary(const t_ping_state *state, struct in_addr dest);
|
||||
uint16_t seq, const struct ping_config *config);
|
||||
void ping_output_summary(const struct ping_state *state, struct in_addr dest);
|
||||
void ping_output_flood_dot(void);
|
||||
void ping_output_flood_erase(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
int cli_parse_inet_addr(const char *s, struct in_addr *out);
|
||||
int cli_parse_destinations(int argc, char **argv, int first_arg,
|
||||
t_ping_config *config);
|
||||
struct ping_config *config);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,19 +10,19 @@
|
|||
#include "internal/ping/stats.h"
|
||||
#include "internal/ping/tracker.h"
|
||||
|
||||
typedef struct s_ping_state {
|
||||
struct ping_state {
|
||||
icmp_handle_t *handle;
|
||||
const t_ping_config *config;
|
||||
const struct ping_config *config;
|
||||
struct in_addr dest;
|
||||
struct timespec start_time;
|
||||
struct timespec linger_start;
|
||||
uint16_t id;
|
||||
uint16_t seq;
|
||||
t_ping_tracker *tracker;
|
||||
t_ping_stats *stats;
|
||||
struct ping_tracker *tracker;
|
||||
struct ping_stats *stats;
|
||||
volatile sig_atomic_t send_flag;
|
||||
volatile sig_atomic_t stop_flag;
|
||||
size_t nb_errors;
|
||||
} t_ping_state;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include <sys/time.h>
|
||||
#include "internal/ping/ping_state.h"
|
||||
|
||||
void ping_scheduler_init(t_ping_state *state);
|
||||
void ping_scheduler_arm(const t_ping_config *config);
|
||||
void ping_scheduler_select_tv(const t_ping_config *config,
|
||||
void ping_scheduler_init(struct ping_state *state);
|
||||
void ping_scheduler_arm(const struct ping_config *config);
|
||||
void ping_scheduler_select_tv(const struct ping_config *config,
|
||||
struct timeval *tv);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@
|
|||
#include <stddef.h>
|
||||
#include "internal/ping/ping_state.h"
|
||||
|
||||
int ping_send_one(t_ping_state *state, size_t payload_len);
|
||||
int ping_send_one(struct ping_state *state, size_t payload_len);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct s_ping_stats {
|
||||
struct ping_stats {
|
||||
int64_t min_ns;
|
||||
int64_t max_ns;
|
||||
int64_t sum_ns;
|
||||
int64_t sum_sq_ns; /* sum of (rtt_ns / 1000)^2 in us^2, to avoid overflow */
|
||||
size_t count;
|
||||
} t_ping_stats;
|
||||
};
|
||||
|
||||
void ping_stats_init(t_ping_stats *s);
|
||||
void ping_stats_update(t_ping_stats *s, int64_t rtt_ns);
|
||||
void ping_stats_get(const t_ping_stats *s,
|
||||
double *min_ms, double *max_ms, double *avg_ms, double *mdev_ms);
|
||||
void ping_stats_init(struct ping_stats *s);
|
||||
void ping_stats_update(struct ping_stats *s, int64_t rtt_ns);
|
||||
void ping_stats_get(const struct ping_stats *s,
|
||||
double *min_ms, double *max_ms, double *avg_ms, double *mdev_ms);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,22 +8,22 @@
|
|||
|
||||
#define PING_TRACKER_SLOTS 128
|
||||
|
||||
typedef struct s_ping_tracker_slot {
|
||||
struct ping_tracker_slot {
|
||||
struct timespec ts;
|
||||
bool used;
|
||||
bool acked;
|
||||
} t_ping_tracker_slot;
|
||||
};
|
||||
|
||||
typedef struct s_ping_tracker {
|
||||
t_ping_tracker_slot slots[PING_TRACKER_SLOTS];
|
||||
struct ping_tracker {
|
||||
struct ping_tracker_slot slots[PING_TRACKER_SLOTS];
|
||||
size_t nb_sent;
|
||||
size_t nb_recv;
|
||||
} t_ping_tracker;
|
||||
};
|
||||
|
||||
void ping_tracker_init(t_ping_tracker *t);
|
||||
void ping_tracker_record_send(t_ping_tracker *t, uint16_t seq, const
|
||||
void ping_tracker_init(struct ping_tracker *t);
|
||||
void ping_tracker_record_send(struct ping_tracker *t, uint16_t seq, const
|
||||
struct timespec *ts);
|
||||
int64_t ping_tracker_record_recv(t_ping_tracker *t, uint16_t seq,
|
||||
int64_t ping_tracker_record_recv(struct ping_tracker *t, uint16_t seq,
|
||||
const struct timespec *ts);
|
||||
|
||||
#define ping_tracker_sent(t) ((t)->nb_sent)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
#include "../cli.h"
|
||||
#include "ping/ft_ping.h"
|
||||
|
||||
enum e_cli_code cli_parse_arguments(int argc, char **argv,
|
||||
t_ping_config *config);
|
||||
void cli_config_free(t_ping_config *config);
|
||||
enum cli_code cli_parse_arguments(int argc, char **argv,
|
||||
struct ping_config *config);
|
||||
void cli_config_free(struct ping_config *config);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@
|
|||
#include <stddef.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
typedef struct s_ping_config
|
||||
struct ping_config
|
||||
{
|
||||
/* Targets */
|
||||
struct in_addr *destinations;
|
||||
|
|
@ -23,6 +21,6 @@ typedef struct s_ping_config
|
|||
|
||||
/* Flags */
|
||||
uint8_t flags;
|
||||
} t_ping_config;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include "ping/ft_ping.h"
|
||||
|
||||
int ping_run(const t_ping_config *config);
|
||||
int ping_run(const struct ping_config *config);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,19 +13,19 @@
|
|||
|
||||
/* Forward declarations */
|
||||
static void build_long_options(struct option *long_opts, size_t nb_opts,
|
||||
const t_option_descriptor *src);
|
||||
static void build_optstr(char *dest, const t_option_descriptor *opts,
|
||||
const struct option_descriptor *src);
|
||||
static void build_optstr(char *dest, const struct option_descriptor *opts,
|
||||
size_t nb_opts);
|
||||
static const t_option_descriptor *find_option_handler(int opt,
|
||||
const t_option_descriptor *opts, size_t nb_opts);
|
||||
static const struct option_descriptor *find_option_handler(int opt,
|
||||
const struct option_descriptor *opts, size_t nb_opts);
|
||||
static int handle_one_option(int opt, char **argv, void *config,
|
||||
uint64_t *opt_tracker,
|
||||
const t_option_descriptor *opts, size_t nb_opts);
|
||||
const struct option_descriptor *opts, size_t nb_opts);
|
||||
/* ------------------- */
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
cli_parse(int argc, char **argv, void *config,
|
||||
const t_option_descriptor *opts, size_t nb_opts,
|
||||
const struct option_descriptor *opts, size_t nb_opts,
|
||||
char *opt_str, struct option *long_opts)
|
||||
{
|
||||
uint64_t tracker = 0;
|
||||
|
|
@ -39,13 +39,13 @@ cli_parse(int argc, char **argv, void *config,
|
|||
HANDLE_QUESTION_MARK(opt);
|
||||
res = handle_one_option(opt, argv, config, &tracker, opts, nb_opts);
|
||||
if (CLI_SUCCESS != res)
|
||||
return (enum e_cli_code)res;
|
||||
return (enum cli_code)res;
|
||||
}
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
build_optstr(char *dest, const t_option_descriptor *opts, size_t nb_opts)
|
||||
build_optstr(char *dest, const struct option_descriptor *opts, size_t nb_opts)
|
||||
{
|
||||
size_t str_i = 1;
|
||||
|
||||
|
|
@ -68,10 +68,10 @@ build_optstr(char *dest, const t_option_descriptor *opts, size_t nb_opts)
|
|||
static int
|
||||
handle_one_option(int opt, char **argv, void *config,
|
||||
uint64_t *opt_tracker,
|
||||
const t_option_descriptor *opts, size_t nb_opts)
|
||||
const struct option_descriptor *opts, size_t nb_opts)
|
||||
{
|
||||
const char *current_opt = argv[optind - 1];
|
||||
const t_option_descriptor *desc;
|
||||
const struct option_descriptor *desc;
|
||||
size_t bitmask_index;
|
||||
int res;
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ handle_one_option(int opt, char **argv, void *config,
|
|||
|
||||
static void
|
||||
build_long_options(struct option *long_opts, size_t nb_opts,
|
||||
const t_option_descriptor *src)
|
||||
const struct option_descriptor *src)
|
||||
{
|
||||
for (size_t i = 0; i < nb_opts; ++i) {
|
||||
long_opts[i].name = src[i].long_opt;
|
||||
|
|
@ -105,8 +105,9 @@ build_long_options(struct option *long_opts, size_t nb_opts,
|
|||
long_opts[nb_opts] = (struct option){0};
|
||||
}
|
||||
|
||||
static const t_option_descriptor *
|
||||
find_option_handler(int opt, const t_option_descriptor *opts, size_t nb_opts)
|
||||
static const struct option_descriptor *
|
||||
find_option_handler(int opt, const struct option_descriptor *opts,
|
||||
size_t nb_opts)
|
||||
{
|
||||
for (size_t i = 0; i < nb_opts; ++i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "ping/cli.h"
|
||||
|
||||
void
|
||||
cli_config_free(t_ping_config *config)
|
||||
cli_config_free(struct ping_config *config)
|
||||
{
|
||||
free(config->destinations);
|
||||
config->destinations = NULL;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
int
|
||||
cli_handle_count(const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
uint64_t count;
|
||||
|
||||
if (0 != cli_parse_uint64(arg, &count))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
int
|
||||
cli_handle_deadline(const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
float deadline;
|
||||
|
||||
if (0 != cli_parse_float(arg, &deadline))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#include "compiler.h"
|
||||
#include "ping/cli.h"
|
||||
#include "ping/ft_ping_flags.h"
|
||||
|
||||
int
|
||||
cli_handle_flood(__unused const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
SET_FLAG(config->flags, FLAG_FLOOD);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include "compiler.h"
|
||||
#include "ping/cli.h"
|
||||
#include "internal/cli/messages.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
int
|
||||
cli_handle_interval(const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
float interval;
|
||||
|
||||
if (0 != cli_parse_float(arg, &interval))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#include "compiler.h"
|
||||
#include "ping/cli.h"
|
||||
#include "ping/ft_ping_flags.h"
|
||||
|
||||
int
|
||||
cli_handle_quiet(__unused const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
SET_FLAG(config->flags, FLAG_QUIET);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
int
|
||||
cli_handle_size(const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
uint64_t size;
|
||||
|
||||
if (0 != cli_parse_uint64(arg, &size) || size > (65535 - 8))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
int
|
||||
cli_handle_timeout(const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
float TO;
|
||||
|
||||
if (0 != cli_parse_float(arg, &TO))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
int
|
||||
cli_handle_ttl(const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
uint64_t ttl;
|
||||
|
||||
if (0 != cli_parse_uint64(arg, &ttl) || ttl > 255)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#include "compiler.h"
|
||||
#include "ping/cli.h"
|
||||
#include "ping/ft_ping_flags.h"
|
||||
|
||||
int
|
||||
cli_handle_verbose(__unused const char *arg, void *config_void)
|
||||
{
|
||||
t_ping_config *config = (t_ping_config *)config_void;
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
SET_FLAG(config->flags, FLAG_VERBOSE);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include "compiler.h"
|
||||
#include "ping/cli.h"
|
||||
#include "internal/cli/messages.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#define X(short_opt, long_opt, has_arg, handler, arg_type, desc) \
|
||||
{ short_opt, long_opt, has_arg, handler, arg_type, desc },
|
||||
|
||||
const t_option_descriptor g_options[] = {
|
||||
const struct option_descriptor g_options[] = {
|
||||
CLI_OPTIONS_LIST
|
||||
{0, NULL, 0, NULL, OPT_ARG_NONE, NULL }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
void static inline print_suggest_help(void);
|
||||
/* -------------------- */
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
error_unknown_opt(const char *current_opt)
|
||||
{
|
||||
dprintf(STDERR_FILENO, "%s: unknown option -- '%s'\n",
|
||||
|
|
@ -19,7 +19,7 @@ error_unknown_opt(const char *current_opt)
|
|||
return CLI_ERROR;
|
||||
}
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
error_invalid_arg(const char *current_opt)
|
||||
{
|
||||
dprintf(STDERR_FILENO, "%s: option '%s' requires an argument\n",
|
||||
|
|
@ -28,7 +28,7 @@ error_invalid_arg(const char *current_opt)
|
|||
return CLI_ERROR;
|
||||
}
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
error_invalid_opt(const char *current_opt)
|
||||
{
|
||||
dprintf(STDERR_FILENO, "%s: invalid option '%s'\n",
|
||||
|
|
@ -37,7 +37,7 @@ error_invalid_opt(const char *current_opt)
|
|||
return CLI_ERROR;
|
||||
}
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
error_duplicate_opt(const char *current_opt)
|
||||
{
|
||||
dprintf(STDERR_FILENO, "%s: duplicate option '%s'\n",
|
||||
|
|
@ -46,7 +46,7 @@ error_duplicate_opt(const char *current_opt)
|
|||
return CLI_ERROR;
|
||||
}
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
error_missing_dest(void)
|
||||
{
|
||||
dprintf(STDERR_FILENO, "%s: usage error: Destination address required\n",
|
||||
|
|
@ -55,7 +55,7 @@ error_missing_dest(void)
|
|||
return CLI_ERROR;
|
||||
}
|
||||
|
||||
enum e_cli_code
|
||||
enum cli_code
|
||||
error_invalid_dest(void)
|
||||
{
|
||||
dprintf(STDERR_FILENO, "%s: unknown host\n", CMD_NAME);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include "internal/cli/options.h"
|
||||
|
||||
/* Forward declarations */
|
||||
static inline const char * option_arg_type_to_str(t_option_arg_type type);
|
||||
static inline const char * option_arg_type_to_str(enum option_arg_type type);
|
||||
/* -------------------- */
|
||||
|
||||
void
|
||||
|
|
@ -16,7 +16,7 @@ print_help(void)
|
|||
|
||||
for (size_t i = 0; i < CLI_OPT_LEN; ++i)
|
||||
{
|
||||
const t_option_descriptor *opt = &g_options[i];
|
||||
const struct option_descriptor *opt = &g_options[i];
|
||||
const char *argstr = option_arg_type_to_str(opt->arg_type);
|
||||
|
||||
printf(" -%c, --%-10s %-8s %s\n",
|
||||
|
|
@ -29,7 +29,7 @@ print_help(void)
|
|||
}
|
||||
|
||||
static inline const char *
|
||||
option_arg_type_to_str(t_option_arg_type type)
|
||||
option_arg_type_to_str(enum option_arg_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@
|
|||
#include "internal/cli/options.h"
|
||||
|
||||
/* Forward declaration */
|
||||
static void init_config(t_ping_config *config);
|
||||
static void init_config(struct ping_config *config);
|
||||
/* ------------------- */
|
||||
|
||||
enum e_cli_code
|
||||
cli_parse_arguments(int argc, char **argv, t_ping_config *config)
|
||||
enum cli_code
|
||||
cli_parse_arguments(int argc, char **argv, struct ping_config *config)
|
||||
{
|
||||
char opt_str[CLI_OPT_STR_LEN];
|
||||
struct option long_opts[CLI_OPT_LEN + 1];
|
||||
enum e_cli_code ret;
|
||||
enum cli_code ret;
|
||||
|
||||
init_config(config);
|
||||
ret = cli_parse(argc, argv, config, g_options, CLI_OPT_LEN,
|
||||
|
|
@ -27,9 +27,9 @@ cli_parse_arguments(int argc, char **argv, t_ping_config *config)
|
|||
}
|
||||
|
||||
static void
|
||||
init_config(t_ping_config *config)
|
||||
init_config(struct ping_config *config)
|
||||
{
|
||||
memset(config, 0, sizeof(t_ping_config));
|
||||
memset(config, 0, sizeof(struct ping_config));
|
||||
config->count = DEFAULT_COUNT;
|
||||
config->interval = DEFAULT_INTERVAL;
|
||||
config->ttl = DEFAULT_TTL;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@
|
|||
#include "internal/ping/parse_utils.h"
|
||||
|
||||
int
|
||||
cli_parse_destinations(int argc, char **argv, int first_arg, t_ping_config *config)
|
||||
cli_parse_destinations(int argc, char **argv, int first_arg,
|
||||
struct ping_config *config)
|
||||
{
|
||||
if (first_arg >= argc)
|
||||
return error_missing_dest();
|
||||
|
||||
config->nb_destinations = (size_t)(argc - first_arg);
|
||||
config->destinations = malloc(config->nb_destinations * sizeof(struct in_addr));
|
||||
config->destinations = malloc(config->nb_destinations
|
||||
* sizeof(struct in_addr));
|
||||
if (NULL == config->destinations)
|
||||
return CLI_ERROR;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,18 +10,20 @@
|
|||
/* Forward declarations */
|
||||
static int extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
||||
uint16_t *seq_out);
|
||||
static void handle_echo_reply(t_ping_state *state, const icmp_reply_t *reply);
|
||||
static void handle_echo_reply(struct ping_state *state,
|
||||
const icmp_reply_t *reply);
|
||||
static int extract_our_error(const icmp_reply_t *reply, uint16_t our_id,
|
||||
icmp_offending_packet_t *out, uint16_t *seq_out);
|
||||
static void handle_icmp_error(t_ping_state *state, const icmp_reply_t *reply);
|
||||
static void handle_icmp_error(struct ping_state *state,
|
||||
const icmp_reply_t *reply);
|
||||
/* -------------------- */
|
||||
|
||||
void
|
||||
ping_callback(const icmp_reply_t *reply, void *userdata)
|
||||
{
|
||||
t_ping_state *state;
|
||||
struct ping_state *state;
|
||||
|
||||
state = (t_ping_state *)userdata;
|
||||
state = (struct ping_state *)userdata;
|
||||
if (ICMP_TYPE_ECHO_REPLY == reply->type)
|
||||
handle_echo_reply(state, reply);
|
||||
else if (ICMP_TYPE_TIME_EXCEEDED == reply->type
|
||||
|
|
@ -45,7 +47,7 @@ extract_our_echo(const icmp_reply_t *reply, uint16_t our_id,
|
|||
}
|
||||
|
||||
static void
|
||||
handle_echo_reply(t_ping_state *state, const icmp_reply_t *reply)
|
||||
handle_echo_reply(struct ping_state *state, const icmp_reply_t *reply)
|
||||
{
|
||||
uint16_t seq;
|
||||
int64_t rtt;
|
||||
|
|
@ -78,7 +80,7 @@ extract_our_error(const icmp_reply_t *reply, uint16_t our_id,
|
|||
}
|
||||
|
||||
static void
|
||||
handle_icmp_error(t_ping_state *state, const icmp_reply_t *reply)
|
||||
handle_icmp_error(struct ping_state *state, const icmp_reply_t *reply)
|
||||
{
|
||||
icmp_offending_packet_t offending;
|
||||
uint16_t seq;
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@
|
|||
#include "internal/ping/scheduler.h"
|
||||
|
||||
/* Forward declarations */
|
||||
static int deadline_expired(const t_ping_state *state);
|
||||
static int linger_expired(const t_ping_state *state);
|
||||
static int should_stop(const t_ping_state *state);
|
||||
static int can_send_more(const t_ping_state *state);
|
||||
static void do_send(t_ping_state *state, size_t payload_len);
|
||||
static void try_recv(t_ping_state *state);
|
||||
static void handle_send_trigger(t_ping_state *state, size_t payload_len);
|
||||
static int deadline_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 do_send(struct ping_state *state, size_t payload_len);
|
||||
static void try_recv(struct ping_state *state);
|
||||
static void handle_send_trigger(struct ping_state *state, size_t payload_len);
|
||||
/* -------------------- */
|
||||
|
||||
void
|
||||
ping_loop(t_ping_state *state, size_t payload_len)
|
||||
ping_loop(struct ping_state *state, size_t payload_len)
|
||||
{
|
||||
do
|
||||
{
|
||||
|
|
@ -32,7 +32,7 @@ ping_loop(t_ping_state *state, size_t payload_len)
|
|||
}
|
||||
|
||||
static int
|
||||
deadline_expired(const t_ping_state *state)
|
||||
deadline_expired(const struct ping_state *state)
|
||||
{
|
||||
struct timespec now;
|
||||
double elapsed;
|
||||
|
|
@ -46,7 +46,7 @@ deadline_expired(const t_ping_state *state)
|
|||
}
|
||||
|
||||
static int
|
||||
linger_expired(const t_ping_state *state)
|
||||
linger_expired(const struct ping_state *state)
|
||||
{
|
||||
struct timespec now;
|
||||
double elapsed;
|
||||
|
|
@ -60,7 +60,7 @@ linger_expired(const t_ping_state *state)
|
|||
}
|
||||
|
||||
static int
|
||||
should_stop(const t_ping_state *state)
|
||||
should_stop(const struct ping_state *state)
|
||||
{
|
||||
size_t count;
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ should_stop(const t_ping_state *state)
|
|||
}
|
||||
|
||||
static int
|
||||
can_send_more(const t_ping_state *state)
|
||||
can_send_more(const struct ping_state *state)
|
||||
{
|
||||
size_t count;
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ can_send_more(const t_ping_state *state)
|
|||
}
|
||||
|
||||
static void
|
||||
do_send(t_ping_state *state, size_t payload_len)
|
||||
do_send(struct ping_state *state, size_t payload_len)
|
||||
{
|
||||
state->send_flag = 0;
|
||||
ping_send_one(state, payload_len);
|
||||
|
|
@ -96,7 +96,7 @@ do_send(t_ping_state *state, size_t payload_len)
|
|||
}
|
||||
|
||||
static void
|
||||
try_recv(t_ping_state *state)
|
||||
try_recv(struct ping_state *state)
|
||||
{
|
||||
int fd;
|
||||
fd_set rfds;
|
||||
|
|
@ -113,7 +113,7 @@ try_recv(t_ping_state *state)
|
|||
}
|
||||
|
||||
static void
|
||||
handle_send_trigger(t_ping_state *state, size_t payload_len)
|
||||
handle_send_trigger(struct ping_state *state, size_t payload_len)
|
||||
{
|
||||
if (!state->send_flag && !HAS_FLAG(state->config->flags, FLAG_FLOOD))
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@
|
|||
#include "internal/ping/loop.h"
|
||||
|
||||
/* Forward declarations */
|
||||
static int ping_one(const t_ping_config *config, struct in_addr dest,
|
||||
static int ping_one(const struct ping_config *config, struct in_addr dest,
|
||||
icmp_handle_t *handle);
|
||||
static void ping_init_state(t_ping_state *state, t_ping_stats *stats,
|
||||
t_ping_tracker *tracker, const t_ping_config *config, struct in_addr
|
||||
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 void ping_first_send(t_ping_state *state, size_t payload_len);
|
||||
static void ping_first_send(struct ping_state *state, size_t payload_len);
|
||||
/* -------------------- */
|
||||
|
||||
int
|
||||
ping_run(const t_ping_config *config)
|
||||
ping_run(const struct ping_config *config)
|
||||
{
|
||||
icmp_handle_t *handle;
|
||||
int ret;
|
||||
|
|
@ -46,12 +46,12 @@ ping_run(const t_ping_config *config)
|
|||
}
|
||||
|
||||
static int
|
||||
ping_one(const t_ping_config *config, struct in_addr dest,
|
||||
ping_one(const struct ping_config *config, struct in_addr dest,
|
||||
icmp_handle_t *handle)
|
||||
{
|
||||
t_ping_state state;
|
||||
t_ping_stats stats;
|
||||
t_ping_tracker tracker;
|
||||
struct ping_state state;
|
||||
struct ping_stats stats;
|
||||
struct ping_tracker tracker;
|
||||
size_t payload_len;
|
||||
|
||||
ping_init_state(&state, &stats, &tracker, config, dest, handle);
|
||||
|
|
@ -65,8 +65,8 @@ ping_one(const t_ping_config *config, struct in_addr dest,
|
|||
}
|
||||
|
||||
static void
|
||||
ping_init_state(t_ping_state *state, t_ping_stats *stats,
|
||||
t_ping_tracker *tracker, const t_ping_config *config,
|
||||
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)
|
||||
{
|
||||
ping_stats_init(stats);
|
||||
|
|
@ -82,7 +82,7 @@ ping_init_state(t_ping_state *state, t_ping_stats *stats,
|
|||
}
|
||||
|
||||
static void
|
||||
ping_first_send(t_ping_state *state, size_t payload_len)
|
||||
ping_first_send(struct ping_state *state, size_t payload_len)
|
||||
{
|
||||
ping_send_one(state, payload_len);
|
||||
if (HAS_FLAG(state->config->flags, FLAG_FLOOD))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "internal/ping/tracker.h"
|
||||
|
||||
int
|
||||
ping_send_one(t_ping_state *state, size_t payload_len)
|
||||
ping_send_one(struct ping_state *state, size_t payload_len)
|
||||
{
|
||||
struct timespec ts;
|
||||
uint8_t payload[MAX_PACKET_SIZE];
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
|
||||
/* Forward declarations */
|
||||
static int init_prog_name(char *name);
|
||||
t_prog_name g_prog_name = {NULL, NULL};
|
||||
struct prog_name g_prog_name = {NULL, NULL};
|
||||
/* -------------------- */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
t_ping_config config;
|
||||
struct ping_config config;
|
||||
int ret;
|
||||
|
||||
if (0 != init_prog_name(argv[0]))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#include "icmp.h"
|
||||
#include "icmp_types.h"
|
||||
#include "internal/ping/output.h"
|
||||
|
|
@ -12,7 +14,7 @@ static const char *error_msg_for(const icmp_reply_t *reply);
|
|||
void
|
||||
ping_output_error(const icmp_reply_t *reply,
|
||||
__unused const icmp_offending_packet_t *offending,
|
||||
uint16_t seq, __unused const t_ping_config *config)
|
||||
uint16_t seq, __unused const struct ping_config *config)
|
||||
{
|
||||
char from_str[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &reply->from, from_str, sizeof(from_str));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
void
|
||||
ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
||||
int64_t rtt_ns, size_t payload_bytes, const t_ping_config *config)
|
||||
int64_t rtt_ns, size_t payload_bytes, const struct ping_config *config)
|
||||
{
|
||||
char from_str[INET_ADDRSTRLEN];
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "internal/ping/output.h"
|
||||
|
||||
void
|
||||
ping_output_start(const t_ping_config *config,
|
||||
ping_output_start(const struct ping_config *config,
|
||||
struct in_addr dest, size_t payload_bytes)
|
||||
{
|
||||
char dest_str[INET_ADDRSTRLEN];
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
/* Forward declarations */
|
||||
static void print_loss_line(size_t sent, size_t ok_recv, size_t errors);
|
||||
static void print_rtt_line(const t_ping_stats *stats);
|
||||
static void print_rtt_line(const struct ping_stats *stats);
|
||||
/* -------------------- */
|
||||
|
||||
void
|
||||
ping_output_summary(const t_ping_state *state, struct in_addr dest)
|
||||
ping_output_summary(const struct ping_state *state, struct in_addr dest)
|
||||
{
|
||||
char dest_str[INET_ADDRSTRLEN];
|
||||
size_t sent;
|
||||
|
|
@ -43,7 +43,7 @@ print_loss_line(size_t sent, size_t ok_recv, size_t errors)
|
|||
}
|
||||
|
||||
static void
|
||||
print_rtt_line(const t_ping_stats *stats)
|
||||
print_rtt_line(const struct ping_stats *stats)
|
||||
{
|
||||
double min_ms;
|
||||
double max_ms;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#include "ping/ft_ping_flags.h"
|
||||
#include "internal/ping/scheduler.h"
|
||||
|
||||
|
|
@ -10,10 +12,10 @@ static void sigint_handler(int sig);
|
|||
static void install_signal(int signum, void (*handler)(int));
|
||||
/* -------------------- */
|
||||
|
||||
static t_ping_state *g_state = NULL;
|
||||
static struct ping_state *g_state = NULL;
|
||||
|
||||
void
|
||||
ping_scheduler_init(t_ping_state *state)
|
||||
ping_scheduler_init(struct ping_state *state)
|
||||
{
|
||||
g_state = state;
|
||||
install_signal(SIGALRM, sigalrm_handler);
|
||||
|
|
@ -21,7 +23,7 @@ ping_scheduler_init(t_ping_state *state)
|
|||
}
|
||||
|
||||
void
|
||||
ping_scheduler_arm(const t_ping_config *config)
|
||||
ping_scheduler_arm(const struct ping_config *config)
|
||||
{
|
||||
struct itimerval itv;
|
||||
double interval;
|
||||
|
|
@ -38,7 +40,7 @@ ping_scheduler_arm(const t_ping_config *config)
|
|||
}
|
||||
|
||||
void
|
||||
ping_scheduler_select_tv(const t_ping_config *config, struct timeval *tv)
|
||||
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
||||
{
|
||||
tv->tv_usec = 0;
|
||||
tv->tv_sec = (long)config->timeout * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
#include "internal/ping/stats.h"
|
||||
|
||||
/* Forward declarations */
|
||||
static double compute_mdev_ms(const t_ping_stats *s, double avg_ms);
|
||||
static double compute_mdev_ms(const struct ping_stats *s, double avg_ms);
|
||||
/* -------------------- */
|
||||
|
||||
void
|
||||
ping_stats_init(t_ping_stats *s)
|
||||
ping_stats_init(struct ping_stats *s)
|
||||
{
|
||||
s->min_ns = INT64_MAX;
|
||||
s->max_ns = INT64_MIN;
|
||||
|
|
@ -18,7 +18,7 @@ ping_stats_init(t_ping_stats *s)
|
|||
}
|
||||
|
||||
void
|
||||
ping_stats_update(t_ping_stats *s, int64_t rtt_ns)
|
||||
ping_stats_update(struct ping_stats *s, int64_t rtt_ns)
|
||||
{
|
||||
int64_t rtt_us;
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ ping_stats_update(t_ping_stats *s, int64_t rtt_ns)
|
|||
}
|
||||
|
||||
void
|
||||
ping_stats_get(const t_ping_stats *s,
|
||||
ping_stats_get(const struct ping_stats *s,
|
||||
double *min_ms, double *max_ms, double *avg_ms, double *mdev_ms)
|
||||
{
|
||||
if (0 == s->count)
|
||||
|
|
@ -51,7 +51,7 @@ ping_stats_get(const t_ping_stats *s,
|
|||
}
|
||||
|
||||
static double
|
||||
compute_mdev_ms(const t_ping_stats *s, double avg_ms)
|
||||
compute_mdev_ms(const struct ping_stats *s, double avg_ms)
|
||||
{
|
||||
double avg_us;
|
||||
double var_us2;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "internal/ping/tracker.h"
|
||||
|
||||
void
|
||||
ping_tracker_init(t_ping_tracker *t)
|
||||
ping_tracker_init(struct ping_tracker *t)
|
||||
{
|
||||
memset(t, 0, sizeof(*t));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
#include "internal/ping/tracker.h"
|
||||
|
||||
int64_t
|
||||
ping_tracker_record_recv(t_ping_tracker *t, uint16_t seq,
|
||||
ping_tracker_record_recv(struct ping_tracker *t, uint16_t seq,
|
||||
const struct timespec *ts)
|
||||
{
|
||||
t_ping_tracker_slot *slot;
|
||||
struct ping_tracker_slot *slot;
|
||||
|
||||
slot = &t->slots[seq % PING_TRACKER_SLOTS];
|
||||
if (false == slot->used || true == slot->acked)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
#include "internal/ping/tracker.h"
|
||||
|
||||
void
|
||||
ping_tracker_record_send(t_ping_tracker *t, uint16_t seq,
|
||||
ping_tracker_record_send(struct ping_tracker *t, uint16_t seq,
|
||||
const struct timespec *ts)
|
||||
{
|
||||
t_ping_tracker_slot *slot;
|
||||
struct ping_tracker_slot *slot;
|
||||
|
||||
slot = &t->slots[seq % PING_TRACKER_SLOTS];
|
||||
slot->ts = *ts;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: basic test */
|
||||
Test(cli_handle_count, valid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "42";
|
||||
int ret = cli_handle_count(arg, &config);
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ Test(cli_handle_count, valid_number)
|
|||
/* Test 2: invalid number */
|
||||
Test(cli_handle_count, invalid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "-42";
|
||||
int ret = cli_handle_count(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* Test 1: test flag*/
|
||||
Test(handle_flood, flag_test)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "";
|
||||
const int ret = cli_handle_flood(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: exit code test */
|
||||
Test(handle_help, exit_code)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "";
|
||||
int ret = cli_handle_help(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: basic test */
|
||||
Test(cli_handle_interval, valid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = ".42";
|
||||
int ret = cli_handle_interval(arg, &config);
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ Test(cli_handle_interval, valid_number)
|
|||
/* Test 2: invalid number */
|
||||
Test(cli_handle_interval, invalid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "-42";
|
||||
int ret = cli_handle_interval(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* Test 1: test flag*/
|
||||
Test(handle_quiet, flag_test)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "";
|
||||
const int ret = cli_handle_quiet(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: basic test */
|
||||
Test(cli_handle_size, valid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "65527";
|
||||
int ret = cli_handle_size(arg, &config);
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ Test(cli_handle_size, valid_number)
|
|||
/* Test 2: invalid number */
|
||||
Test(cli_handle_size, invalid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "-42";
|
||||
int ret = cli_handle_size(arg, &config);
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ Test(cli_handle_size, invalid_number)
|
|||
/* Test 3: max test */
|
||||
Test(cli_handle_size, limit_test)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "65528";
|
||||
int ret = cli_handle_size(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: basic test */
|
||||
Test(cli_handle_timeout, valid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = ".42";
|
||||
int ret = cli_handle_timeout(arg, &config);
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ Test(cli_handle_timeout, valid_number)
|
|||
/* Test 2: invalid number */
|
||||
Test(cli_handle_timeout, invalid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "-42";
|
||||
int ret = cli_handle_timeout(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: basic test */
|
||||
Test(cli_handle_ttl, valid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "255";
|
||||
int ret = cli_handle_ttl(arg, &config);
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ Test(cli_handle_ttl, valid_number)
|
|||
/* Test 2: invalid number */
|
||||
Test(cli_handle_ttl, invalid_number)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "-1";
|
||||
int ret = cli_handle_ttl(arg, &config);
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ Test(cli_handle_ttl, invalid_number)
|
|||
/* Test 3: max test */
|
||||
Test(cli_handle_ttl, limit_test)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "256";
|
||||
int ret = cli_handle_ttl(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* Test 1: test flag*/
|
||||
Test(handle_verbose, flag_test)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "";
|
||||
const int ret = cli_handle_verbose(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
/* Test 1: exit code test */
|
||||
Test(handle_version, exit_code)
|
||||
{
|
||||
t_ping_config config = {0};
|
||||
struct ping_config config = {0};
|
||||
const char *arg = "";
|
||||
int ret = cli_handle_version(arg, &config);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
Test(ping_stats, init_neutral)
|
||||
{
|
||||
t_ping_stats s;
|
||||
struct ping_stats s;
|
||||
double min_ms, max_ms, avg_ms, mdev_ms;
|
||||
|
||||
ping_stats_init(&s);
|
||||
|
|
@ -19,7 +19,7 @@ Test(ping_stats, init_neutral)
|
|||
|
||||
Test(ping_stats, single_update)
|
||||
{
|
||||
t_ping_stats s;
|
||||
struct ping_stats s;
|
||||
double min_ms, max_ms, avg_ms, mdev_ms;
|
||||
|
||||
ping_stats_init(&s);
|
||||
|
|
@ -33,7 +33,7 @@ Test(ping_stats, single_update)
|
|||
|
||||
Test(ping_stats, multiple_updates)
|
||||
{
|
||||
t_ping_stats s;
|
||||
struct ping_stats s;
|
||||
double min_ms, max_ms, avg_ms, mdev_ms;
|
||||
|
||||
ping_stats_init(&s);
|
||||
|
|
@ -49,7 +49,7 @@ Test(ping_stats, multiple_updates)
|
|||
|
||||
Test(ping_stats, identical_values_mdev_zero)
|
||||
{
|
||||
t_ping_stats s;
|
||||
struct ping_stats s;
|
||||
double min_ms, max_ms, avg_ms, mdev_ms;
|
||||
|
||||
ping_stats_init(&s);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ make_ts(long sec, long nsec)
|
|||
|
||||
Test(ping_tracker, init)
|
||||
{
|
||||
t_ping_tracker t;
|
||||
struct ping_tracker t;
|
||||
|
||||
ping_tracker_init(&t);
|
||||
cr_assert_eq(ping_tracker_sent(&t), (size_t)0);
|
||||
|
|
@ -24,7 +24,7 @@ Test(ping_tracker, init)
|
|||
|
||||
Test(ping_tracker, basic_send_recv)
|
||||
{
|
||||
t_ping_tracker t;
|
||||
struct ping_tracker t;
|
||||
struct timespec ts_send;
|
||||
struct timespec ts_recv;
|
||||
int64_t rtt;
|
||||
|
|
@ -42,7 +42,7 @@ Test(ping_tracker, basic_send_recv)
|
|||
|
||||
Test(ping_tracker, double_recv_ignored)
|
||||
{
|
||||
t_ping_tracker t;
|
||||
struct ping_tracker t;
|
||||
struct timespec ts_send;
|
||||
struct timespec ts_recv;
|
||||
int64_t rtt;
|
||||
|
|
@ -60,7 +60,7 @@ Test(ping_tracker, double_recv_ignored)
|
|||
|
||||
Test(ping_tracker, unknown_seq_returns_minus_one)
|
||||
{
|
||||
t_ping_tracker t;
|
||||
struct ping_tracker t;
|
||||
struct timespec ts;
|
||||
int64_t rtt;
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ Test(ping_tracker, unknown_seq_returns_minus_one)
|
|||
|
||||
Test(ping_tracker, wraparound_seq)
|
||||
{
|
||||
t_ping_tracker t;
|
||||
struct ping_tracker t;
|
||||
struct timespec ts_send;
|
||||
struct timespec ts_recv;
|
||||
int64_t rtt;
|
||||
|
|
@ -88,7 +88,7 @@ Test(ping_tracker, wraparound_seq)
|
|||
|
||||
Test(ping_tracker, lost_count)
|
||||
{
|
||||
t_ping_tracker t;
|
||||
struct ping_tracker t;
|
||||
struct timespec ts;
|
||||
|
||||
ping_tracker_init(&t);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <criterion/criterion.h>
|
||||
#include "version_gen.h"
|
||||
|
||||
t_prog_name g_prog_name = { NULL, NULL };
|
||||
struct prog_name g_prog_name = { NULL, NULL };
|
||||
|
||||
Test(dummy, always_pass)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue