Skip to content

Commit

Permalink
usage: unify usage outputs, and improve their helpfulness
Browse files Browse the repository at this point in the history
Just listing options, like ping(8) did, does not help users.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
  • Loading branch information
kerolasa committed Oct 3, 2018
1 parent ddc5f04 commit 120602e
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 129 deletions.
35 changes: 19 additions & 16 deletions arping.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,27 @@ static inline socklen_t sll_len(size_t halen)
void usage(void)
{
fprintf(stderr,
"Usage: arping [-fqbDUAV] [-c count] [-w timeout] [-I device] [-s source] destination\n"
" -f : quit on first reply\n"
" -q : be quiet\n"
" -b : keep broadcasting, don't go unicast\n"
" -D : duplicate address detection mode\n"
" -U : Unsolicited ARP mode, update your neighbours\n"
" -A : ARP answer mode, update your neighbours\n"
" -V : print version and exit\n"
" -c count : how many packets to send\n"
" -w timeout : how long to wait for a reply\n"
" -I device : which ethernet device to use"
"\nUsage:\n"
" arping [options] <destination>\n"
"\nOptions:\n"
" -f quit on first reply\n"
" -q be quiet\n"
" -b keep on broadcasting, do not unicast\n"
" -D duplicate address detection mode\n"
" -U unsolicited ARP mode, update your neighbours\n"
" -A ARP answer mode, update your neighbours\n"
" -V print version and exit\n"
" -c <count> how many packets to send\n"
" -w <timeout> how long to wait for a reply\n"
" -I <device> which ethernet device to use"
#ifdef DEFAULT_DEVICE_STR
" (" DEFAULT_DEVICE_STR ")"
"(" DEFAULT_DEVICE_STR ")"
#endif
"\n"
" -s source : source ip address\n"
" destination : ask for what ip address\n"
);
"\n"
" -s <source> source ip address\n"
" <destination> dns name or ip address\n"
"\nFor more details see arping(8).\n"
);
exit(2);
}

Expand Down
17 changes: 13 additions & 4 deletions clockdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,19 @@ measure_opt(struct sockaddr_in * addr)
* be reduced by increasing the number of messages sent in each measurement.
*/

void
usage() {
fprintf(stderr, "Usage: clockdiff [-o] <host>\n");
exit(1);
void usage(void)
{
fprintf(stderr,
"\nUsage:\n"
" clockdiff [options] <destination>\n"
"\nOptions:\n"
" without -o, use ip timestamp only\n"
" -o use ip timestamp and icmp echo\n"
" -o1 use three-term ip timestamp and icmp echo\n"
" <destination> dns name or ip address\n"
"\nFor more details see clockdiff(8).\n"
);
exit(1);
}

void drop_rights(void) {
Expand Down
11 changes: 9 additions & 2 deletions ninfod/ninfod.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,15 @@ static void print_copying(void) {

static void print_usage(void) {
fprintf(stderr,
"Usage: %s [-d] [-p pidfile] [-u user] [-h] [-v]\n\n",
appname
"Usage:\n"
" ninfod [options]\n"
"\nOptions:\n"
" -d debug mode\n"
" -h show help\n"
" -p <pidfile> file to store process-id\n"
" -u <user> run <user>\n"
" -v verbose mode\n"
"\nFor more details see ninfod(8).\n"
);
}

Expand Down
40 changes: 2 additions & 38 deletions ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ static int broadcast_pings = 0;

static void pr_options(unsigned char * cp, int hlen);
static void pr_iph(struct iphdr *ip);
static void usage(void) __attribute__((noreturn));
static unsigned short in_cksum(const unsigned short *addr, int len, unsigned short salt);
static void pr_icmph(uint8_t type, uint8_t code, uint32_t info, struct icmphdr *icp);
static int parsetos(char *str);
Expand Down Expand Up @@ -268,10 +267,8 @@ main(int argc, char **argv)
options |= F_FLOWINFO;
break;
case 'N':
if (niquery_option_handler(optarg) < 0) {
ping6_usage(0);
exit(2);
}
if (niquery_option_handler(optarg) < 0)
usage();
hints.ai_socktype = SOCK_RAW;
break;
/* Common options */
Expand Down Expand Up @@ -1667,36 +1664,3 @@ void ping4_install_filter(socket_st *sock)
if (setsockopt(sock->fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)))
perror("WARNING: failed to install socket filter\n");
}

#define USAGE_NEWLINE "\n "

void usage(void)
{
fprintf(stderr,
"Usage: ping"
" [-"
"aAbBdDfhLnOqrRUvV64"
"]"
" [-c count]"
" [-i interval]"
" [-I interface]"
USAGE_NEWLINE
" [-m mark]"
" [-M pmtudisc_option]"
" [-l preload]"
" [-p pattern]"
" [-Q tos]"
USAGE_NEWLINE
" [-s packetsize]"
" [-S sndbuf]"
" [-t ttl]"
" [-T timestamp_option]"
USAGE_NEWLINE
" [-w deadline]"
" [-W timeout]"
" [hop1 ...] destination"
"\n"
);
ping6_usage(1);
exit(2);
}
1 change: 1 addition & 0 deletions ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ static inline void advance_ntransmitted(void)
acked = (uint16_t)ntransmitted + 1;
}

extern void usage(void) __attribute__((noreturn));
extern void limit_capabilities(void);
static int enable_capability_raw(void);
static int disable_capability_raw(void);
Expand Down
74 changes: 20 additions & 54 deletions ping6_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ static unsigned char cmsgbuf[4096];
static size_t cmsglen = 0;

static int pr_icmph(uint8_t type, uint8_t code, uint32_t info);
void ping6_usage(unsigned) __attribute((noreturn));

struct sockaddr_in6 source6 = { .sin6_family = AF_INET6 };
char *device;
Expand Down Expand Up @@ -560,15 +559,24 @@ static int niquery_option_subject_name_handler(int index, const char *name)

int niquery_option_help_handler(int index __attribute__((__unused__)), const char *arg __attribute__((__unused__)))
{
fprintf(stderr, "ping6 -N suboptions\n"
"\tHelp:\n"
"\t\thelp\n"
"\tQuery:\n"
"\t\tname,\n"
"\t\tipv6,ipv6-all,ipv6-compatible,ipv6-linklocal,ipv6-sitelocal,ipv6-global,\n"
"\t\tipv4,ipv4-all,\n"
"\tSubject:\n"
"\t\tsubject-ipv6=addr,subject-ipv4=addr,subject-name=name,subject-fqdn=name,\n"
fprintf(stderr, "ping -6 -N <nodeinfo opt>\n"
"Help:\n"
" help\n"
"Query:\n"
" name\n"
" ipv6\n"
" ipv6-all\n"
" ipv6-compatible\n"
" ipv6-global\n"
" ipv6-linklocal\n"
" ipv6-sitelocal\n"
" ipv4\n"
" ipv4-all\n"
"Subject:\n"
" subject-ipv6=addr\n"
" subject-ipv4=addr\n"
" subject-name=name\n"
" subject-fqdn=name\n"
);
exit(2);
}
Expand Down Expand Up @@ -701,12 +709,12 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock
#ifndef ENABLE_PING6_RTHDR
fprintf(stderr, "ping6: Source routing is deprecated by RFC5095.\n");
#endif
ping6_usage(0);
usage();
} else if (argc == 1) {
target = *argv;
} else {
if (ni_query < 0 && ni_subject_type != NI_SUBJ_NAME)
ping6_usage(0);
usage();
target = ni_group;
}

Expand Down Expand Up @@ -1568,45 +1576,3 @@ void ping6_install_filter(socket_st *sock)
if (setsockopt(sock->fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)))
perror("WARNING: failed to install socket filter\n");
}

#define USAGE_NEWLINE "\n "

void ping6_usage(unsigned from_ping)
{
const char *name;
if (from_ping)
name = "ping -6";
else
name = "ping6";
fprintf(stderr,
"Usage: %s"
" [-"
"aAbBdDfhLnOqrRUvV"
"]"
" [-c count]"
" [-i interval]"
" [-I interface]"
USAGE_NEWLINE
" [-l preload]"
" [-m mark]"
" [-M pmtudisc_option]"
USAGE_NEWLINE
" [-N nodeinfo_option]"
" [-p pattern]"
" [-Q tclass]"
" [-s packetsize]"
USAGE_NEWLINE
" [-S sndbuf]"
" [-t ttl]"
" [-T timestamp_option]"
" [-w deadline]"
USAGE_NEWLINE
" [-W timeout]"
#ifdef ENABLE_PING6_RTHDR
" [hop1 ...]"
#endif
" destination"
"\n", name
);
exit(2);
}
48 changes: 48 additions & 0 deletions ping_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,54 @@ static cap_value_t cap_raw = CAP_NET_RAW;
static cap_value_t cap_admin = CAP_NET_ADMIN;
#endif

void usage(void)
{
fprintf(stderr,
"\nUsage\n"
" ping [options] <destination>\n"
"\nOptions:\n"
" <destination> dns name or ip address\n"
" -a use audible ping\n"
" -A use adaptive ping\n"
" -B sticky source address\n"
" -c <count> stop after <count> replies\n"
" -D print timestamps\n"
" -d use SO_DEBUG socket option\n"
" -f flood ping\n"
" -h print help and exit\n"
" -I <interface> either interface name or address\n"
" -i <interval> seconds between sending each packet\n"
" -L suppress loopback of multicast packets\n"
" -l <preload> send <preload> number of packages while waiting replies\n"
" -m <mark> tag the packets going out\n"
" -M <pmtud opt> define mtu discovery, can be one of <do|dont|want>\n"
" -n no dns name resolution\n"
" -O report outstanding replies\n"
" -p <pattern> contents of padding byte\n"
" -q quiet output\n"
" -Q <tclass> use quality of service <tclass> bits\n"
" -s <size> use <size> as number of data bytes to be sent\n"
" -S <size> use <size> as SO_SNDBUF socket option value\n"
" -t <ttl> define time to live\n"
" -U print user-to-user latency\n"
" -v verbose output\n"
" -V print version and exit\n"
" -w <deadline> reply wait <deadline> in seconds\n"
" -W <timeout> time to wait for response\n"
"\nIPv4 options:\n"
" -4 use IPv4\n"
" -b allow pinging broadcast\n"
" -R record route\n"
" -T <timestamp> define timestamp, can be one of <tsonly|tsandaddr|tsprespec>\n"
"\nIPv6 options:\n"
" -6 use IPv6\n"
" -F <flowlabel> define flow label, default is random\n"
" -N <nodeinfo opt> use icmp6 node info query, try <help> as argument\n"
"\nFor more details see ping(8).\n"
);
exit(2);
}

void limit_capabilities(void)
{
#ifdef CAPABILITIES
Expand Down
14 changes: 12 additions & 2 deletions rarpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,19 @@ struct rarp_map
uint32_t ipaddr;
} *rarp_db;

void usage()
void usage(void)
{
fprintf(stderr, "Usage: rarpd [ -dveaA ] [ -b tftpdir ] [ interface]\n");
fprintf(stderr,
"\nUsage:\n"
" rarpd [options] [interface]\n"
"\nOptions:\n"
" -A listen also arp messages\n"
" -b <dir> tftpd boot directory\n"
" -d debug mode\n"
" -e /etc/ethers markup alone is fine\n"
" -v verbose mode\n"
"\nFor more details see rarpd(8).\n"
);
exit(1);
}

Expand Down
31 changes: 21 additions & 10 deletions rdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ static int interfaces_size; /* Number of elements in interfaces */
/* fraser */
int debugfile;

const char usage[] =
"Usage: rdisc [-b] [-d] [-s] [-v] [-f] [-a] [-V] [send_address] [receive_address]\n"
#ifdef RDISC_SERVER
" rdisc -r [-b] [-d] [-s] [-v] [-f] [-a] [-V] [-p <preference>] [-T <secs>]\n"
" [send_address] [receive_address]\n"
#endif
;


int s; /* Socket file descriptor */
struct sockaddr_in whereto;/* Address to send to */

Expand Down Expand Up @@ -232,7 +223,27 @@ static __inline__ int ismulticast(struct sockaddr_in *sin)

static void prusage(void)
{
fputs(usage, stderr);
fprintf(stderr,
"\nUsage\n"
" rdisc [options] <send address> <receive address>\n"
"\nOptions:\n"
" -a accept all routers\n"
" -b accept best only (default)\n"
" -d enable debug syslog messages\n"
" -f run forever\n"
#ifdef RDISC_SERVER
" -r responder mode\n"
#endif
" -s send solicitation messages at startup\n"
#ifdef RDISC_SERVER
" -p <preference> set <preference> in advertisement\n"
" -T <seconds> set max advertisement interval in <seconds>\n"
#endif
" -t test mode, do not go background\n"
" -v verbose mode\n"
" -V print version and exit\n"
"\nFor more details see rdisc(8).\n"
);
exit(1);
}

Expand Down
15 changes: 14 additions & 1 deletion tracepath.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,20 @@ static void usage(void) __attribute((noreturn));

static void usage(void)
{
fprintf(stderr, "Usage: tracepath [-4] [-6] [-n] [-b] [-l <len>] [-p port] <destination>\n");
fprintf(stderr,
"\nUsage\n"
" tracepath [options] <destination>\n"
"\nOptions:\n"
" -4 use IPv4\n"
" -6 use IPv6\n"
" -b print both name and ip\n"
" -l <length> use packet <length>\n"
" -m <hops> use maximum <hops>\n"
" -n no dns name resolution\n"
" -p <port> use destination <port>\n"
" <destination> dns name or ip address\n"
"\nFor more details see tracepath(8).\n"
);
exit(-1);
}

Expand Down
Loading

0 comments on commit 120602e

Please sign in to comment.