1) Fix usage to match convention and manual. Fix manual to match usage.

2) Must be root to run preload (OpenBSD ping.c 1.8)
3) Don't print all replies unless verbose and root (from idea in
   OpenBSD ping.c 1.10 and 1.11) to avoid leaking information available
   only to root.
4) Remove unused h: from option string to getopt.
5) Make the compiler happy with exit(0) (Lite-2?)

Reviewed by: Dan Cross <tenser@spitfire.ecsel.psu.edu>

Good candidate for 2.2 and 2.1 (as are many of the 1.17 changes).
This commit is contained in:
Warner Losh 1997-03-02 06:32:42 +00:00
parent 4d64566be2
commit f78ac61b3a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23251
2 changed files with 26 additions and 10 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 .\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\" $Id: ping.8,v 1.7 1997/02/22 14:33:06 peter Exp $ .\" $Id: ping.8,v 1.8 1997/03/01 20:19:18 wollman Exp $
.\" .\"
.Dd March 1, 1997 .Dd March 1, 1997
.Dt PING 8 .Dt PING 8
@ -42,15 +42,20 @@
packets to network hosts packets to network hosts
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm ping .Nm ping
.Op Fl adfnqrvLRQ .Op Fl QRadfnqrv
.Op Fl c Ar count .Op Fl c Ar count
.Op Fl i Ar wait .Op Fl i Ar wait
.Op Fl I Ar interface
.Op Fl l Ar preload .Op Fl l Ar preload
.Op Fl p Ar pattern .Op Fl p Ar pattern
.Op Fl s Ar packetsize .Op Fl s Ar packetsize
.Op Fl T Ar ttl [
.Ar host .Ar host
|
.Op Fl L
.Op Fl I Ar interface
.Op Fl T Ar ttl
.Ar mcast-group
]
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm Ping .Nm Ping
uses the uses the

View File

@ -45,7 +45,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
*/ */
static const char rcsid[] = static const char rcsid[] =
"$Id$"; "$Id: ping.c,v 1.17 1997/03/01 20:19:18 wollman Exp $";
#endif /* not lint */ #endif /* not lint */
/* /*
@ -205,7 +205,7 @@ main(argc, argv)
preload = 0; preload = 0;
datap = &outpack[8 + sizeof(struct timeval)]; datap = &outpack[8 + sizeof(struct timeval)];
while ((ch = getopt(argc, argv, "I:LQRT:c:adfh:i:l:np:qrs:v")) != -1) { while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:v")) != -1) {
switch(ch) { switch(ch) {
case 'a': case 'a':
options |= F_AUDIBLE; options |= F_AUDIBLE;
@ -249,6 +249,11 @@ main(argc, argv)
if (*ep || ep == optarg || ultmp > INT_MAX) if (*ep || ep == optarg || ultmp > INT_MAX)
errx(EX_USAGE, errx(EX_USAGE,
"invalid preload value: `%s'", optarg); "invalid preload value: `%s'", optarg);
if (getuid()) {
errno = EPERM;
err(EX_NOPERM, "-l flag");
}
options |= F_FLOOD;
preload = ultmp; preload = ultmp;
break; break;
case 'L': case 'L':
@ -465,6 +470,7 @@ main(argc, argv)
} }
finish(0); finish(0);
/* NOTREACHED */ /* NOTREACHED */
exit(0); /* Make the compiler happy */
} }
/* /*
@ -653,6 +659,10 @@ pr_pack(buf, cc, from)
* See if it's a reply to something that we sent. * See if it's a reply to something that we sent.
* We can compare IP destination, protocol, * We can compare IP destination, protocol,
* and ICMP type and ID. * and ICMP type and ID.
*
* Only print all the error messages if we are running
* as root to avoid leaking information not normally
* available to those not running as root.
*/ */
#ifndef icmp_data #ifndef icmp_data
struct ip *oip = &icp->icmp_ip; struct ip *oip = &icp->icmp_ip;
@ -661,7 +671,7 @@ pr_pack(buf, cc, from)
#endif #endif
struct icmp *oicmp = (struct icmp *)(oip + 1); struct icmp *oicmp = (struct icmp *)(oip + 1);
if ((options & F_VERBOSE) || if (((options & F_VERBOSE) && getuid() == 0) ||
(!(options & F_QUIET2) && (!(options & F_QUIET2) &&
(oip->ip_dst.s_addr == (oip->ip_dst.s_addr ==
((struct sockaddr_in *)&whereto)->sin_addr.s_addr) && ((struct sockaddr_in *)&whereto)->sin_addr.s_addr) &&
@ -1085,7 +1095,7 @@ pr_addr(ina)
struct in_addr ina; struct in_addr ina;
{ {
struct hostent *hp; struct hostent *hp;
static char buf[80]; static char buf[16 + 3 + MAXHOSTNAMELEN];
if ((options & F_NUMERIC) || if ((options & F_NUMERIC) ||
!(hp = gethostbyaddr((char *)&ina, 4, AF_INET))) !(hp = gethostbyaddr((char *)&ina, 4, AF_INET)))
@ -1157,9 +1167,10 @@ static void
usage(argv0) usage(argv0)
const char *argv0; const char *argv0;
{ {
warnx("usage:"); if (strrchr(argv0,'/'))
argv0 = strrchr(argv0,'/') + 1;
fprintf(stderr, fprintf(stderr,
"\t%s [-QRadfnqrv] [-c count] [-i wait] [-l preload] " "usage: %s [-QRadfnqrv] [-c count] [-i wait] [-l preload] "
"[-p pattern]\n\t\t[-s packetsize] " "[-p pattern]\n\t\t[-s packetsize] "
"[host | [-L] [-I iface] [-T ttl] mcast-group]\n", "[host | [-L] [-I iface] [-T ttl] mcast-group]\n",
argv0); argv0);