diff options
-rw-r--r-- | usr.sbin/traceroute/traceroute.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c index 13a02356d85..ae3e7fecfd0 100644 --- a/usr.sbin/traceroute/traceroute.c +++ b/usr.sbin/traceroute/traceroute.c @@ -266,7 +266,7 @@ int lsrrlen = 0; u_char packet[512], *outpacket; /* last inbound (icmp) 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, struct sockaddr_in *)); double deltaT __P((struct timeval *, struct timeval *)); int packet_ok __P((u_char *, int, struct sockaddr_in *, int)); @@ -491,7 +491,7 @@ main(argc, argv) (void) gettimeofday(&t1, &tz); send_probe(++seq, ttl, &to); - 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) { @@ -551,18 +551,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, |