summaryrefslogtreecommitdiffstats
path: root/usr.sbin/traceroute
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1995-07-23 01:25:33 +0000
committerache <ache@FreeBSD.org>1995-07-23 01:25:33 +0000
commitf40b6d385cacee2d35a7ae4e41af9a1a4cb86b07 (patch)
tree0698c06985827e349590906ee8b65abc54968629 /usr.sbin/traceroute
parentb35c09c9b0369b24fa58758063338b9b70528806 (diff)
downloadFreeBSD-src-f40b6d385cacee2d35a7ae4e41af9a1a4cb86b07.zip
FreeBSD-src-f40b6d385cacee2d35a7ae4e41af9a1a4cb86b07.tar.gz
bugfix: traceroute hangs forever, if another ICMP traffics exists and
timeout occurse, close PR 612 Submitted by: Bill Fenner <fenner@parc.xerox.com>
Diffstat (limited to 'usr.sbin/traceroute')
-rw-r--r--usr.sbin/traceroute/traceroute.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index 14849fd..bd9d250 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -268,7 +268,7 @@ struct opacket {
u_char packet[512]; /* last inbound (icmp) packet */
struct opacket *outpacket; /* last output (udp) packet */
-int wait_for_reply __P((int, struct sockaddr_in *));
+int wait_for_reply __P((int, struct sockaddr_in *, struct timeval *));
void send_probe __P((int, int));
double deltaT __P((struct timeval *, struct timeval *));
int packet_ok __P((u_char *, int, struct sockaddr_in *, int));
@@ -500,7 +500,7 @@ main(argc, argv)
(void) gettimeofday(&t1, &tz);
send_probe(++seq, ttl);
- while (cc = wait_for_reply(s, &from)) {
+ while (cc = wait_for_reply(s, &from, &t1)) {
(void) gettimeofday(&t2, &tz);
if ((i = packet_ok(packet, cc, &from, seq))) {
if (from.sin_addr.s_addr != lastaddr) {
@@ -552,18 +552,27 @@ main(argc, argv)
}
int
-wait_for_reply(sock, from)
+wait_for_reply(sock, from, sent)
int sock;
struct sockaddr_in *from;
+ struct timeval *sent;
{
fd_set fds;
- struct timeval wait;
+ struct timeval now, wait;
int cc = 0;
int fromlen = sizeof (*from);
FD_ZERO(&fds);
FD_SET(sock, &fds);
- wait.tv_sec = waittime; wait.tv_usec = 0;
+ gettimeofday(&now, NULL);
+ wait.tv_sec = (sent->tv_sec + waittime) - now.tv_sec;
+ wait.tv_usec = sent->tv_usec - now.tv_usec;
+ if (wait.tv_usec < 0) {
+ wait.tv_usec += 1000000;
+ wait.tv_sec--;
+ }
+ if (wait.tv_sec < 0)
+ wait.tv_sec = wait.tv_usec = 0;
if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0)
cc=recvfrom(s, (char *)packet, sizeof(packet), 0,
OpenPOWER on IntegriCloud