Add multicast options -I (source interface), -T (set ttl), -L (no loopback).

They were all lowercase in the original, but our ping already uses -i and
-l so I made them all uppercase.

Obtained from:	Multicast release 3.5
This commit is contained in:
Bill Fenner 1996-12-15 23:41:29 +00:00
parent d26d022d05
commit 854569350f
2 changed files with 80 additions and 15 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\" $Id$
.\" $Id: ping.8,v 1.3 1996/10/05 22:27:04 wosch Exp $
.\"
.Dd December 11, 1993
.Dt PING 8
@ -42,12 +42,15 @@
packets to network hosts
.Sh SYNOPSIS
.Nm ping
.Op Fl dfnqrvRQ
.Op Fl dfnqrvLRQ
.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
.Sh DESCRIPTION
.Nm Ping
uses the
@ -99,6 +102,9 @@ The default is to wait for one second between each packet.
This option is incompatible with the
.Fl f
option.
.It Fl I Ar interface
Source multicast packets with the given interface address.
This flag only applies if the ping destination is a multicast address.
.It Fl l Ar preload
If
.Ar preload
@ -106,6 +112,9 @@ is specified,
.Nm ping
sends that many packets as fast as possible before falling into its normal
mode of behavior.
.It Fl L
Suppress loopback of multicast packets.
This flag only applies if the ping destination is a multicast address.
.It Fl n
Numeric output only.
No attempt will be made to lookup symbolic names for host addresses.
@ -159,6 +168,9 @@ data bytes when combined
with the 8 bytes of
.Tn ICMP
header data.
.It Fl T Ar ttl
Set the IP Time To Live for multicasted packets.
This flag only applies if the ping destination is a multicast address.
.It Fl v
Verbose output.
.Tn ICMP
@ -216,11 +228,15 @@ given.
.Sh DUPLICATE AND DAMAGED PACKETS
.Nm Ping
will report duplicate and damaged packets.
Duplicate packets should never occur, and seem to be caused by
Duplicate packets should never occur when pinging a unicast address,
and seem to be caused by
inappropriate link-level retransmissions.
Duplicates may occur in many situations and are rarely (if ever) a
good sign, although the presence of low levels of duplicates may not
always be cause for alarm.
Duplicates are expected when pinging a broadcast or multicast address,
since they are not really duplicates but replies from different hosts
to the same request.
.Pp
Damaged packets are obviously serious cause for alarm and often
indicate broken hardware somewhere in the

View File

@ -96,16 +96,19 @@ static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
/* various options */
int options;
#define F_FLOOD 0x001
#define F_INTERVAL 0x002
#define F_NUMERIC 0x004
#define F_PINGFILLED 0x008
#define F_QUIET 0x010
#define F_RROUTE 0x020
#define F_SO_DEBUG 0x040
#define F_SO_DONTROUTE 0x080
#define F_VERBOSE 0x100
#define F_QUIET2 0x200
#define F_FLOOD 0x0001
#define F_INTERVAL 0x0002
#define F_NUMERIC 0x0004
#define F_PINGFILLED 0x0008
#define F_QUIET 0x0010
#define F_RROUTE 0x0020
#define F_SO_DEBUG 0x0040
#define F_SO_DONTROUTE 0x0080
#define F_VERBOSE 0x0100
#define F_QUIET2 0x0200
#define F_NOLOOP 0x0400
#define F_MTTL 0x0800
#define F_MIF 0x1000
/*
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@ -157,6 +160,8 @@ main(argc, argv)
struct termios ts;
register int i;
int ch, fdmask, hold, packlen, preload, sockerrno;
struct in_addr ifaddr;
unsigned char ttl, loop;
u_char *datap, *packet;
char *target, hnamebuf[MAXHOSTNAMELEN], *malloc();
#ifdef IP_OPTIONS
@ -180,7 +185,7 @@ main(argc, argv)
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
while ((ch = getopt(argc, argv, "QRc:dfh:i:l:np:qrs:v")) != EOF)
while ((ch = getopt(argc, argv, "I:LQRT:c:dfh:i:l:np:qrs:v")) != EOF)
switch(ch) {
case 'c':
npackets = atoi(optarg);
@ -211,6 +216,14 @@ main(argc, argv)
}
options |= F_INTERVAL;
break;
case 'I': /* multicast interface */
if (inet_aton(optarg, &ifaddr) == 0) {
(void)fprintf(stderr,
"ping: bad multicast interface.\n");
exit(1);
}
options |= F_MIF;
break;
case 'l':
preload = atoi(optarg);
if (preload < 0) {
@ -219,6 +232,10 @@ main(argc, argv)
exit(1);
}
break;
case 'L':
options |= F_NOLOOP;
loop = 0;
break;
case 'n':
options |= F_NUMERIC;
break;
@ -251,6 +268,16 @@ main(argc, argv)
exit(1);
}
break;
case 'T': /* multicast TTL */
i = atoi(optarg);
if (i < 0 || i > 255) {
(void)fprintf(stderr,
"ping: illegal multicast TTL.\n");
exit(1);
}
ttl = i;
options |= F_MTTL;
break;
case 'v':
options |= F_VERBOSE;
break;
@ -337,6 +364,28 @@ main(argc, argv)
#endif /* IP_OPTIONS */
}
if (options & F_NOLOOP) {
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop,
sizeof(loop)) < 0) {
perror("ping: IP_MULTICAST_LOOP");
exit(1);
}
}
if (options & F_MTTL) {
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
sizeof(ttl)) < 0) {
perror("ping: IP_MULTICAST_TTL");
exit(1);
}
}
if (options & F_MIF) {
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &ifaddr,
sizeof(ifaddr)) < 0) {
perror("ping: IP_MULTICAST_IF");
exit(1);
}
}
/*
* When pinging the broadcast address, you can get a lot of answers.
* Doing something so evil is useful if you are trying to stress the
@ -1085,6 +1134,6 @@ fill(bp, patp)
usage()
{
(void)fprintf(stderr,
"usage: ping [-Rdfnqrv] [-c count] [-i wait] [-l preload]\n\t[-p pattern] [-s packetsize] host\n");
"usage: ping [-LQRdfnqrv] [-c count] [-i wait] [-I interface]\n\t[-l preload] [-p pattern] [-s packetsize] [-T ttl] host\n");
exit(1);
}