3 --- fping.c.orig Mon Sep 20 13:10:23 1999
4 +++ fping.c Mon Sep 20 13:15:05 1999
8 extern int optind,opterr;
9 +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
10 extern char *sys_errlist[];
16 int timeout = DEFAULT_TIMEOUT;
17 int interval = DEFAULT_INTERVAL;
20 -long min_reply=10000;
22 +long max_reply=0; /* usec */
23 +long min_reply=10000; /* usec */
24 +int total_replies=0; /* usec */
27 struct timeval timeout_timeval;
30 if (!ping_file) errno_crash_and_burn("fopen");
31 while(fgets(line,132,ping_file)) {
33 sscanf(line,"%s",host);
34 if ((!*host) || (host[0]=='#')) /* magic to avoid comments */
40 - gettimeofday(&start_time,&tz);
42 + gettimeofday(&start_time,&tz);
43 while (num_waiting) { /* while pings are outstanding */
44 if ( (timeval_diff(¤t_time,&cursor->last_time)> timeout) ||
45 cursor->num_packets_sent==0) {
47 min_reply=0; max_reply=0; total_replies=1; sum_replies=0;
50 - fprintf(stderr," %8d msec (min round trip time)\n",min_reply);
51 - fprintf(stderr," %8d msec (avg round trip time)\n",(int)sum_replies/total_replies);
52 - fprintf(stderr," %8d msec (max round trip time)\n",max_reply);
53 + fprintf(stderr," %8.3f msec (min round trip time)\n",min_reply/1000.0);
54 + fprintf(stderr," %8.3f msec (avg round trip time)\n",sum_replies/total_replies/1000.0);
55 + fprintf(stderr," %8.3f msec (max round trip time)\n",max_reply/1000.0);
56 fprintf(stderr," %8.3f sec (elapsed real time)\n",
57 - timeval_diff( &end_time,&start_time)/1000.0);
58 + timeval_diff( &end_time,&start_time)/1000000.0);
63 struct icmp *icp = (struct icmp *) buffer;
66 - gettimeofday(&h->last_time,&tz);
68 icp->icmp_type = ICMP_ECHO;
72 #define SIZE_PACK_SENT (sizeof(h->num_packets_sent))
73 #define SIZE_LAST_TIME (sizeof(h->last_time))
75 - bcopy(&h->last_time,&buffer[SIZE_ICMP_HDR],SIZE_LAST_TIME);
76 bcopy(&h->num_packets_sent,
77 &buffer[SIZE_ICMP_HDR+SIZE_LAST_TIME], SIZE_PACK_SENT);
79 len = SIZE_ICMP_HDR+SIZE_LAST_TIME+SIZE_PACK_SENT;
81 + /* set the time at the very last possible point */
82 + gettimeofday(&h->last_time,&tz);
83 + bcopy(&h->last_time,&buffer[SIZE_ICMP_HDR],SIZE_LAST_TIME);
85 icp->icmp_cksum = in_cksum( (u_short *)icp, len );
87 n = sendto( s, buffer, len, 0, (struct sockaddr *)&h->saddr,
89 return 1; /* packet received, don't about it anymore */
92 + /* get time of receipt as close to the real time as possible */
93 + gettimeofday(¤t_time,&tz);
98 - gettimeofday(¤t_time,&tz);
99 bcopy(&icp->icmp_data[0],&sent_time,sizeof(sent_time));
100 bcopy(&icp->icmp_data[SIZE_LAST_TIME],&the_index, sizeof(the_index));
101 this_reply = timeval_diff(¤t_time,&sent_time);
103 if (dns_flag) printf("%s",get_host_by_address(response_addr.sin_addr));
104 else printf("%s",h->host);
105 if (verbose_flag) printf(" is alive");
106 - if (elapsed_flag) printf(" (%d msec)",this_reply);
107 + if (elapsed_flag) printf(" (%.3f msec)",this_reply/1000.0);
114 (((a->tv_sec*1000000)+ a->tv_usec) -
115 - ((b->tv_sec*1000000)+ b->tv_usec))/1000;
116 + ((b->tv_sec*1000000)+ b->tv_usec));