Cleaned up revisions 1.22 and 1.23.

Fixed minor bugs in revisions 1.12 and 1.23 (variables assigned to in signal
handlers weren't declared as volatile).
This commit is contained in:
Bruce Evans 1997-07-20 06:09:55 +00:00
parent 96b89afc1d
commit 8f975bb321
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27533

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.24 1997/07/13 06:16:44 sef Exp $"; "$Id: ping.c,v 1.25 1997/07/18 17:52:05 wollman Exp $";
#endif /* not lint */ #endif /* not lint */
/* /*
@ -93,13 +93,13 @@ static const char rcsid[] =
#include <arpa/inet.h> #include <arpa/inet.h>
#define DEFDATALEN (64 - 8) /* default data length */ #define DEFDATALEN (64 - 8) /* default data length */
#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
/* runs out of buffer space */
#define MAXIPLEN 60 #define MAXIPLEN 60
#define MAXICMPLEN 76 #define MAXICMPLEN 76
#define MAXPACKET (65536 - 60 - 8)/* max packet size */ #define MAXPACKET (65536 - 60 - 8)/* max packet size */
#define MAXWAIT 10 /* max seconds to wait for response */ #define MAXWAIT 10 /* max seconds to wait for response */
#define NROUTES 9 /* number of record route slots */ #define NROUTES 9 /* number of record route slots */
#define FLOOD_BACKOFF 20000 /* usecs to back off if flooding */
/* reports we are out of buffer space */
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
@ -149,7 +149,6 @@ long nreceived; /* # of packets we got back */
long nrepeats; /* number of duplicates */ long nrepeats; /* number of duplicates */
long ntransmitted; /* sequence # for outbound packets = #sent */ long ntransmitted; /* sequence # for outbound packets = #sent */
int interval = 1; /* interval between packets */ int interval = 1; /* interval between packets */
int finish_up = 0; /* We've been told to finish up */
/* timing */ /* timing */
int timing; /* flag to do timing */ int timing; /* flag to do timing */
@ -158,15 +157,15 @@ double tmax = 0.0; /* maximum round trip time */
double tsum = 0.0; /* sum of all times, for doing average */ double tsum = 0.0; /* sum of all times, for doing average */
double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ double tsumsq = 0.0; /* sum of all times squared, for std. dev. */
volatile sig_atomic_t finish_up; /* nonzero if we've been told to finish up */
int reset_kerninfo; int reset_kerninfo;
sig_atomic_t siginfo_p; volatile sig_atomic_t siginfo_p;
static void fill(char *, char *); static void fill(char *, char *);
static u_short in_cksum(u_short *, int); static u_short in_cksum(u_short *, int);
static void catcher(int sig); static void catcher(int sig);
static void check_status(void); static void check_status(void);
static void stopit(int); static void finish(void) __dead2;
static void finish(int) __dead2;
static void pinger(void); static void pinger(void);
static char *pr_addr(struct in_addr); static char *pr_addr(struct in_addr);
static void pr_icmph(struct icmp *); static void pr_icmph(struct icmp *);
@ -174,6 +173,7 @@ static void pr_iph(struct ip *);
static void pr_pack(char *, int, struct sockaddr_in *); static void pr_pack(char *, int, struct sockaddr_in *);
static void pr_retip(struct ip *); static void pr_retip(struct ip *);
static void status(int); static void status(int);
static void stopit(int);
static void tvsub(struct timeval *, struct timeval *); static void tvsub(struct timeval *, struct timeval *);
static void usage(const char *) __dead2; static void usage(const char *) __dead2;
@ -460,7 +460,7 @@ main(argc, argv)
if ((options & F_FLOOD) == 0) if ((options & F_FLOOD) == 0)
catcher(0); /* start things going */ catcher(0); /* start things going */
while (finish_up == 0) { while (!finish_up) {
struct sockaddr_in from; struct sockaddr_in from;
register int cc; register int cc;
int fromlen; int fromlen;
@ -487,24 +487,24 @@ main(argc, argv)
if (npackets && nreceived >= npackets) if (npackets && nreceived >= npackets)
break; break;
} }
finish(0); finish();
/* NOTREACHED */ /* NOTREACHED */
exit(0); /* Make the compiler happy */ exit(0); /* Make the compiler happy */
} }
/* /*
* Stopit -- * stopit --
* * Set the global bit that causes the main loop to quit.
* set the global bit that cause everything to quit.. * Do NOT call finish() from here, since finish() does far too much
* do rNOT quit and exit from the signal handler! * to be called from a signal handler.
*/ */
void void
stopit(int ignored) stopit(sig)
int sig;
{ {
finish_up = 1; finish_up = 1;
} }
/* /*
* catcher -- * catcher --
* This routine causes another PING to be transmitted, and then * This routine causes another PING to be transmitted, and then
@ -551,6 +551,9 @@ catcher(int sig)
* and the sequence number is an ascending integer. The first 8 bytes * and the sequence number is an ascending integer. The first 8 bytes
* of the data portion are used to hold a UNIX "timeval" struct in host * of the data portion are used to hold a UNIX "timeval" struct in host
* byte-order, to compute the round-trip time. * byte-order, to compute the round-trip time.
*
* bug --
* this does far too much to be called from a signal handler.
*/ */
static void static void
pinger(void) pinger(void)
@ -582,7 +585,7 @@ pinger(void)
if (i < 0 || i != cc) { if (i < 0 || i != cc) {
if (i < 0) { if (i < 0) {
if ((options & F_FLOOD) && (errno == ENOBUFS)) { if (options & F_FLOOD && errno == ENOBUFS) {
usleep(FLOOD_BACKOFF); usleep(FLOOD_BACKOFF);
return; return;
} }
@ -591,9 +594,8 @@ pinger(void)
warn("%s: partial write: %d of %d bytes", warn("%s: partial write: %d of %d bytes",
hostname, cc, i); hostname, cc, i);
} }
} else { } else
ntransmitted++; /* only count those that made it out */ ntransmitted++; /* only count those that made it out */
}
if (!(options & F_QUIET) && options & F_FLOOD) if (!(options & F_QUIET) && options & F_FLOOD)
(void)write(STDOUT_FILENO, &DOT, 1); (void)write(STDOUT_FILENO, &DOT, 1);
} }
@ -619,7 +621,7 @@ pr_pack(buf, cc, from)
static char old_rr[MAX_IPOPTLEN]; static char old_rr[MAX_IPOPTLEN];
struct ip *ip; struct ip *ip;
struct timeval tv, *tp; struct timeval tv, *tp;
double triptime = 0.0; double triptime;
int hlen, dupflag; int hlen, dupflag;
(void)gettimeofday(&tv, (struct timezone *)NULL); (void)gettimeofday(&tv, (struct timezone *)NULL);
@ -641,6 +643,7 @@ pr_pack(buf, cc, from)
if (icp->icmp_id != ident) if (icp->icmp_id != ident)
return; /* 'Twas not our ECHO */ return; /* 'Twas not our ECHO */
++nreceived; ++nreceived;
triptime = 0.0;
if (timing) { if (timing) {
#ifndef icmp_data #ifndef icmp_data
tp = (struct timeval *)&icp->icmp_ip; tp = (struct timeval *)&icp->icmp_ip;
@ -904,7 +907,7 @@ check_status()
* Print out statistics, and give up. * Print out statistics, and give up.
*/ */
static void static void
finish(int sig) finish()
{ {
struct termios ts; struct termios ts;