mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 14:39:37 +00:00
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:
parent
4d64566be2
commit
f78ac61b3a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23251
@ -30,7 +30,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)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
|
||||
.Dt PING 8
|
||||
@ -42,15 +42,20 @@
|
||||
packets to network hosts
|
||||
.Sh SYNOPSIS
|
||||
.Nm ping
|
||||
.Op Fl adfnqrvLRQ
|
||||
.Op Fl QRadfnqrv
|
||||
.Op Fl c Ar count
|
||||
.Op Fl i Ar wait
|
||||
.Op Fl I Ar interface
|
||||
.Op Fl l Ar preload
|
||||
.Op Fl p Ar pattern
|
||||
.Op Fl s Ar packetsize
|
||||
.Op Fl T Ar ttl
|
||||
[
|
||||
.Ar host
|
||||
|
|
||||
.Op Fl L
|
||||
.Op Fl I Ar interface
|
||||
.Op Fl T Ar ttl
|
||||
.Ar mcast-group
|
||||
]
|
||||
.Sh DESCRIPTION
|
||||
.Nm Ping
|
||||
uses the
|
||||
|
@ -45,7 +45,7 @@ static const char copyright[] =
|
||||
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
|
||||
*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
"$Id: ping.c,v 1.17 1997/03/01 20:19:18 wollman Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -205,7 +205,7 @@ main(argc, argv)
|
||||
preload = 0;
|
||||
|
||||
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) {
|
||||
case 'a':
|
||||
options |= F_AUDIBLE;
|
||||
@ -249,6 +249,11 @@ main(argc, argv)
|
||||
if (*ep || ep == optarg || ultmp > INT_MAX)
|
||||
errx(EX_USAGE,
|
||||
"invalid preload value: `%s'", optarg);
|
||||
if (getuid()) {
|
||||
errno = EPERM;
|
||||
err(EX_NOPERM, "-l flag");
|
||||
}
|
||||
options |= F_FLOOD;
|
||||
preload = ultmp;
|
||||
break;
|
||||
case 'L':
|
||||
@ -465,6 +470,7 @@ main(argc, argv)
|
||||
}
|
||||
finish(0);
|
||||
/* 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.
|
||||
* We can compare IP destination, protocol,
|
||||
* 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
|
||||
struct ip *oip = &icp->icmp_ip;
|
||||
@ -661,7 +671,7 @@ pr_pack(buf, cc, from)
|
||||
#endif
|
||||
struct icmp *oicmp = (struct icmp *)(oip + 1);
|
||||
|
||||
if ((options & F_VERBOSE) ||
|
||||
if (((options & F_VERBOSE) && getuid() == 0) ||
|
||||
(!(options & F_QUIET2) &&
|
||||
(oip->ip_dst.s_addr ==
|
||||
((struct sockaddr_in *)&whereto)->sin_addr.s_addr) &&
|
||||
@ -1085,7 +1095,7 @@ pr_addr(ina)
|
||||
struct in_addr ina;
|
||||
{
|
||||
struct hostent *hp;
|
||||
static char buf[80];
|
||||
static char buf[16 + 3 + MAXHOSTNAMELEN];
|
||||
|
||||
if ((options & F_NUMERIC) ||
|
||||
!(hp = gethostbyaddr((char *)&ina, 4, AF_INET)))
|
||||
@ -1157,9 +1167,10 @@ static void
|
||||
usage(argv0)
|
||||
const char *argv0;
|
||||
{
|
||||
warnx("usage:");
|
||||
if (strrchr(argv0,'/'))
|
||||
argv0 = strrchr(argv0,'/') + 1;
|
||||
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] "
|
||||
"[host | [-L] [-I iface] [-T ttl] mcast-group]\n",
|
||||
argv0);
|
||||
|
Loading…
Reference in New Issue
Block a user