80 lines
2.0 KiB
C
80 lines
2.0 KiB
C
#include "ping.h"
|
|
#include <help.h>
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
void print_help(void) {
|
|
printf("Usage: ping [OPTION...] HOST ...\n");
|
|
printf("Send ICMP ECHO_REQUEST packets to network hosts.\n\n");
|
|
|
|
printf(" All the mandatory options : \n");
|
|
OPT_WHILE {
|
|
if (options[i].grp == 1) {
|
|
if (strlen(options[i].name) > 5)
|
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
|
options[i].doc);
|
|
else
|
|
printf(" -%c, --%s:\t\t %s\n", options[i].opt, options[i].name,
|
|
options[i].doc);
|
|
}
|
|
i++;
|
|
}
|
|
printf("\n All the bonuses options : \n");
|
|
i = 0;
|
|
while (i < OPT_NB) {
|
|
if (options[i].grp == 2) {
|
|
if (strlen(options[i].name) > 5)
|
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
|
options[i].doc);
|
|
else
|
|
printf(" -%c, --%s:\t\t %s\n", options[i].opt, options[i].name,
|
|
options[i].doc);
|
|
}
|
|
i++;
|
|
}
|
|
printf("\n All the prints and help function : \n");
|
|
i = 0;
|
|
while (i < OPT_NB) {
|
|
if (options[i].grp == 0) {
|
|
if (strlen(options[i].name) > 5)
|
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name,
|
|
options[i].doc);
|
|
else
|
|
printf(" -%c, --%s:\t\t %s\n", options[i].opt, options[i].name,
|
|
options[i].doc);
|
|
}
|
|
i++;
|
|
}
|
|
printf(
|
|
"\nMandatory or optional arguments to long options are also mandatory "
|
|
"or optional\nfor any corresponding short options.\n\n");
|
|
printf("Report bugs to <noreply@adjoly.fr> :D.\n");
|
|
}
|
|
|
|
void print_parse_err(error_t err, char *opt) {
|
|
switch (err) {
|
|
case MISSING_HOST:
|
|
printf("%s: missing host operand\n", exec_name);
|
|
break;
|
|
case INVALID_OPT:
|
|
printf("%s: invalid option -- %s\n", exec_name, opt);
|
|
break;
|
|
case NEED_ARG:
|
|
printf("%s: option '--%s' requires an argument\n", exec_name, opt);
|
|
|
|
}
|
|
printf("Try 'ping --help' or 'ping --usage' for more information.\n");
|
|
}
|
|
|
|
void print_usage(void) {
|
|
printf("Usage %s:", exec_name);
|
|
OPT_WHILE {
|
|
printf(" [--%s] ", options[i].name);
|
|
i++;
|
|
}
|
|
printf("HOST ...\n");
|
|
}
|