From b011f9fd8f882b7737f7d32d8c455ddcf13455ab Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sat, 17 Aug 1996 10:37:28 +0000 Subject: [PATCH] Fixes from NetBSD: - inet_ntoa() returns a pointer to a static buffer, dont use it twice in the same printf(). - prevent the possibility of never timing out - Report two more ICMP error types (prohibited nets etc) And some (commented out) enhancements that I use, but some don't like. --- usr.sbin/traceroute/Makefile | 5 ++++ usr.sbin/traceroute/traceroute.c | 39 ++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/usr.sbin/traceroute/Makefile b/usr.sbin/traceroute/Makefile index b9d6c20c89f3..337f1294e64d 100644 --- a/usr.sbin/traceroute/Makefile +++ b/usr.sbin/traceroute/Makefile @@ -6,4 +6,9 @@ BINOWN= root BINMODE=4555 CFLAGS+=-DHAVE_BZERO=1 -DHAVE_SETLINEBUF=1 +# RTT Jitter on the internet these days means printing 3 decimal places on +# > 1000ms times is plain useless. Uncomment this to enable variable precision +# reporting, ie: print a variable precision from 0.001ms through 1000ms +# CFLAGS+=-DSANE_PRECISION + .include diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c index e39be381b597..7df7b726fdba 100644 --- a/usr.sbin/traceroute/traceroute.c +++ b/usr.sbin/traceroute/traceroute.c @@ -1,6 +1,6 @@ #ifndef lint static char *rcsid = - "@(#)$Header: /home/ncvs/src/usr.sbin/traceroute/traceroute.c,v 1.6 1996/08/09 06:00:53 fenner Exp $ (LBL)"; + "@(#)$Header: /home/ncvs/src/usr.sbin/traceroute/traceroute.c,v 1.7 1996/08/13 16:28:59 fenner Exp $ (LBL)"; #endif /* @@ -564,12 +564,35 @@ main(int argc, char **argv) send_probe(++seq, ttl, &t1); while ((cc = wait_for_reply(s, &from, &t1)) != 0) { (void) gettimeofday(&t2, &tz); + /* + * Since we'll be receiving all ICMP + * messages to this host above, we may + * never end up with cc=0, so we need + * an additional termination check. + */ + if (t2.tv_sec - t1.tv_sec > waittime) { + cc = 0; + break; + } if ((i = packet_ok(packet, cc, &from, seq))) { + double T; + int precis; if (from.sin_addr.s_addr != lastaddr) { print(packet, cc, &from); lastaddr = from.sin_addr.s_addr; } - Printf(" %.3f ms", deltaT(&t1, &t2)); + T = deltaT(&t1, &t2); +#ifdef SANE_PRECISION + if (T >= 1000.0) + precis = 0; + else if (T >= 100.0) + precis = 1; + else if (T >= 10.0) + precis = 2; + else +#endif + precis = 3; + Printf(" %.*f ms", precis, T); switch(i - 1) { case ICMP_UNREACH_PORT: #ifndef ARCHAIC @@ -599,6 +622,14 @@ main(int argc, char **argv) ++unreachable; Printf(" !S"); break; + case ICMP_UNREACH_NET_PROHIB: + ++unreachable; + Printf(" !A"); + break; + case ICMP_UNREACH_HOST_PROHIB: + ++unreachable; + Printf(" !C"); + break; } break; } @@ -737,8 +768,8 @@ packet_ok(u_char *buf, int cc, struct sockaddr_in *from, int seq) int i; u_long *lp = (u_long *)&icp->icmp_ip; - Printf("\n%d bytes from %s to %s", cc, - inet_ntoa(from->sin_addr), inet_ntoa(ip->ip_dst)); + Printf("\n%d bytes from %s", cc, inet_ntoa(from->sin_addr)); + Printf(" to %s", inet_ntoa(ip->ip_dst)); Printf(": icmp type %d (%s) code %d\n", type, pr_type(type), icp->icmp_code); for (i = 4; i < cc ; i += sizeof(long))