Lines 1-146
Link Here
|
1 |
--- fping.c.orig Mon Jan 21 02:06:30 2002 |
|
|
2 |
+++ fping.c Tue Jul 12 18:11:30 2005 |
3 |
@@ -42,7 +42,6 @@ |
4 |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
5 |
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
6 |
*/ |
7 |
-#define IPV6 1 /* This should be a compiler option, or even better be done from the Makefile... ;) */ |
8 |
|
9 |
#ifndef _NO_PROTO |
10 |
#if !__STDC__ && !defined( __cplusplus ) && !defined( FUNCPROTO ) \ |
11 |
@@ -67,7 +66,7 @@ |
12 |
|
13 |
/*** autoconf includes ***/ |
14 |
|
15 |
- |
16 |
+#include <sys/types.h> |
17 |
#include <stdio.h> |
18 |
#include <errno.h> |
19 |
#include <time.h> |
20 |
@@ -88,7 +87,6 @@ |
21 |
#include <string.h> |
22 |
#include <stddef.h> |
23 |
|
24 |
-#include <sys/types.h> |
25 |
#include <sys/time.h> |
26 |
#include <sys/socket.h> |
27 |
|
28 |
@@ -112,6 +110,10 @@ |
29 |
#include <arpa/inet.h> |
30 |
#include <netdb.h> |
31 |
|
32 |
+#if (defined(__unix__) || defined(unix)) && !defined(USG) |
33 |
+#include <sys/param.h> |
34 |
+#endif |
35 |
+ |
36 |
/* RS6000 has sys/select.h */ |
37 |
#ifdef HAVE_SYS_SELECT_H |
38 |
#include <sys/select.h> |
39 |
@@ -246,13 +248,13 @@ |
40 |
struct timeval last_send_time; /* time of last packet sent */ |
41 |
int num_sent; /* number of ping packets sent */ |
42 |
int num_recv; /* number of pings received */ |
43 |
- int max_reply; /* longest response time */ |
44 |
- int min_reply; /* shortest response time */ |
45 |
+ long max_reply; /* longest response time */ |
46 |
+ long min_reply; /* shortest response time */ |
47 |
int total_time; /* sum of response times */ |
48 |
int num_sent_i; /* number of ping packets sent */ |
49 |
int num_recv_i; /* number of pings received */ |
50 |
- int max_reply_i; /* longest response time */ |
51 |
- int min_reply_i; /* shortest response time */ |
52 |
+ long max_reply_i; /* longest response time */ |
53 |
+ long min_reply_i; /* shortest response time */ |
54 |
int total_time_i; /* sum of response times */ |
55 |
int *resp_times; /* individual response times */ |
56 |
#if defined( DEBUG ) || defined( _DEBUG ) |
57 |
@@ -482,7 +484,7 @@ |
58 |
|
59 |
}/* IF */ |
60 |
|
61 |
- prog = argv[0]; |
62 |
+ prog = (prog = strrchr(argv[0], '/')) ? prog + 1 : argv[0]; |
63 |
ident = getpid() & 0xFFFF; |
64 |
|
65 |
verbose_flag = 1; |
66 |
@@ -502,8 +504,8 @@ |
67 |
break; |
68 |
|
69 |
case 'r': |
70 |
- if( !( retry = ( u_int )atoi( optarg ) ) ) |
71 |
- usage(); |
72 |
+ retry = ( u_int )atoi( optarg ); |
73 |
+ |
74 |
|
75 |
break; |
76 |
|
77 |
@@ -823,6 +825,7 @@ |
78 |
|
79 |
while( fgets( line, 132, ping_file ) ) |
80 |
{ |
81 |
+ line[132-1] = '\0'; |
82 |
if( sscanf( line, "%s", host ) != 1 ) |
83 |
continue; |
84 |
|
85 |
@@ -1503,7 +1506,6 @@ |
86 |
memset( buffer, 0, ping_pkt_size * sizeof( char ) ); |
87 |
icp = ( FPING_ICMPHDR* )buffer; |
88 |
|
89 |
- gettimeofday( &h->last_send_time, &tz ); |
90 |
#ifndef IPV6 |
91 |
icp->icmp_type = ICMP_ECHO; |
92 |
icp->icmp_code = 0; |
93 |
@@ -1512,6 +1514,8 @@ |
94 |
icp->icmp_id = ident; |
95 |
|
96 |
pdp = ( PING_DATA* )( buffer + SIZE_ICMP_HDR ); |
97 |
+ /* set the time at the very last possible point */ |
98 |
+ gettimeofday(&h->last_send_time,&tz); |
99 |
pdp->ping_ts = h->last_send_time; |
100 |
pdp->ping_count = h->num_sent; |
101 |
|
102 |
@@ -1523,6 +1527,8 @@ |
103 |
icp->icmp6_id = ident; |
104 |
|
105 |
pdp = ( PING_DATA* )( buffer + SIZE_ICMP_HDR ); |
106 |
+ /* set the time at the very last possible point */ |
107 |
+ gettimeofday(&h->last_send_time,&tz); |
108 |
pdp->ping_ts = h->last_send_time; |
109 |
pdp->ping_count = h->num_sent; |
110 |
|
111 |
@@ -1611,6 +1617,9 @@ |
112 |
|
113 |
result = recvfrom_wto( s, buffer, sizeof(buffer), &response_addr, select_time ); |
114 |
|
115 |
+ /* get time of receipt as close to the real time as possible */ |
116 |
+ gettimeofday(¤t_time,&tz); |
117 |
+ |
118 |
if( result < 0 ) |
119 |
return 0; /* timeout */ |
120 |
|
121 |
@@ -1625,7 +1634,7 @@ |
122 |
|
123 |
ip = ( struct ip* )buffer; |
124 |
#ifndef IPV6 |
125 |
-#if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ ) |
126 |
+#if defined( __alpha__ ) && defined(__osf1__) && __STDC__ && !defined( __GLIBC__ ) |
127 |
/* The alpha headers are decidedly broken. |
128 |
* Using an ANSI compiler, it provides ip_vhl instead of ip_hl and |
129 |
* ip_v. So, to get ip_hl, we mask off the bottom four bits. |
130 |
@@ -1633,7 +1642,7 @@ |
131 |
hlen = ( ip->ip_vhl & 0x0F ) << 2; |
132 |
#else |
133 |
hlen = ip->ip_hl << 2; |
134 |
-#endif /* defined(__alpha__) && __STDC__ */ |
135 |
+#endif /* defined(__alpha__) && defined(__osf1__) && __STDC__ */ |
136 |
if( result < hlen + ICMP_MINLEN ) |
137 |
#else |
138 |
if( result < sizeof(FPING_ICMPHDR) ) |
139 |
@@ -1690,7 +1699,6 @@ |
140 |
h = table[n]; |
141 |
|
142 |
/* received ping is cool, so process it */ |
143 |
- gettimeofday( ¤t_time, &tz ); |
144 |
h->waiting = 0; |
145 |
h->timeout = timeout; |
146 |
h->num_recv++; |