summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>1996-09-30 19:39:25 +0000
committerfenner <fenner@FreeBSD.org>1996-09-30 19:39:25 +0000
commit44721b732a7df98046e2de1e5ffac91fee7fce44 (patch)
tree04fbaa4ef62238d7c83c5beb005c89089e6e1414 /contrib
parent89f295a1d65e2294a6edeafab9a0fedb702c6baf (diff)
downloadFreeBSD-src-44721b732a7df98046e2de1e5ffac91fee7fce44.zip
FreeBSD-src-44721b732a7df98046e2de1e5ffac91fee7fce44.tar.gz
Add FreeBSD modifications
- Move setuid(getuid()) much earlier - Add "SANE_PRECISION" time printing code
Diffstat (limited to 'contrib')
-rw-r--r--contrib/traceroute/traceroute.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/contrib/traceroute/traceroute.c b/contrib/traceroute/traceroute.c
index 21612f8..b1b1b87 100644
--- a/contrib/traceroute/traceroute.c
+++ b/contrib/traceroute/traceroute.c
@@ -24,7 +24,7 @@ static const char copyright[] =
"@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
- "@(#)$Header: traceroute.c,v 1.43 96/09/27 20:08:10 leres Exp $ (LBL)";
+ "@(#)$Header: /home/ncvs/src/contrib/traceroute/traceroute.c,v 1.1.1.1 1996/09/30 19:09:55 fenner Exp $ (LBL)";
#endif
/*
@@ -313,6 +313,23 @@ main(int argc, char **argv)
register int tos = 0;
register int lsrr = 0;
register int optlen = 0;
+ int sockerrno;
+
+ /*
+ * Do the setuid-required stuff first, then lose priveleges ASAP.
+ * Do error checking for these two calls where they appeared in
+ * the original code.
+ */
+ cp = "icmp";
+ pe = getprotobyname(cp);
+ if (pe) {
+ if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0)
+ sockerrno = errno;
+ else if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
+ sockerrno = errno;
+ }
+
+ setuid(getuid());
if ((cp = strrchr(argv[0], '/')) != NULL)
prog = cp + 1;
@@ -487,12 +504,12 @@ main(int argc, char **argv)
outdata = (struct outdata *)(outudp + 1);
- cp = "icmp";
- if ((pe = getprotobyname(cp)) == NULL) {
+ if (pe == NULL) {
Fprintf(stderr, "%s: unknown protocol %s\n", prog, cp);
exit(1);
}
- if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) {
+ if (s < 0) {
+ errno = sockerrno;
Fprintf(stderr, "%s: icmp socket: %s\n", prog, strerror(errno));
exit(1);
}
@@ -503,14 +520,12 @@ main(int argc, char **argv)
(void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
sizeof(on));
- if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
+ if (sndsock < 0) {
+ errno = sockerrno;
Fprintf(stderr, "%s: raw socket: %s\n", prog, strerror(errno));
exit(1);
}
- /* Revert to non-privileged user after opening sockets */
- setuid(getuid());
-
#if defined(IP_OPTIONS) && !defined(HAVE_RAW_OPTIONS)
if (lsrr > 0) {
u_char optlist[MAX_IPOPTLEN];
@@ -599,6 +614,9 @@ main(int argc, char **argv)
(void)gettimeofday(&t1, &tz);
send_probe(++seq, ttl, &t1);
while ((cc = wait_for_reply(s, &from, &t1)) != 0) {
+ double T;
+ int precis;
+
(void)gettimeofday(&t2, &tz);
i = packet_ok(packet, cc, &from, seq);
/* Skip short packet */
@@ -608,7 +626,18 @@ main(int argc, char **argv)
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);
/* time exceeded in transit */
if (i == -1)
break;
OpenPOWER on IntegriCloud