1) Minor nits in the usage message from bde. I took out the hard tabs and

used spaces to align the second line under the program name.
2) Cache uid after call to setuid(getuid()) so we don't waste a system call
   for each packet with a call to getuid for the -v case.
3) Update manual to reflect new restriction on -l from last delta.

Suggested by:	bde, Bill Fenner
This commit is contained in:
Warner Losh 1997-03-02 20:01:13 +00:00
parent 984e3edbe2
commit ee2bf73496
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23295
2 changed files with 7 additions and 4 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.8 1997/03/01 20:19:18 wollman Exp $ .\" $Id: ping.8,v 1.9 1997/03/02 06:32:42 imp Exp $
.\" .\"
.Dd March 1, 1997 .Dd March 1, 1997
.Dt PING 8 .Dt PING 8
@ -120,6 +120,7 @@ is specified,
.Nm ping .Nm ping
sends that many packets as fast as possible before falling into its normal sends that many packets as fast as possible before falling into its normal
mode of behavior. mode of behavior.
Only the super-user may use this option.
.It Fl L .It Fl L
Suppress loopback of multicast packets. Suppress loopback of multicast packets.
This flag only applies if the ping destination is a multicast address. This flag only applies if the ping destination is a multicast address.

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: ping.c,v 1.17 1997/03/01 20:19:18 wollman Exp $"; "$Id: ping.c,v 1.18 1997/03/02 06:32:40 imp Exp $";
#endif /* not lint */ #endif /* not lint */
/* /*
@ -138,6 +138,7 @@ char BSPACE = '\b'; /* characters written for flood */
char DOT = '.'; char DOT = '.';
char *hostname; char *hostname;
int ident; /* process id to identify our packets */ int ident; /* process id to identify our packets */
int uid; /* cached uid for micro-optimization */
/* counters */ /* counters */
long npackets; /* max packets to transmit */ long npackets; /* max packets to transmit */
@ -201,6 +202,7 @@ main(argc, argv)
sockerrno = errno; sockerrno = errno;
setuid(getuid()); setuid(getuid());
uid = getuid();
preload = 0; preload = 0;
@ -671,7 +673,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) && getuid() == 0) || if (((options & F_VERBOSE) && uid == 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) &&
@ -1171,7 +1173,7 @@ usage(argv0)
argv0 = strrchr(argv0,'/') + 1; argv0 = strrchr(argv0,'/') + 1;
fprintf(stderr, fprintf(stderr,
"usage: %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 [-s packetsize] "
"[host | [-L] [-I iface] [-T ttl] mcast-group]\n", "[host | [-L] [-I iface] [-T ttl] mcast-group]\n",
argv0); argv0);
exit(EX_USAGE); exit(EX_USAGE);