--- ping.c.orig Fri Jun 30 00:16:47 2000 +++ ping.c Thu Jun 29 22:13:18 2000 @@ -79,6 +79,7 @@ #include #include #include +#include /* * Note: on some systems dropping root makes the process dumpable or @@ -151,6 +152,7 @@ #define F_SO_DEBUG 0x040 #define F_SO_DONTROUTE 0x080 #define F_VERBOSE 0x100 +#define F_STD_DEV 0x200 /* multicast options */ int moptions; @@ -197,6 +199,9 @@ static u_long tmax = 0; /* maximum round trip time */ static u_long tsum; /* sum of all times, for doing average */ +/* sum of the squares of the times, for doing standard deviations */ +static u_long tsumsquared = 0; + /* protos */ static char *pr_addr(u_long); static int in_cksum(u_short *addr, int len); @@ -254,7 +259,7 @@ preload = 0; datap = &outpack[8 + sizeof(struct timeval)]; - while ((ch = getopt(argc, argv, "I:LRc:dfh:i:l:np:qrs:t:v")) != EOF) + while ((ch = getopt(argc, argv, "I:LRSc:dfh:i:l:np:qrs:t:v")) != EOF) switch(ch) { case 'c': npackets = atoi(optarg); @@ -339,6 +344,9 @@ moptions |= MULTICAST_NOLOOP; loop = 0; break; + case 'S': + options |= F_STD_DEV; + break; case 't': moptions |= MULTICAST_TTL; i = atoi(optarg); @@ -727,6 +735,7 @@ tvsub(&tv, tp); triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100); tsum += triptime; + tsumsquared += triptime * triptime; if (triptime < tmin && !negflag) tmin = triptime; if (triptime > tmax && !negflag) @@ -933,6 +942,10 @@ static void finish(int ignore) { + u_long count; + u_long mean; + u_long deviation; + (void)ignore; (void)signal(SIGINT, SIG_IGN); @@ -957,6 +970,16 @@ (tsum / (nreceived + nrepeats))/10, (tsum / (nreceived + nrepeats))%10, tmax/10, tmax%10); + + if (nreceived && timing && (options & F_STD_DEV)) { + /* Note: timing is in 100's of microseconds. */ + count = nreceived + nrepeats; + if( count > 1 ) { + mean = tsum / count; + deviation = sqrt( ((tsumsquared - count*mean*mean) / (count - 1))*1.0 ); + (void)printf("round-trip deviation = %lu.%lu ms\n", deviation/10, deviation%10 ); + } + } if (nreceived==0) exit(1); exit(0); --- Makefile.orig Thu Jun 29 22:16:17 2000 +++ Makefile Thu Jun 29 21:58:34 2000 @@ -13,7 +13,7 @@ $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ install: ping - install -o root -g root -m$(SUIDMODE) ping $(INSTALLROOT)$(ROOTBINDIR) + install -o root -g root -m$(SUIDMODE) ping $(INSTALLROOT)$(ROOTBINDIR) -lmath install -m$(MANMODE) ping.8 $(INSTALLROOT)$(MANDIR)/man8 clean: