summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-08-17 10:37:28 +0000
committerpeter <peter@FreeBSD.org>1996-08-17 10:37:28 +0000
commitd489b09360f37e44317d4751e6ae9a22152a8115 (patch)
treea3bd6b6d9bb49125732ab260385afdee7e91c849 /usr.sbin
parent09c95c56c1a46aca49137838118691239790b94c (diff)
downloadFreeBSD-src-d489b09360f37e44317d4751e6ae9a22152a8115.zip
FreeBSD-src-d489b09360f37e44317d4751e6ae9a22152a8115.tar.gz
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/traceroute/Makefile5
-rw-r--r--usr.sbin/traceroute/traceroute.c39
2 files changed, 40 insertions, 4 deletions
diff --git a/usr.sbin/traceroute/Makefile b/usr.sbin/traceroute/Makefile
index b9d6c20..337f129 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 <bsd.prog.mk>
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index e39be38..7df7b72 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))
OpenPOWER on IntegriCloud