feat(core): add domaine name in start message
This commit is contained in:
parent
cdc4df4f85
commit
cde8ada0a3
7 changed files with 24 additions and 17 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
#include "internal/ping/ping_state.h"
|
#include "internal/ping/ping_state.h"
|
||||||
|
|
||||||
void ping_output_start(const struct ping_config *config,
|
void ping_output_start(const struct ping_config *config,
|
||||||
struct in_addr dest, size_t payload_bytes);
|
struct destinations *dest, size_t payload_bytes);
|
||||||
void ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
void ping_output_packet(const icmp_reply_t *reply, uint16_t seq,
|
||||||
int64_t rtt_ns, size_t payload_bytes, const struct 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,
|
void ping_output_error(const icmp_reply_t *reply,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include "ping/ping.h"
|
#include "ping/ping.h"
|
||||||
|
|
||||||
int cli_parse_inet_addr(const char *s, struct in_addr *out);
|
int cli_parse_inet_addr(const char *s, struct destinations *out);
|
||||||
int cli_parse_destinations(int argc, char **argv, int first_arg,
|
int cli_parse_destinations(int argc, char **argv, int first_arg,
|
||||||
struct ping_config *config);
|
struct ping_config *config);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,10 @@
|
||||||
struct ping_config
|
struct ping_config
|
||||||
{
|
{
|
||||||
/* Targets */
|
/* Targets */
|
||||||
struct in_addr *destinations;
|
struct destinations {
|
||||||
|
const char *dom;
|
||||||
|
struct in_addr ip;
|
||||||
|
} *destinations;
|
||||||
size_t nb_destinations;
|
size_t nb_destinations;
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "ping/cli.h"
|
#include "ping/cli.h"
|
||||||
#include "internal/cli/messages.h"
|
#include "internal/cli/messages.h"
|
||||||
#include "internal/ping/parse_utils.h"
|
#include "internal/ping/parse_utils.h"
|
||||||
|
#include "ping/ping.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
cli_parse_destinations(int argc, char **argv, int first_arg,
|
cli_parse_destinations(int argc, char **argv, int first_arg,
|
||||||
|
|
@ -13,7 +14,7 @@ cli_parse_destinations(int argc, char **argv, int first_arg,
|
||||||
|
|
||||||
config->nb_destinations = (size_t)(argc - first_arg);
|
config->nb_destinations = (size_t)(argc - first_arg);
|
||||||
config->destinations = malloc(config->nb_destinations
|
config->destinations = malloc(config->nb_destinations
|
||||||
* sizeof(struct in_addr));
|
* sizeof(struct destinations));
|
||||||
if (NULL == config->destinations)
|
if (NULL == config->destinations)
|
||||||
return CLI_ERROR;
|
return CLI_ERROR;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
#include "ping/ping.h"
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
cli_parse_inet_addr(const char *s, struct in_addr *out)
|
cli_parse_inet_addr(const char *s, struct destinations *out)
|
||||||
{
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *res;
|
struct addrinfo *res;
|
||||||
|
|
@ -18,6 +19,7 @@ cli_parse_inet_addr(const char *s, struct in_addr *out)
|
||||||
|
|
||||||
memcpy(&sin, res->ai_addr, sizeof(sin));
|
memcpy(&sin, res->ai_addr, sizeof(sin));
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
*out = sin.sin_addr;
|
out->ip = sin.sin_addr;
|
||||||
|
out->dom = s;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@
|
||||||
#include "internal/ping/loop.h"
|
#include "internal/ping/loop.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int ping_one(const struct ping_config *config, struct in_addr dest,
|
static int ping_one(const struct ping_config *config,
|
||||||
icmp_handle_t *handle);
|
struct destinations *dest, icmp_handle_t *handle);
|
||||||
static void ping_init_state(struct ping_state *state, struct ping_stats *stats,
|
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
|
struct ping_tracker *tracker, const struct ping_config *config,
|
||||||
dest, icmp_handle_t *handle);
|
struct in_addr dest, icmp_handle_t *handle);
|
||||||
static void ping_first_send(struct ping_state *state, size_t payload_len);
|
static void ping_first_send(struct ping_state *state, size_t payload_len);
|
||||||
/* -------------------- */
|
/* -------------------- */
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ ping_run(const struct ping_config *config)
|
||||||
|
|
||||||
while (i < config->nb_destinations)
|
while (i < config->nb_destinations)
|
||||||
{
|
{
|
||||||
if (0 != ping_one(config, config->destinations[i], handle))
|
if (0 != ping_one(config, &config->destinations[i], handle))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,7 @@ cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ping_one(const struct ping_config *config, struct in_addr dest,
|
ping_one(const struct ping_config *config, struct destinations *dest,
|
||||||
icmp_handle_t *handle)
|
icmp_handle_t *handle)
|
||||||
{
|
{
|
||||||
struct ping_state state;
|
struct ping_state state;
|
||||||
|
|
@ -60,13 +60,13 @@ ping_one(const struct ping_config *config, struct in_addr dest,
|
||||||
struct ping_tracker tracker;
|
struct ping_tracker tracker;
|
||||||
size_t payload_len;
|
size_t payload_len;
|
||||||
|
|
||||||
ping_init_state(&state, &stats, &tracker, config, dest, handle);
|
ping_init_state(&state, &stats, &tracker, config, dest->ip, handle);
|
||||||
payload_len = config->packet_size;
|
payload_len = config->packet_size;
|
||||||
ping_scheduler_init(&state);
|
ping_scheduler_init(&state);
|
||||||
ping_output_start(config, dest, payload_len);
|
ping_output_start(config, dest, payload_len);
|
||||||
ping_first_send(&state, payload_len);
|
ping_first_send(&state, payload_len);
|
||||||
ping_loop(&state, payload_len);
|
ping_loop(&state, payload_len);
|
||||||
ping_output_summary(&state, dest);
|
ping_output_summary(&state, dest->ip);
|
||||||
return tracker.nb_recv <= state.nb_errors;
|
return tracker.nb_recv <= state.nb_errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,16 @@
|
||||||
|
|
||||||
#include "ping/ft_ping_flags.h"
|
#include "ping/ft_ping_flags.h"
|
||||||
#include "internal/ping/output.h"
|
#include "internal/ping/output.h"
|
||||||
|
#include "ping/ping.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
ping_output_start(const struct ping_config *config,
|
ping_output_start(const struct ping_config *config,
|
||||||
struct in_addr dest, size_t payload_bytes)
|
struct destinations *dest, size_t payload_bytes)
|
||||||
{
|
{
|
||||||
char dest_str[INET_ADDRSTRLEN];
|
char dest_str[INET_ADDRSTRLEN];
|
||||||
|
|
||||||
inet_ntop(AF_INET, &dest, dest_str, sizeof(dest_str));
|
inet_ntop(AF_INET, &dest->ip, dest_str, sizeof(dest_str));
|
||||||
printf("PING %s (%s): %zu data bytes", dest_str, dest_str, payload_bytes);
|
printf("PING %s (%s): %zu data bytes", dest->dom, dest_str, payload_bytes);
|
||||||
if (HAS_FLAG(config->flags, FLAG_VERBOSE))
|
if (HAS_FLAG(config->flags, FLAG_VERBOSE))
|
||||||
{
|
{
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue