add: help message
This commit is contained in:
@@ -93,7 +93,11 @@ int main(int ac, char **av)
|
||||
struct statistics stats;
|
||||
struct setting settings;
|
||||
|
||||
if (get_setting(av + 1, &settings))
|
||||
int ret = get_setting(av + 1, &settings);
|
||||
|
||||
if (ret == -1)
|
||||
goto finish;
|
||||
if (ret)
|
||||
goto error0;
|
||||
|
||||
size_t packet_size = sizeof(struct icmphdr) + settings.payload_size;
|
||||
@@ -168,6 +172,7 @@ int main(int ac, char **av)
|
||||
|
||||
print_statistics(&stats, &settings);
|
||||
|
||||
finish:
|
||||
return 0;
|
||||
|
||||
error3:
|
||||
|
||||
15
src/print.c
15
src/print.c
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "icmp_error.h"
|
||||
#include "interval.h"
|
||||
#include "parsing.h"
|
||||
#include "setting.h"
|
||||
#include "statistics.h"
|
||||
#include <arpa/inet.h>
|
||||
@@ -83,3 +84,17 @@ void print_recv(const struct setting *settings, const char *packet, const struct
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_help(struct param *parameters)
|
||||
{
|
||||
printf("PING [OPTION...] HOST...\n");
|
||||
for (size_t i = 0; parameters[i].name || parameters[i].alias; i++)
|
||||
{
|
||||
if (parameters[i].alias)
|
||||
printf("-%s", parameters[i].alias);
|
||||
printf("\t");
|
||||
if (parameters[i].name)
|
||||
printf("--%s", parameters[i].name);
|
||||
printf("\t");
|
||||
printf("%s\n", parameters[i].desc);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "parsing.h"
|
||||
#include "setting.h"
|
||||
#include "statistics.h"
|
||||
#include <bits/types/struct_timeval.h>
|
||||
@@ -9,4 +10,5 @@ void print_err(const char *format, ...);
|
||||
|
||||
void print_header(struct setting const *settings);
|
||||
void print_statistics(struct statistics const *stats, struct setting const *settings);
|
||||
void print_recv(const struct setting *settings, const char *packet, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender);
|
||||
void print_recv(const struct setting *settings, const char *packet, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender);
|
||||
void print_help(struct param *parameters);
|
||||
@@ -47,6 +47,13 @@ int get_setting(char * const *av, struct setting *settings)
|
||||
{NULL, NULL, 0, NULL, NULL},
|
||||
};
|
||||
char *hostname = parsing(av, parameters);
|
||||
|
||||
if (parameters[0].value)
|
||||
{
|
||||
print_help(parameters);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hostname == NULL)
|
||||
return 1;
|
||||
settings->dest.hostname = hostname;
|
||||
|
||||
Reference in New Issue
Block a user