summaryrefslogtreecommitdiff
path: root/usr.sbin/traceroute
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-07-23 10:52:29 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-07-23 10:52:29 +0000
commit4f200b3097d8dafb0964403dab658d99329a1d9f (patch)
tree8b69fb93982132b694c7e1dc219bb65505af4cf6 /usr.sbin/traceroute
parent3c3b6a6d1bb369bca9d8a0c26cee1c02bf11d84e (diff)
open sockets then revoke privs; and a strdup() solution from freebsd
Diffstat (limited to 'usr.sbin/traceroute')
-rw-r--r--usr.sbin/traceroute/traceroute.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index b66db3ed072..13a02356d85 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -304,6 +304,16 @@ main(argc, argv)
int ch, i, lsrr, on, probe, seq, tos, ttl;
struct ip *ip;
+ if ((pe = getprotobyname("icmp")) == NULL) {
+ Fprintf(stderr, "icmp: unknown protocol\n");
+ exit(10);
+ }
+ if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0)
+ err(5, "icmp socket");
+ if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
+ err(5, "raw socket");
+ setuid(getuid());
+
lsrr = 0;
on = 1;
seq = tos = 0;
@@ -390,7 +400,7 @@ main(argc, argv)
errx(1, "unknown host %s", *argv);
to.sin_family = hp->h_addrtype;
memcpy(&to.sin_addr, hp->h_addr, hp->h_length);
- hostname = hp->h_name;
+ hostname = strdup(hp->h_name);
}
if (*++argv)
datalen = atoi(*argv);
@@ -426,22 +436,12 @@ main(argc, argv)
ident = (getpid() & 0xffff) | 0x8000;
- if ((pe = getprotobyname("icmp")) == NULL) {
- Fprintf(stderr, "icmp: unknown protocol\n");
- exit(10);
- }
- if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0)
- err(5, "icmp socket");
if (options & SO_DEBUG)
(void) setsockopt(s, SOL_SOCKET, SO_DEBUG,
(char *)&on, sizeof(on));
if (options & SO_DONTROUTE)
(void) setsockopt(s, SOL_SOCKET, SO_DONTROUTE,
(char *)&on, sizeof(on));
-
- if ((sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
- err(5, "raw socket");
-
#ifdef SO_SNDBUF
if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&datalen,
sizeof(datalen)) < 0)