Merge from vendor branch TNF:
[pkgsrc.git] / net / fping / patches / patch-ab
1 $NetBSD$
2
3 --- fping.c.orig        Mon Sep 20 13:10:23 1999
4 +++ fping.c     Mon Sep 20 13:15:05 1999
5 @@ -185,7 +185,9 @@
6  
7  extern char *optarg;
8  extern int optind,opterr;
9 +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
10  extern char *sys_errlist[];
11 +#endif
12  
13  
14  #ifdef __cplusplus
15 @@ -234,9 +236,9 @@
16  int timeout = DEFAULT_TIMEOUT;
17  int interval = DEFAULT_INTERVAL;
18  
19 -long max_reply=0;
20 -long min_reply=10000;
21 -int total_replies=0;
22 +long max_reply=0;      /* usec */
23 +long min_reply=10000;  /* usec */
24 +int total_replies=0;   /* usec */
25  double sum_replies=0;
26  
27  struct timeval timeout_timeval;
28 @@ -385,6 +387,7 @@
29           }
30           if (!ping_file) errno_crash_and_burn("fopen");
31           while(fgets(line,132,ping_file)) {
32 +           line[132-1] = '\0';
33             sscanf(line,"%s",host);
34                if ((!*host) || (host[0]=='#'))  /* magic to avoid comments */
35                  continue;
36 @@ -411,8 +414,8 @@
37        cursor=cursor->next;
38    }
39  
40 -  gettimeofday(&start_time,&tz);
41    cursor=rrlist;
42 +  gettimeofday(&start_time,&tz);
43    while (num_waiting) {  /* while pings are outstanding */
44          if ( (timeval_diff(&current_time,&cursor->last_time)> timeout) ||
45                                                  cursor->num_packets_sent==0)  {
46 @@ -455,11 +458,11 @@
47            min_reply=0; max_reply=0; total_replies=1; sum_replies=0;
48  }
49  
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);
59       fprintf(stderr,"\n");
60  
61    }
62 @@ -493,8 +496,6 @@
63    struct icmp *icp = (struct icmp *) buffer;
64    int n,len;
65  
66 -  gettimeofday(&h->last_time,&tz);
67 -
68    icp->icmp_type = ICMP_ECHO;
69    icp->icmp_code = 0;
70    icp->icmp_cksum = 0;
71 @@ -504,12 +505,15 @@
72  #define SIZE_PACK_SENT (sizeof(h->num_packets_sent))
73  #define SIZE_LAST_TIME (sizeof(h->last_time))
74  
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);
78  
79    len = SIZE_ICMP_HDR+SIZE_LAST_TIME+SIZE_PACK_SENT;
80  
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);
84 +
85    icp->icmp_cksum = in_cksum( (u_short *)icp, len );
86  
87    n = sendto( s, buffer, len, 0, (struct sockaddr *)&h->saddr, 
88 @@ -578,10 +582,12 @@
89         return 1; /* packet received, don't about it anymore */
90    }
91  
92 +    /* get time of receipt as close to the real time as possible */
93 +    gettimeofday(&current_time,&tz);
94 +
95      n=icp->icmp_seq;
96      h=table[n];
97  
98 -    gettimeofday(&current_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(&current_time,&sent_time);
102 @@ -594,7 +600,7 @@
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);
108         printf("\n");
109      }
110      num_alive++;
111 @@ -756,7 +762,7 @@
112  
113  temp = 
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));
117  
118  return (long) temp;
119