Improve command-line handling and documentation

In particular:

- generally improve the look of the man page and help message
- add missing command line options to the man page
- reorder command line options to be more consistent
- use the same order for command line options everywhere (man page, code, help message)
- add missing switches in getopt_long call (-M, -F)
- fix incorrect switch in getopt_long call (-Z)

Note that a few options were never documented (they are now marked as
"MISSING" in the man page).
This commit is contained in:
Baptiste Jonglez 2014-07-12 13:40:45 +09:00
parent 0cc9f56313
commit 9d62fe4fd5
2 changed files with 164 additions and 250 deletions

356
mtr.8
View File

@ -1,20 +1,14 @@
.TH MTR 8 "March 4, 1999" "mtr" "mtr" .TH MTR 8 "July 12, 2014" "mtr" "mtr"
.SH NAME .SH NAME
mtr \- a network diagnostic tool mtr \- a network diagnostic tool
.SH SYNOPSIS .SH SYNOPSIS
.B mtr .B mtr
[\c [\c
.B \-BfhvrctglxspQemniuTP46\c .BR \-4 |\c
.B \-6\c
] ]
[\c [\c
.B \-\-help\c .BI \-F \ FILENAME\c
]
[\c
.B \-\-version\c
] ]
[\c [\c
.B \-\-report\c .B \-\-report\c
@ -23,22 +17,22 @@ mtr \- a network diagnostic tool
.B \-\-report-wide\c .B \-\-report-wide\c
] ]
[\c [\c
.B \-\-report\-cycles\ COUNT\c .B \-\-xml\c
]
[\c
.B \-\-gtk\c
] ]
[\c [\c
.B \-\-curses\c .B \-\-curses\c
] ]
[\c [\c
.B \-\-split\c
]
[\c
.B \-\-raw\c .B \-\-raw\c
] ]
[ [\c
.B \-\-xml\c .B \-\-csv\c
] ]
[\c [\c
.B \-\-mpls\c .B \-\-split\c
] ]
[\c [\c
.B \-\-no-dns\c .B \-\-no-dns\c
@ -47,60 +41,71 @@ mtr \- a network diagnostic tool
.B \-\-show-ips\c .B \-\-show-ips\c
] ]
[\c [\c
.B \-\-gtk\c .BI \-o \ FIELDS\c
] ]
[\c [\c
.B \-\-address\ IP.ADD.RE.SS\c .BI \-y \ IPINFO\c
] ]
[\c [\c
.B \-\-interval\ SECONDS\c .B \-\-aslookup\c
] ]
[\c [\c
.B \-\-max-ttl\ NUM\c .BI \-i \ INTERVAL\c
] ]
[\c [\c
.B \-\-first-ttl\ NUM\c .BI \-c \ COUNT\c
] ]
[\c [\c
.B \-\-bitpattern\ NUM\c .BI \-s \ PACKETSIZE\c
] ]
[\c [\c
.B \-\-tos\ NUM\c .BI \-B \ BITPATTERN\c
] ]
[\c [\c
.B \-\-psize\ BYTES | -s BYTES\c .BI \-Q \ TOS\c
] ]
[\c [\c
.B \-\-tcp\c .B \-\-mpls\c
]
[\c
.BI \-a \ ADDRESS\c
]
[\c
.BI \-f \ FIRST\-TTL\c
]
[\c
.BI \-m \ MAX\-TTL\c
] ]
[\c [\c
.B \-\-udp\c .B \-\-udp\c
] ]
[\c [\c
.B \-\-port\ PORT\c .B \-\-tcp\c
] ]
[\c [\c
.B \-\-timeout\ SECONDS\c .BI \-P \ PORT\c
] ]
.B HOSTNAME [PACKETSIZE] [\c
.BI \-Z \ TIMEOUT\c
]
[\c
.BI \-M \ MARK\c
]
.I HOSTNAME
.SH DESCRIPTION .SH DESCRIPTION
.B mtr .B mtr
combines the functionality of the combines the functionality of the
.B traceroute .B traceroute
and and
.B ping .B ping
programs in a single network diagnostic tool. programs in a single network diagnostic tool.
.PP .PP
As As
.B mtr .B mtr
starts, it investigates the network connection between the host starts, it investigates the network connection between the host
.B mtr .B mtr
runs on and runs on and
.BR HOSTNAME . .BR HOSTNAME
by sending packets with purposely low TTLs. It continues to send by sending packets with purposely low TTLs. It continues to send
packets with low TTL, noting the response time of the intervening packets with low TTL, noting the response time of the intervening
routers. This allows routers. This allows
@ -110,32 +115,27 @@ route to
.BR HOSTNAME . .BR HOSTNAME .
A sudden increase in packet loss or response time is often an indication A sudden increase in packet loss or response time is often an indication
of a bad (or simply overloaded) link. of a bad (or simply overloaded) link.
.PP .PP
The results are usually reported as round-trip-response times in miliseconds The results are usually reported as round-trip-response times in miliseconds
and the percentage of packetloss. and the percentage of packetloss.
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-h .B \-h\fR, \fB\-\-help
.TP
.B \-\-help
.br
Print the summary of command line argument options. Print the summary of command line argument options.
.TP .TP
.B \-v .B \-v\fR, \fB\-\-version
.TP
.B \-\-version
.br
Print the installed version of mtr. Print the installed version of mtr.
.TP .TP
.B \-r .B \-4
Use IPv4 only.
.TP .TP
.B \-\-report .B \-6
.br Use IPv6 only. (IPV4 may be used for DNS lookups).
.TP
.B \-F \fIFILENAME\fR, \fB\-\-filename \fIFILENAME
MISSING
.TP
.B \-r\fR, \fB\-\-report
This option puts This option puts
.B mtr .B mtr
into into
@ -154,12 +154,8 @@ generates a significant amount of network traffic. Using
.B mtr .B mtr
to measure the quality of your network may result in decreased to measure the quality of your network may result in decreased
network performance. network performance.
.TP .TP
.B \-w .B \-w\fR, \fB\-\-report\-wide
.TP
.B \-\-report-wide
.br
This option puts This option puts
.B mtr .B mtr
into into
@ -167,75 +163,61 @@ into
mode. When in this mode, mode. When in this mode,
.B mtr .B mtr
will not cut hostnames in the report. will not cut hostnames in the report.
.TP .TP
.B \-c\ COUNT .B \-x\fR, \fB\-\-xml
Use this option to tell
.B mtr
to use the xml output format. This format is better suited for
automated processing of the measurement results.
.TP .TP
.B \-\-report\-cycles\ COUNT .B \-t\fR, \fB\-\-curses
Use this option to set the number of pings sent to determine
both the machines on the network and the reliability of
those machines. Each cycle lasts one second.
.TP
.B \-s\ BYTES
.TP
.B \-\-psize\ BYTES
.TP
.B PACKETSIZE
These options or a trailing PACKETSIZE on the command line sets
the packet size used for probing.
It is in bytes inclusive IP and ICMP headers
If set to a negative number, every iteration will use a different, random
packet size upto that number.
.TP
.B \-t
.TP
.B \-\-curses
.br
Use this option to force Use this option to force
.B mtr .B mtr
to use the curses based terminal to use the curses based terminal
interface (if available). interface (if available).
.TP .TP
.B \-e .B \-g\fR, \fB\-\-gtk
.TP Use this option to force
.B \-\-mpls
.br
Use this option to tell
.B mtr .B mtr
to display information from ICMP extensions for MPLS (RFC 4950) to use the GTK+ based X11 window interface (if available).
that are encoded in the response packets. GTK+ must have been available on the system when
.B mtr
was built for this to work. See the GTK+ web page at
.B http://www.gtk.org/
for more information about GTK+.
.TP .TP
.B \-n .B \-l\fR, \fB\-\-raw
Use this option to tell
.B mtr
to use the raw output format. This format is better suited for
archival of the measurement results. It could be parsed to
be presented into any of the other display methods.
.TP .TP
.B \-\-no-dns .B \-C\fR, \fB\-\-csv
.br MISSING
.TP
.B \-p\fR, \fB\-\-split
Use this option to set
.B mtr
to spit out a format that is suitable for a split-user interface.
.TP
.B \-n\fR, \fB\-\-no\-dns
Use this option to force Use this option to force
.B mtr .B mtr
to display numeric IP numbers and not try to resolve the to display numeric IP numbers and not try to resolve the
host names. host names.
.TP .TP
.B \-b .B \-b\fR, \fB\-\-show\-ips
.TP
.B \-\-show-ips
.br
Use this option to tell Use this option to tell
.B mtr .B mtr
to display both the host names and numeric IP numbers. In split mode to display both the host names and numeric IP numbers. In split mode
this adds an extra field to the output. In report mode, there is usually this adds an extra field to the output. In report mode, there is usually
too little space to add the IPs, and they will be truncated. Use the too little space to add the IPs, and they will be truncated. Use the
wide report (-w) mode to see the IPs in report mode. wide report (-w) mode to see the IPs in report mode.
.TP .TP
.B \-o\ fields\ order .B \-o \fIFIELDS\fR, \fB\-\-order \fIFIELDS
.TP Use this option to specify which fields to display and in which order.
.B \-\-order\ fields\ order You may use one or more space characters to separate fields.
.br
Use this option to specify the fields and their order when loading mtr.
.br .br
Available fields: Available fields:
.TS .TS
@ -259,166 +241,96 @@ I%Interarrival Jitter
.br .br
Example: Example:
-o "LSD NBAW" -o "LSD NBAW X"
.TP .TP
.B \-g .B \-y \fIn\fR, \fB\-\-ipinfo \fIn
MISSING
.TP .TP
.B \-\-gtk .B \-z\fR, \fB\-\-aslookup
.br MISSING
Use this option to force .TP
.B \-i \fISECONDS\fR, \fB\-\-interval \fISECONDS
Use this option to specify the positive number of seconds between ICMP
ECHO requests. The default value for this parameter is one second. The
root user may choose values between zero and one.
.TP
.B \-c \fICOUNT\fR, \fB\-\-report\-cycles \fICOUNT
Use this option to set the number of pings sent to determine
both the machines on the network and the reliability of
those machines. Each cycle lasts one second.
.TP
.B \-s \fIPACKETSIZE\fR, \fB\-\-psize \fIPACKETSIZE
This option sets the packet size used for probing. It is in bytes,
inclusive IP and ICMP headers.
If set to a negative number, every iteration will use a different, random
packet size up to that number.
.TP
.B \-B \fINUM\fR, \fB\-\-bitpattern \fINUM
Specifies bit pattern to use in payload. Should be within range 0 - 255. If
.I NUM
is greater than 255, a random pattern is used.
.TP
.B \-Q \fINUM\fR, \fB\-\-tos \fINUM
Specifies value for type of service field in IP header. Should be within range 0
- 255.
.TP
.B \-e\fR, \fB\-\-mpls
Use this option to tell
.B mtr .B mtr
to use the GTK+ based X11 window interface (if available). to display information from ICMP extensions for MPLS (RFC 4950)
GTK+ must have been available on the system when that are encoded in the response packets.
.B mtr
was built for this to work. See the GTK+ web page at
.B http://www.gtk.org/
for more information about GTK+.
.TP .TP
.B \-p .B \-a \fIADDRESS\fR, \fB\-\-address \fIADDRESS
.TP
.B \-\-split
.br
Use this option to set
.B mtr
to spit out a format that is suitable for a split-user interface.
.TP
.B \-l
.TP
.B \-\-raw
.br
Use this option to tell
.B mtr
to use the raw output format. This format is better suited for
archival of the measurement results. It could be parsed to
be presented into any of the other display methods.
.TP
.B \-x
.TP
.B \-\-xml
.br
Use this option to tell
.B mtr
to use the xml output format. This format is better suited for
automated processing of the measurement results.
.TP
.B \-a\ IP.ADD.RE.SS
.TP
.B \-\-address\ IP.ADD.RE.SS
.br
Use this option to bind outgoing packets' socket to specific interface, Use this option to bind outgoing packets' socket to specific interface,
so that any packet will be sent through this interface. NOTE that this so that any packet will be sent through this interface. NOTE that this
option doesn't apply to DNS requests (which could be and could not be option doesn't apply to DNS requests (which could be and could not be
what you want). what you want).
.TP .TP
.B \-i\ SECONDS .B \-f \fINUM\fR, \fB\-\-first-ttl \fINUM
Specifies with what TTL to start. Defaults to 1.
.TP .TP
.B \-\-interval\ SECONDS .B \-m \fINUM\fR, \fB\-\-max-ttl \fINUM
.br
Use this option to specify the positive number of seconds between ICMP
ECHO requests. The default value for this parameter is one second. The
root user may choose values between zero and one.
.TP
.B \-m\ NUM
.TP
.B \-\-max-ttl\ NUM
.br
Specifies the maximum number of hops (max time-to-live value) traceroute will Specifies the maximum number of hops (max time-to-live value) traceroute will
probe. Default is 30. probe. Default is 30.
.TP .TP
.B \-f\ NUM .B \-u\fR, \fB\-\-udp
.TP
.B \-\-first-ttl\ NUM
.br
Specifies with what TTL to start. Defaults to 1.
.TP
.B \-B\ NUM
.TP
.B \-\-bitpattern\ NUM
.br
Specifies bit pattern to use in payload. Should be within range 0 - 255.
.TP
.B \-Q\ NUM
.TP
.B \-\-tos\ NUM
.br
Specifies value for type of service field in IP header. Should be within range 0
- 255.
.TP
.B \-u
.TP
.B \-\-udp
.br
Use UDP datagrams instead of ICMP ECHO. Use UDP datagrams instead of ICMP ECHO.
.TP .TP
.B \-T .B \-T\fR, \fB\-\-tcp
Use TCP SYN packets instead of ICMP ECHO.
.I PACKETSIZE
is ignored, since SYN packets can not contain data.
.TP .TP
.B \-\-tcp .B \-P \fIPORT\fR, \fB\-\-port \fIPORT
.br
Use TCP SYN packets instead of ICMP ECHO. PACKETSIZE is ignored, since
SYN packets can not contain data.
.TP
.B \-P\ PORT
.TP
.B \-\-port\ PORT
.br
The target port number for TCP traces. The target port number for TCP traces.
.TP .TP
.B \-\-timeout\ SECONDS .B \-Z \fISECONDS\fR, \fB\-\-timeout \fISECONDS
.br
The number of seconds to keep the TCP socket open before giving up on The number of seconds to keep the TCP socket open before giving up on
the connection. This will only affect the final hop. Using large values the connection. This will only affect the final hop. Using large values
for this, especially combined with a short interval, will use up a lot for this, especially combined with a short interval, will use up a lot
of file descriptors. of file descriptors.
.TP .TP
.B \-4 .B \-M \fIMARK\fR, \fB\-\-mark \fIMARK
.br MISSING
Use IPv4 only.
.TP
.B \-6
.br
Use IPv6 only. (IPV4 may be used for DNS lookups).
.SH BUGS .SH BUGS
Some modern routers give a lower priority to ICMP ECHO packets than Some modern routers give a lower priority to ICMP ECHO packets than
to other network traffic. Consequently, the reliability of these to other network traffic. Consequently, the reliability of these
routers reported by routers reported by
.B mtr .B mtr
will be significantly lower than the actual reliability of will be significantly lower than the actual reliability of
these routers. these routers.
.SH CONTACT INFORMATION .SH CONTACT INFORMATION
.PP .PP
For the latest version, see the mtr web page at For the latest version, see the mtr web page at
.BR http://www.bitwizard.nl/mtr/ . .BR http://www.bitwizard.nl/mtr/ .
.PP .PP
The mtr mailinglist was little used and is no longer active. The mtr mailinglist was little used and is no longer active.
.PP .PP
For patches, bug reports, or feature requests, please open an issue on For patches, bug reports, or feature requests, please open an issue on
GitHub at: GitHub at:
.BR https://github.com/traviscross/mtr . .BR https://github.com/traviscross/mtr .
.SH "SEE ALSO" .SH "SEE ALSO"
traceroute(8), traceroute(8),
ping(8) ping(8)
TCP/IP Illustrated (Stevens, ISBN 0201633469). TCP/IP Illustrated (Stevens, ISBN 0201633469).

58
mtr.c
View File

@ -257,9 +257,20 @@ void parse_arg (int argc, char **argv)
{ {
int opt; int opt;
int i; int i;
/* IMPORTANT: when adding or modifying an option:
1/ mind the order of options, there is some logic;
2/ update the getopt_long call below;
3/ update the man page (use the same order);
4/ update the help message showed when using --help.
*/
static struct option long_options[] = { static struct option long_options[] = {
{ "version", 0, 0, 'v' },
{ "help", 0, 0, 'h' }, { "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
{ "inet", 0, 0, '4' }, /* IPv4 only */
{ "inet6", 0, 0, '6' }, /* IPv6 only */
{ "filename", 1, 0, 'F' },
{ "report", 0, 0, 'r' }, { "report", 0, 0, 'r' },
{ "report-wide", 0, 0, 'w' }, { "report-wide", 0, 0, 'w' },
@ -271,7 +282,13 @@ void parse_arg (int argc, char **argv)
{ "split", 0, 0, 'p' }, /* BL */ { "split", 0, 0, 'p' }, /* BL */
/* maybe above should change to -d 'x' */ /* maybe above should change to -d 'x' */
{ "order", 1, 0, 'o' }, /* fileds to display & their order */ { "no-dns", 0, 0, 'n' },
{ "show-ips", 0, 0, 'b' },
{ "order", 1, 0, 'o' }, /* fields to display & their order */
#ifdef IPINFO
{ "ipinfo", 1, 0, 'y' }, /* IP info lookup */
{ "aslookup", 0, 0, 'z' }, /* Do AS lookup (--ipinfo 0) */
#endif
{ "interval", 1, 0, 'i' }, { "interval", 1, 0, 'i' },
{ "report-cycles", 1, 0, 'c' }, { "report-cycles", 1, 0, 'c' },
@ -280,22 +297,13 @@ void parse_arg (int argc, char **argv)
{ "bitpattern", 1, 0, 'B' },/* overload b>255, ->rand(0,255) */ { "bitpattern", 1, 0, 'B' },/* overload b>255, ->rand(0,255) */
{ "tos", 1, 0, 'Q' }, /* typeof service (0,255) */ { "tos", 1, 0, 'Q' }, /* typeof service (0,255) */
{ "mpls", 0, 0, 'e' }, { "mpls", 0, 0, 'e' },
{ "no-dns", 0, 0, 'n' },
{ "show-ips", 0, 0, 'b' },
{ "address", 1, 0, 'a' }, { "address", 1, 0, 'a' },
{ "first-ttl", 1, 0, 'f' }, /* -f & -m are borrowed from traceroute */ { "first-ttl", 1, 0, 'f' }, /* -f & -m are borrowed from traceroute */
{ "filename", 1, 0, 'F' },
{ "max-ttl", 1, 0, 'm' }, { "max-ttl", 1, 0, 'm' },
{ "udp", 0, 0, 'u' }, /* UDP (default is ICMP) */ { "udp", 0, 0, 'u' }, /* UDP (default is ICMP) */
{ "tcp", 0, 0, 'T' }, /* TCP (default is ICMP) */ { "tcp", 0, 0, 'T' }, /* TCP (default is ICMP) */
{ "port", 1, 0, 'P' }, /* target port number for TCP */ { "port", 1, 0, 'P' }, /* target port number for TCP */
{ "timeout", 1, 0, 'Z' }, /* timeout for TCP sockets */ { "timeout", 1, 0, 'Z' }, /* timeout for TCP sockets */
{ "inet", 0, 0, '4' }, /* IPv4 only */
{ "inet6", 0, 0, '6' }, /* IPv6 only */
#ifdef IPINFO
{ "ipinfo", 1, 0, 'y' }, /* IP info lookup */
{ "aslookup", 0, 0, 'z' }, /* Do AS lookup (--ipinfo 0) */
#endif
#ifdef SO_MARK #ifdef SO_MARK
{ "mark", 1, 0, 'M' }, /* use SO_MARK */ { "mark", 1, 0, 'M' }, /* use SO_MARK */
#endif #endif
@ -304,9 +312,8 @@ void parse_arg (int argc, char **argv)
opt = 0; opt = 0;
while(1) { while(1) {
/* added f:m:o: byMin */
opt = getopt_long(argc, argv, opt = getopt_long(argc, argv,
"vhrwxtglCpo:B:i:c:s:Q:ena:f:m:uTP:Zby:z46", long_options, NULL); "hv46F:rwxtglCpnbo:y:zi:c:s:B:Q:ea:f:m:uTP:Z:M:", long_options, NULL);
if(opt == -1) if(opt == -1)
break; break;
@ -586,21 +593,16 @@ int main(int argc, char **argv)
} }
if (PrintHelp) { if (PrintHelp) {
printf("usage: %s [-BfhvrwctglxspQomniuT46] [--help] [--version] [--report]\n" printf("usage: %s [--help] [--version] [-4|-6] [-F FILENAME]\n"
"\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n" "\t\t[--report] [--report-wide]\n"
"\t\t[--csv|-C] [--raw] [--xml] [--split] [--mpls] [--no-dns] [--show-ips]\n" "\t\t[--xml] [--gtk] [--curses] [--raw] [--csv] [--split]\n"
"\t\t[--address interface] [--filename=FILE|-F]\n" /* BL */ "\t\t[--no-dns] [--show-ips] [-o FIELDS] [-y IPINFO] [--aslookup]\n"
#ifdef IPINFO "\t\t[-i INTERVAL] [-c COUNT] [-s PACKETSIZE] [-B BITPATTERN]\n"
"\t\t[--ipinfo=item_no|-y item_no]\n" "\t\t[-Q TOS] [--mpls]\n"
"\t\t[--aslookup|-z]\n" "\t\t[-a ADDRESS] [-f FIRST-TTL] [-m MAX-TTL]\n"
#endif "\t\t[--udp] [--tcp] [-P PORT] [-Z TIMEOUT]\n"
#ifdef SO_MARK "\t\t[-M MARK] HOSTNAME\n", argv[0]);
"\t\t[--mark=NUM]\n" printf("See the man page for details.\n");
#endif
"\t\t[--psize=bytes/-s bytes] [--order fields]\n" /* ok */
"\t\t[--report-wide|-w] [--inet] [--inet6] [--max-ttl=NUM] [--first-ttl=NUM]\n"
"\t\t[--bitpattern=NUM] [--tos=NUM] [--udp] [--tcp] [--port=PORT] [--timeout=SECONDS]\n" /* rew */
"\t\t[--interval=SECONDS] HOSTNAME\n", argv[0]);
exit(0); exit(0);
} }