style: fix struct/variable alignment and wrap indentation
This commit is contained in:
parent
07cd155f3a
commit
5a8671bdde
22 changed files with 64 additions and 64 deletions
|
|
@ -25,16 +25,16 @@ enum option_arg_type
|
|||
|
||||
struct option_descriptor
|
||||
{
|
||||
char short_opt;
|
||||
const char *long_opt;
|
||||
int has_arg;
|
||||
t_option_handler handler;
|
||||
char short_opt;
|
||||
const char *long_opt;
|
||||
int has_arg;
|
||||
t_option_handler handler;
|
||||
enum option_arg_type arg_type;
|
||||
const char *description;
|
||||
const char *description;
|
||||
};
|
||||
|
||||
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);
|
||||
const struct option_descriptor *opts, size_t nb_opts,
|
||||
char *opt_str, struct option *long_opts);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
struct ping_config *config);
|
||||
struct ping_config *config);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@
|
|||
#include "internal/ping/tracker.h"
|
||||
|
||||
struct ping_state {
|
||||
icmp_handle_t *handle;
|
||||
icmp_handle_t *handle;
|
||||
const struct ping_config *config;
|
||||
struct in_addr dest;
|
||||
struct timespec start_time;
|
||||
struct timespec linger_start;
|
||||
uint16_t id;
|
||||
uint16_t seq;
|
||||
struct ping_tracker *tracker;
|
||||
struct ping_stats *stats;
|
||||
volatile sig_atomic_t send_flag;
|
||||
volatile sig_atomic_t stop_flag;
|
||||
size_t nb_errors;
|
||||
struct in_addr dest;
|
||||
struct timespec start_time;
|
||||
struct timespec linger_start;
|
||||
uint16_t id;
|
||||
uint16_t seq;
|
||||
struct ping_tracker *tracker;
|
||||
struct ping_stats *stats;
|
||||
volatile sig_atomic_t send_flag;
|
||||
volatile sig_atomic_t stop_flag;
|
||||
size_t nb_errors;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ struct ping_tracker_slot {
|
|||
|
||||
struct ping_tracker {
|
||||
struct ping_tracker_slot slots[PING_TRACKER_SLOTS];
|
||||
size_t nb_sent;
|
||||
size_t nb_recv;
|
||||
size_t nb_sent;
|
||||
size_t nb_recv;
|
||||
};
|
||||
|
||||
void ping_tracker_init(struct ping_tracker *t);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "ping/ft_ping.h"
|
||||
|
||||
enum cli_code cli_parse_arguments(int argc, char **argv,
|
||||
struct ping_config *config);
|
||||
struct ping_config *config);
|
||||
void cli_config_free(struct ping_config *config);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,25 +8,25 @@
|
|||
#define HANDLE_QUESTION_MARK(opt) \
|
||||
do { \
|
||||
if (opt == '?' && (optopt) == '?') \
|
||||
opt = 'h'; \
|
||||
opt = 'h'; \
|
||||
} while (0)
|
||||
|
||||
/* Forward declarations */
|
||||
static void build_long_options(struct option *long_opts, size_t nb_opts,
|
||||
const struct option_descriptor *src);
|
||||
const struct option_descriptor *src);
|
||||
static void build_optstr(char *dest, const struct option_descriptor *opts,
|
||||
size_t nb_opts);
|
||||
size_t nb_opts);
|
||||
static const struct option_descriptor *find_option_handler(int opt,
|
||||
const struct option_descriptor *opts, size_t nb_opts);
|
||||
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 struct option_descriptor *opts, size_t nb_opts);
|
||||
uint64_t *opt_tracker,
|
||||
const struct 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)
|
||||
const struct option_descriptor *opts, size_t nb_opts,
|
||||
char *opt_str, struct option *long_opts)
|
||||
{
|
||||
uint64_t tracker = 0;
|
||||
int opt;
|
||||
|
|
@ -67,13 +67,13 @@ build_optstr(char *dest, 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 struct option_descriptor *opts, size_t nb_opts)
|
||||
uint64_t *opt_tracker,
|
||||
const struct option_descriptor *opts, size_t nb_opts)
|
||||
{
|
||||
const char *current_opt = argv[optind - 1];
|
||||
const char *current_opt = argv[optind - 1];
|
||||
const struct option_descriptor *desc;
|
||||
size_t bitmask_index;
|
||||
int res;
|
||||
size_t bitmask_index;
|
||||
int res;
|
||||
|
||||
if ('?' == opt)
|
||||
return error_unknown_opt(current_opt);
|
||||
|
|
@ -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 struct 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;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ int
|
|||
cli_handle_count(const char *arg, void *config_void)
|
||||
{
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
uint64_t count;
|
||||
uint64_t count;
|
||||
|
||||
if (0 != cli_parse_uint64(arg, &count))
|
||||
return CLI_ERROR;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ int
|
|||
cli_handle_deadline(const char *arg, void *config_void)
|
||||
{
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
float deadline;
|
||||
float deadline;
|
||||
|
||||
if (0 != cli_parse_float(arg, &deadline))
|
||||
return CLI_ERROR;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ int
|
|||
cli_handle_interval(const char *arg, void *config_void)
|
||||
{
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
float interval;
|
||||
float interval;
|
||||
|
||||
if (0 != cli_parse_float(arg, &interval))
|
||||
return CLI_ERROR;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ int
|
|||
cli_handle_size(const char *arg, void *config_void)
|
||||
{
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
uint64_t size;
|
||||
uint64_t size;
|
||||
|
||||
if (0 != cli_parse_uint64(arg, &size) || size > (65535 - 8))
|
||||
return CLI_ERROR;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ int
|
|||
cli_handle_timeout(const char *arg, void *config_void)
|
||||
{
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
float TO;
|
||||
float TO;
|
||||
|
||||
if (0 != cli_parse_float(arg, &TO))
|
||||
return CLI_ERROR;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ int
|
|||
cli_handle_ttl(const char *arg, void *config_void)
|
||||
{
|
||||
struct ping_config *config = (struct ping_config *)config_void;
|
||||
uint64_t ttl;
|
||||
uint64_t ttl;
|
||||
|
||||
if (0 != cli_parse_uint64(arg, &ttl) || ttl > 255)
|
||||
return CLI_ERROR;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ print_help(void)
|
|||
opt->long_opt,
|
||||
argstr[0] ? argstr : "",
|
||||
opt->description
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ cli_parse_arguments(int argc, char **argv, struct ping_config *config)
|
|||
|
||||
init_config(config);
|
||||
ret = cli_parse(argc, argv, config, g_options, CLI_OPT_LEN,
|
||||
opt_str, long_opts);
|
||||
opt_str, long_opts);
|
||||
if (CLI_SUCCESS != ret)
|
||||
return ret;
|
||||
return cli_parse_destinations(argc, argv, optind, config);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ cli_parse_destinations(int argc, char **argv, int first_arg,
|
|||
|
||||
config->nb_destinations = (size_t)(argc - first_arg);
|
||||
config->destinations = malloc(config->nb_destinations
|
||||
* sizeof(struct in_addr));
|
||||
* sizeof(struct in_addr));
|
||||
if (NULL == config->destinations)
|
||||
return CLI_ERROR;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ ping_callback(const icmp_reply_t *reply, void *userdata)
|
|||
if (ICMP_TYPE_ECHO_REPLY == reply->type)
|
||||
handle_echo_reply(state, reply);
|
||||
else if (ICMP_TYPE_TIME_EXCEEDED == reply->type
|
||||
|| ICMP_TYPE_DEST_UNREACHABLE == reply->type)
|
||||
|| ICMP_TYPE_DEST_UNREACHABLE == reply->type)
|
||||
handle_icmp_error(state, reply);
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ handle_echo_reply(struct ping_state *state, const icmp_reply_t *reply)
|
|||
ping_output_flood_erase();
|
||||
else
|
||||
ping_output_packet(reply, seq, rtt, state->config->packet_size,
|
||||
state->config);
|
||||
state->config);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ ping_one(const struct ping_config *config, struct in_addr dest,
|
|||
struct ping_state state;
|
||||
struct ping_stats stats;
|
||||
struct ping_tracker tracker;
|
||||
size_t payload_len;
|
||||
size_t payload_len;
|
||||
|
||||
ping_init_state(&state, &stats, &tracker, config, dest, handle);
|
||||
payload_len = config->packet_size;
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ ping_send_one(struct ping_state *state, size_t payload_len)
|
|||
memset(payload, 0x42, payload_len);
|
||||
icmp_get_time(&ts);
|
||||
ping_tracker_record_send(state->tracker, state->seq, &ts);
|
||||
return (icmp_send_echo(state->handle,
|
||||
state->dest,
|
||||
state->id,
|
||||
state->seq++,
|
||||
state->config->ttl,
|
||||
payload, payload_len));
|
||||
return icmp_send_echo(state->handle,
|
||||
state->dest,
|
||||
state->id,
|
||||
state->seq++,
|
||||
state->config->ttl,
|
||||
payload, payload_len);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ int
|
|||
main(int argc, char **argv)
|
||||
{
|
||||
struct ping_config config;
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
if (0 != init_prog_name(argv[0]))
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ ping_output_error(const icmp_reply_t *reply,
|
|||
char from_str[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &reply->from, from_str, sizeof(from_str));
|
||||
fprintf(stderr, "From %s: icmp_seq=%u %s\n",
|
||||
from_str, (unsigned int)seq, error_msg_for(reply));
|
||||
from_str, (unsigned int)seq, error_msg_for(reply));
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
|||
return;
|
||||
inet_ntop(AF_INET, &reply->from, from_str, sizeof(from_str));
|
||||
printf("%zu bytes from %s: icmp_seq=%u ttl=%u time=%.3f ms\n",
|
||||
payload_bytes + 8,
|
||||
from_str,
|
||||
(unsigned int)seq,
|
||||
(unsigned int)reply->ttl,
|
||||
(double)rtt_ns / 1e6);
|
||||
payload_bytes + 8,
|
||||
from_str,
|
||||
(unsigned int)seq,
|
||||
(unsigned int)reply->ttl,
|
||||
(double)rtt_ns / 1e6);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ print_loss_line(size_t sent, size_t ok_recv, size_t errors)
|
|||
loss_pct = (0 < sent) ? (int)((sent - ok_recv) * 100 / sent) : 0;
|
||||
if (0 < errors)
|
||||
printf("%zu packets transmitted, %zu received, +%zu errors,"
|
||||
" %d%% packet loss\n", sent, ok_recv, errors, loss_pct);
|
||||
" %d%% packet loss\n", sent, ok_recv, errors, loss_pct);
|
||||
else
|
||||
printf("%zu packets transmitted, %zu received, %d%% packet loss\n",
|
||||
sent, ok_recv, loss_pct);
|
||||
sent, ok_recv, loss_pct);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -52,5 +52,5 @@ print_rtt_line(const struct ping_stats *stats)
|
|||
|
||||
ping_stats_get(stats, &min_ms, &max_ms, &avg_ms, &mdev_ms);
|
||||
printf("round-trip min/avg/max/mdev = %.3f/%.3f/%.3f/%.3f ms\n",
|
||||
min_ms, avg_ms, max_ms, mdev_ms);
|
||||
min_ms, avg_ms, max_ms, mdev_ms);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue