summaryrefslogtreecommitdiffstats
path: root/usr.sbin/traceroute6/traceroute6.c
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2001-06-11 12:39:29 +0000
committerume <ume@FreeBSD.org>2001-06-11 12:39:29 +0000
commit832f8d224926758a9ae0b23a6b45353e44fbc87a (patch)
treea79fc7ad2b97862c4a404f352f0211ad93a7b5f1 /usr.sbin/traceroute6/traceroute6.c
parent2693854b01a52b0395a91322aa3edf926bddff38 (diff)
downloadFreeBSD-src-832f8d224926758a9ae0b23a6b45353e44fbc87a.zip
FreeBSD-src-832f8d224926758a9ae0b23a6b45353e44fbc87a.tar.gz
Sync with recent KAME.
This work was based on kame-20010528-freebsd43-snap.tgz and some critical problem after the snap was out were fixed. There are many many changes since last KAME merge. TODO: - The definitions of SADB_* in sys/net/pfkeyv2.h are still different from RFC2407/IANA assignment because of binary compatibility issue. It should be fixed under 5-CURRENT. - ip6po_m member of struct ip6_pktopts is no longer used. But, it is still there because of binary compatibility issue. It should be removed under 5-CURRENT. Reviewed by: itojun Obtained from: KAME MFC after: 3 weeks
Diffstat (limited to 'usr.sbin/traceroute6/traceroute6.c')
-rw-r--r--usr.sbin/traceroute6/traceroute6.c90
1 files changed, 66 insertions, 24 deletions
diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c
index d715cc3..f5f3fbe 100644
--- a/usr.sbin/traceroute6/traceroute6.c
+++ b/usr.sbin/traceroute6/traceroute6.c
@@ -1,4 +1,4 @@
-/* $KAME: traceroute6.c,v 1.32 2000/07/07 12:21:34 itojun Exp $ */
+/* $KAME: traceroute6.c,v 1.42 2001/05/08 04:36:41 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -385,6 +385,7 @@ main(argc, argv)
int ch, i, on, probe, seq, hops, rcvcmsglen;
static u_char *rcvcmsgbuf;
char hbuf[NI_MAXHOST], src0[NI_MAXHOST];
+ char *ep;
/*
* Receive ICMP
@@ -394,6 +395,10 @@ main(argc, argv)
exit(5);
}
+ /* revoke privs */
+ seteuid(getuid());
+ setuid(getuid());
+
/* set a minimum set of socket options */
on = 1;
/* specify to tell receiving interface */
@@ -418,19 +423,21 @@ main(argc, argv)
err(1, "setsockopt(IPV6_HOPLIMIT)");
#endif
- /* revoke privs */
- seteuid(getuid());
- setuid(getuid());
-
seq = 0;
- while ((ch = getopt(argc, argv, "df:g:lm:np:q:rs:w:v")) != EOF)
+ while ((ch = getopt(argc, argv, "df:g:lm:np:q:rs:w:v")) != -1)
switch(ch) {
case 'd':
options |= SO_DEBUG;
break;
case 'f':
- first_hop = atoi(optarg);
+ ep = NULL;
+ first_hop = strtoul(optarg, &ep, 0);
+ if (!*argv || *ep) {
+ Fprintf(stderr,
+ "traceroute6: invalid min hoplimit.\n");
+ exit(1);
+ }
if (first_hop > max_hops) {
Fprintf(stderr,
"traceroute6: min hoplimit must be <= %d.\n", max_hops);
@@ -477,7 +484,13 @@ main(argc, argv)
lflag++;
break;
case 'm':
- max_hops = atoi(optarg);
+ ep = NULL;
+ max_hops = strtoul(optarg, &ep, 0);
+ if (!*argv || *ep) {
+ Fprintf(stderr,
+ "traceroute6: invalid max hoplimit.\n");
+ exit(1);
+ }
if (max_hops < first_hop) {
Fprintf(stderr,
"traceroute6: max hoplimit must be >= %d.\n", first_hop);
@@ -488,7 +501,13 @@ main(argc, argv)
nflag++;
break;
case 'p':
- port = atoi(optarg);
+ ep = NULL;
+ port = strtoul(optarg, &ep, 0);
+ if (!*argv || *ep) {
+ Fprintf(stderr,
+ "traceroute6: port.\n");
+ exit(1);
+ }
if (port < 1) {
Fprintf(stderr,
"traceroute6: port must be >0.\n");
@@ -496,7 +515,13 @@ main(argc, argv)
}
break;
case 'q':
- nprobes = atoi(optarg);
+ ep = NULL;
+ nprobes = strtoul(optarg, &ep, 0);
+ if (!*argv || *ep) {
+ Fprintf(stderr,
+ "traceroute6: invalid nprobes.\n");
+ exit(1);
+ }
if (nprobes < 1) {
Fprintf(stderr,
"traceroute6: nprobes must be >0.\n");
@@ -517,7 +542,13 @@ main(argc, argv)
verbose++;
break;
case 'w':
- waittime = atoi(optarg);
+ ep = NULL;
+ waittime = strtoul(optarg, &ep, 0);
+ if (!*argv || *ep) {
+ Fprintf(stderr,
+ "traceroute6: invalid wait time.\n");
+ exit(1);
+ }
if (waittime <= 1) {
Fprintf(stderr,
"traceroute6: wait must be >1 sec.\n");
@@ -530,7 +561,7 @@ main(argc, argv)
argc -= optind;
argv += optind;
- if (argc < 1)
+ if (argc < 1 || argc > 2)
usage();
#if 1
@@ -557,9 +588,20 @@ main(argc, argv)
}
memcpy(&Dst, res->ai_addr, res->ai_addrlen);
hostname = res->ai_canonname ? strdup(res->ai_canonname) : *argv;
+ if (!hostname) {
+ (void)fprintf(stderr, "traceroute6: not enough core\n");
+ exit(1);
+ }
- if (*++argv)
- datalen = atoi(*argv);
+ if (*++argv) {
+ ep = NULL;
+ datalen = strtoul(*argv, &ep, 0);
+ if (!*argv || *ep) {
+ Fprintf(stderr,
+ "traceroute6: invalid packet length.\n");
+ exit(1);
+ }
+ }
if (datalen < 0 || datalen >= MAXPACKET - sizeof(struct opacket)) {
Fprintf(stderr,
"traceroute6: packet size must be 0 <= s < %ld.\n",
@@ -787,7 +829,7 @@ main(argc, argv)
*/
if (getnameinfo((struct sockaddr *)&Dst, Dst.sin6_len, hbuf,
sizeof(hbuf), NULL, 0, NI_NUMERICHOST | niflag))
- strcpy(hbuf, "(invalid)");
+ strlcpy(hbuf, "(invalid)", sizeof(hbuf));
Fprintf(stderr, "traceroute6");
Fprintf(stderr, " to %s (%s)", hostname, hbuf);
if (source)
@@ -889,7 +931,7 @@ wait_for_reply(sock, mhdr)
struct timeval wait;
int cc = 0, fdsn;
- fdsn = howmany(sock+1, NFDBITS) * sizeof(fd_mask);
+ fdsn = howmany(sock + 1, NFDBITS) * sizeof(fd_mask);
if ((fdsp = (fd_set *)malloc(fdsn)) == NULL)
err(1, "malloc");
memset(fdsp, 0, fdsn);
@@ -1074,7 +1116,7 @@ packet_ok(mhdr, cc, seq)
if (getnameinfo((struct sockaddr *)from, from->sin6_len,
hbuf, sizeof(hbuf), NULL, 0,
NI_NUMERICHOST | niflag) != 0)
- strcpy(hbuf, "invalid");
+ strlcpy(hbuf, "invalid", sizeof(hbuf));
Printf("packet too short (%d bytes) from %s\n", cc,
hbuf);
}
@@ -1088,7 +1130,7 @@ packet_ok(mhdr, cc, seq)
if (getnameinfo((struct sockaddr *)from, from->sin6_len,
hbuf, sizeof(hbuf), NULL, 0,
NI_NUMERICHOST | niflag) != 0)
- strcpy(hbuf, "invalid");
+ strlcpy(hbuf, "invalid", sizeof(hbuf));
Printf("data too short (%d bytes) from %s\n", cc, hbuf);
}
return(0);
@@ -1146,7 +1188,7 @@ packet_ok(mhdr, cc, seq)
if (getnameinfo((struct sockaddr *)from, from->sin6_len,
sbuf, sizeof(sbuf), NULL, 0, NI_NUMERICHOST | niflag) != 0)
- strcpy(sbuf, "invalid");
+ strlcpy(sbuf, "invalid", sizeof(hbuf));
Printf("\n%d bytes from %s to %s", cc, sbuf,
rcvpktinfo ? inet_ntop(AF_INET6, &rcvpktinfo->ipi6_addr,
dbuf, sizeof(dbuf))
@@ -1225,7 +1267,7 @@ print(mhdr, cc)
if (getnameinfo((struct sockaddr *)from, from->sin6_len,
hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST | niflag) != 0)
- strcpy(hbuf, "invalid");
+ strlcpy(hbuf, "invalid", sizeof(hbuf));
if (nflag)
Printf(" %s", hbuf);
else if (lflag)
@@ -1282,7 +1324,7 @@ inetname(sa)
first = 0;
if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
(cp = index(domain, '.')))
- (void) strcpy(domain, cp + 1);
+ (void) strlcpy(domain, cp + 1, sizeof(domain));
else
domain[0] = 0;
}
@@ -1301,7 +1343,7 @@ inetname(sa)
if (getnameinfo(sa, sa->sa_len, line, sizeof(line), NULL, 0,
NI_NUMERICHOST | niflag) != 0)
- strcpy(line, "invalid");
+ strlcpy(line, "invalid", sizeof(line));
return line;
}
@@ -1309,7 +1351,7 @@ void
usage()
{
(void)fprintf(stderr,
-"usage: traceroute6 [-dlnrv] [-f first_hop] [-m max_hops] [-p port#] \n"
-" [-q nqueries] [-s src_addr] [-g gateway] [-w wait] host [data size]\n");
+"usage: traceroute6 [-dlnrv] [-f firsthop] [-g gateway] [-m hoplimit] [-p port]\n"
+" [-q probes] [-s src] [-w waittime] target [datalen]\n");
exit(1);
}
OpenPOWER on IntegriCloud