summaryrefslogtreecommitdiff
path: root/net/fping/patches/patch-ab
blob: a74cfb9c06c3b7677bdbb158b1eb7590b0602fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
$NetBSD: patch-ab,v 1.2 2001/08/23 17:15:15 abs Exp $

--- fping.c.orig	Thu Aug 23 18:10:14 2001
+++ fping.c
@@ -185,7 +185,9 @@
 
 extern char *optarg;
 extern int optind,opterr;
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__linux__)
 extern char *sys_errlist[];
+#endif
 
 
 #ifdef __cplusplus
@@ -234,9 +236,9 @@
 int timeout = DEFAULT_TIMEOUT;
 int interval = DEFAULT_INTERVAL;
 
-long max_reply=0;
-long min_reply=10000;
-int total_replies=0;
+long max_reply=0;	/* usec */
+long min_reply=10000;	/* usec */
+int total_replies=0;	/* usec */
 double sum_replies=0;
 
 struct timeval timeout_timeval;
@@ -385,6 +387,7 @@
          }
          if (!ping_file) errno_crash_and_burn("fopen");
          while(fgets(line,132,ping_file)) {
+           line[132-1] = '\0';
            sscanf(line,"%s",host);
               if ((!*host) || (host[0]=='#'))  /* magic to avoid comments */
                 continue;
@@ -411,8 +414,8 @@
       cursor=cursor->next;
   }
 
-  gettimeofday(&start_time,&tz);
   cursor=rrlist;
+  gettimeofday(&start_time,&tz);
   while (num_waiting) {  /* while pings are outstanding */
         if ( (timeval_diff(&current_time,&cursor->last_time)> timeout) ||
                                                 cursor->num_packets_sent==0)  {
@@ -455,11 +458,11 @@
           min_reply=0; max_reply=0; total_replies=1; sum_replies=0;
 }
 
-     fprintf(stderr," %8d msec (min round trip time)\n",min_reply);
-     fprintf(stderr," %8d msec (avg round trip time)\n",(int)sum_replies/total_replies);
-     fprintf(stderr," %8d msec (max round trip time)\n",max_reply);
+     fprintf(stderr," %8.3f msec (min round trip time)\n",min_reply/1000.0);
+     fprintf(stderr," %8.3f msec (avg round trip time)\n",sum_replies/total_replies/1000.0);
+     fprintf(stderr," %8.3f msec (max round trip time)\n",max_reply/1000.0);
      fprintf(stderr," %8.3f sec (elapsed real time)\n",
-	     timeval_diff( &end_time,&start_time)/1000.0);
+	     timeval_diff( &end_time,&start_time)/1000000.0);
      fprintf(stderr,"\n");
 
   }
@@ -493,8 +496,6 @@
   struct icmp *icp = (struct icmp *) buffer;
   int n,len;
 
-  gettimeofday(&h->last_time,&tz);
-
   icp->icmp_type = ICMP_ECHO;
   icp->icmp_code = 0;
   icp->icmp_cksum = 0;
@@ -504,12 +505,15 @@
 #define SIZE_PACK_SENT (sizeof(h->num_packets_sent))
 #define SIZE_LAST_TIME (sizeof(h->last_time))
 
-  bcopy(&h->last_time,&buffer[SIZE_ICMP_HDR],SIZE_LAST_TIME);
   bcopy(&h->num_packets_sent,
              &buffer[SIZE_ICMP_HDR+SIZE_LAST_TIME], SIZE_PACK_SENT);
 
   len = SIZE_ICMP_HDR+SIZE_LAST_TIME+SIZE_PACK_SENT;
 
+  /* set the time at the very last possible point */
+  gettimeofday(&h->last_time,&tz);
+  bcopy(&h->last_time,&buffer[SIZE_ICMP_HDR],SIZE_LAST_TIME);
+
   icp->icmp_cksum = in_cksum( (u_short *)icp, len );
 
   n = sendto( s, buffer, len, 0, (struct sockaddr *)&h->saddr, 
@@ -578,10 +582,12 @@
        return 1; /* packet received, don't about it anymore */
   }
 
+    /* get time of receipt as close to the real time as possible */
+    gettimeofday(&current_time,&tz);
+
     n=icp->icmp_seq;
     h=table[n];
 
-    gettimeofday(&current_time,&tz);
     bcopy(&icp->icmp_data[0],&sent_time,sizeof(sent_time));
     bcopy(&icp->icmp_data[SIZE_LAST_TIME],&the_index,  sizeof(the_index));
     this_reply = timeval_diff(&current_time,&sent_time);
@@ -594,7 +600,7 @@
        if (dns_flag) printf("%s",get_host_by_address(response_addr.sin_addr));
        else printf("%s",h->host);
        if (verbose_flag) printf(" is alive");
-       if (elapsed_flag) printf(" (%d msec)",this_reply);
+       if (elapsed_flag) printf(" (%.3f msec)",this_reply/1000.0);
        printf("\n");
     }
     num_alive++;
@@ -756,7 +762,7 @@
 
 temp = 
   (((a->tv_sec*1000000)+ a->tv_usec) - 
-     ((b->tv_sec*1000000)+ b->tv_usec))/1000;
+     ((b->tv_sec*1000000)+ b->tv_usec));
 
 return (long) temp;