ping.c (27354) | ping.c (27508) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Muuss. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44/* 45static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; 46*/ 47static const char rcsid[] = | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Muuss. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44/* 45static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; 46*/ 47static const char rcsid[] = |
48 "$Id: ping.c,v 1.23 1997/07/09 20:33:58 julian Exp $"; | 48 "$Id: ping.c,v 1.24 1997/07/13 06:16:44 sef Exp $"; |
49#endif /* not lint */ 50 51/* 52 * P I N G . C 53 * 54 * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, 55 * measure round-trip-delays and packet loss across network paths. 56 * --- 9 unchanged lines hidden (view full) --- 66 * This program has to run SUID to ROOT to access the ICMP socket. 67 */ 68 69#include <sys/param.h> /* NB: we rely on this for <sys/types.h> */ 70 71#include <ctype.h> 72#include <err.h> 73#include <errno.h> | 49#endif /* not lint */ 50 51/* 52 * P I N G . C 53 * 54 * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, 55 * measure round-trip-delays and packet loss across network paths. 56 * --- 9 unchanged lines hidden (view full) --- 66 * This program has to run SUID to ROOT to access the ICMP socket. 67 */ 68 69#include <sys/param.h> /* NB: we rely on this for <sys/types.h> */ 70 71#include <ctype.h> 72#include <err.h> 73#include <errno.h> |
74#include <math.h> |
|
74#include <netdb.h> 75#include <signal.h> 76#include <stdio.h> 77#include <stdlib.h> 78#include <string.h> 79#include <sysexits.h> 80#include <termios.h> 81#include <unistd.h> --- 68 unchanged lines hidden (view full) --- 150int interval = 1; /* interval between packets */ 151int finish_up = 0; /* We've been told to finish up */ 152 153/* timing */ 154int timing; /* flag to do timing */ 155double tmin = 999999999.0; /* minimum round trip time */ 156double tmax = 0.0; /* maximum round trip time */ 157double tsum = 0.0; /* sum of all times, for doing average */ | 75#include <netdb.h> 76#include <signal.h> 77#include <stdio.h> 78#include <stdlib.h> 79#include <string.h> 80#include <sysexits.h> 81#include <termios.h> 82#include <unistd.h> --- 68 unchanged lines hidden (view full) --- 151int interval = 1; /* interval between packets */ 152int finish_up = 0; /* We've been told to finish up */ 153 154/* timing */ 155int timing; /* flag to do timing */ 156double tmin = 999999999.0; /* minimum round trip time */ 157double tmax = 0.0; /* maximum round trip time */ 158double tsum = 0.0; /* sum of all times, for doing average */ |
159double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ |
|
158 159int reset_kerninfo; 160sig_atomic_t siginfo_p; 161 162static void fill(char *, char *); 163static u_short in_cksum(u_short *, int); 164static void catcher(int sig); 165static void check_status(void); --- 478 unchanged lines hidden (view full) --- 644 tp = (struct timeval *)&icp->icmp_ip; 645#else 646 tp = (struct timeval *)icp->icmp_data; 647#endif 648 tvsub(&tv, tp); 649 triptime = ((double)tv.tv_sec) * 1000.0 + 650 ((double)tv.tv_usec) / 1000.0; 651 tsum += triptime; | 160 161int reset_kerninfo; 162sig_atomic_t siginfo_p; 163 164static void fill(char *, char *); 165static u_short in_cksum(u_short *, int); 166static void catcher(int sig); 167static void check_status(void); --- 478 unchanged lines hidden (view full) --- 646 tp = (struct timeval *)&icp->icmp_ip; 647#else 648 tp = (struct timeval *)icp->icmp_data; 649#endif 650 tvsub(&tv, tp); 651 triptime = ((double)tv.tv_sec) * 1000.0 + 652 ((double)tv.tv_usec) / 1000.0; 653 tsum += triptime; |
654 tsumsq += triptime * triptime; |
|
652 if (triptime < tmin) 653 tmin = triptime; 654 if (triptime > tmax) 655 tmax = triptime; 656 } 657 658 if (TST(icp->icmp_seq % mx_dup_ck)) { 659 ++nrepeats; --- 257 unchanged lines hidden (view full) --- 917 if (ntransmitted) 918 if (nreceived > ntransmitted) 919 (void)printf("-- somebody's printing up packets!"); 920 else 921 (void)printf("%d%% packet loss", 922 (int) (((ntransmitted - nreceived) * 100) / 923 ntransmitted)); 924 (void)putchar('\n'); | 655 if (triptime < tmin) 656 tmin = triptime; 657 if (triptime > tmax) 658 tmax = triptime; 659 } 660 661 if (TST(icp->icmp_seq % mx_dup_ck)) { 662 ++nrepeats; --- 257 unchanged lines hidden (view full) --- 920 if (ntransmitted) 921 if (nreceived > ntransmitted) 922 (void)printf("-- somebody's printing up packets!"); 923 else 924 (void)printf("%d%% packet loss", 925 (int) (((ntransmitted - nreceived) * 100) / 926 ntransmitted)); 927 (void)putchar('\n'); |
925 if (nreceived && timing) 926 (void)printf("round-trip min/avg/max = %.3f/%.3f/%.3f ms\n", 927 tmin, tsum / (nreceived + nrepeats), tmax); | 928 if (nreceived && timing) { 929 double n = nreceived + nrepeats; 930 double avg = tsum / n; 931 double vari = tsumsq / n - avg * avg; 932 printf("round-trip min/avg/max/stddev = " 933 "%.3f/%.3f/%.3f/%.3f ms\n", 934 tmin, avg, tmax, sqrt(vari)); 935 } |
928 if (reset_kerninfo && tcgetattr(STDOUT_FILENO, &ts) != -1) { 929 ts.c_lflag &= ~NOKERNINFO; 930 tcsetattr(STDOUT_FILENO, TCSANOW, &ts); 931 } 932 933 if (nreceived) 934 exit(0); 935 else --- 288 unchanged lines hidden --- | 936 if (reset_kerninfo && tcgetattr(STDOUT_FILENO, &ts) != -1) { 937 ts.c_lflag &= ~NOKERNINFO; 938 tcsetattr(STDOUT_FILENO, TCSANOW, &ts); 939 } 940 941 if (nreceived) 942 exit(0); 943 else --- 288 unchanged lines hidden --- |