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