Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/traceroute6 print source address of query. support...
details: https://anonhg.NetBSD.org/src/rev/6160c0af23fa
branches: trunk
changeset: 487760:6160c0af23fa
user: itojun <itojun%NetBSD.org@localhost>
date: Mon Jun 12 16:31:52 2000 +0000
description:
print source address of query. support -f (skip first N hops).
do not choke on unexpected ND messages.
diffstat:
usr.sbin/traceroute6/traceroute6.8 | 48 +++++-
usr.sbin/traceroute6/traceroute6.c | 241 ++++++++++++++++++++++++------------
2 files changed, 197 insertions(+), 92 deletions(-)
diffs (truncated from 545 to 300 lines):
diff -r e70214172005 -r 6160c0af23fa usr.sbin/traceroute6/traceroute6.8
--- a/usr.sbin/traceroute6/traceroute6.8 Mon Jun 12 16:26:13 2000 +0000
+++ b/usr.sbin/traceroute6/traceroute6.8 Mon Jun 12 16:31:52 2000 +0000
@@ -1,6 +1,9 @@
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+.\" $NetBSD: traceroute6.8,v 1.5 2000/06/12 16:31:52 itojun Exp $
+.\" $KAME: traceroute6.8,v 1.8 2000/06/12 16:29:18 itojun Exp $
+.\"
.\" All rights reserved.
-.\"
+.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
@@ -12,7 +15,7 @@
.\" 3. Neither the name of the project nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
-.\"
+.\"
.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -25,9 +28,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $NetBSD: traceroute6.8,v 1.4 2000/02/16 06:10:15 itojun Exp $
-.\" KAME Id: traceroute6.8,v 1.4 2000/02/16 06:08:39 itojun Exp
-.\"
.Dd May 17, 1998
.Dt TRACEROUTE6 8
.Os
@@ -37,20 +37,48 @@
.Nd "print the route IPv6 packets will take to the destination"
.\"
.Sh SYNOPSIS
-.Nm
+.Nm traceroute6
+.Bk -words
.Op Fl dlnrv
+.Ek
+.Bk -words
+.Op Fl f Ar firsthop
+.Ek
+.Bk -words
+.Op Fl g Ar gateway
+.Ek
+.Bk -words
.Op Fl m Ar hoplimit
+.Ek
+.Bk -words
.Op Fl p Ar port
+.Ek
+.Bk -words
.Op Fl q Ar probes
+.Ek
+.Bk -words
.Op Fl s Ar src
+.Ek
+.Bk -words
.Op Fl w Ar waittime
+.Ek
+.Bk -words
.Ar target
.Op Ar datalen
+.Ek
.\"
.Sh DESCRIPTION
.Bl -tag -width Ds
.It Fl d
Debug mode.
+.It Fl f Ar firsthop
+Specify how many hops to skip in trace.
+.It Fl g Ar gateway
+Specify intermediate gateway
+.Po
+.Nm
+uses routing header
+.Pc .
.It Fl m Ar hoplimit
Specify maximum hoplimit.
.It Fl l
@@ -81,8 +109,9 @@
.El
.\"
.Sh RETURN VALUES
-.Nm Traceroute6
-will exit with 0 on success, and non-zero on errors.
+The
+.Nm
+command will exit with 0 on success, and non-zero on errors.
.\"
.Sh SEE ALSO
.Xr ping 8 ,
@@ -93,6 +122,3 @@
The
.Nm
command first appeared in WIDE hydrangea IPv6 protocol stack kit.
-.\"
-.\" .Sh BUGS
-.\" (to be written)
diff -r e70214172005 -r 6160c0af23fa usr.sbin/traceroute6/traceroute6.c
--- a/usr.sbin/traceroute6/traceroute6.c Mon Jun 12 16:26:13 2000 +0000
+++ b/usr.sbin/traceroute6/traceroute6.c Mon Jun 12 16:31:52 2000 +0000
@@ -1,9 +1,10 @@
-/* $NetBSD: traceroute6.c,v 1.10 2000/03/12 02:42:43 itojun Exp $ */
+/* $NetBSD: traceroute6.c,v 1.11 2000/06/12 16:31:53 itojun Exp $ */
+/* $KAME: traceroute6.c,v 1.29 2000/06/12 16:29:18 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -15,7 +16,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -78,7 +79,7 @@
#else
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: traceroute6.c,v 1.10 2000/03/12 02:42:43 itojun Exp $");
+__RCSID("$NetBSD: traceroute6.c,v 1.11 2000/06/12 16:31:53 itojun Exp $");
#endif
#endif
@@ -260,7 +261,7 @@
#include <sys/file.h>
#include <sys/ioctl.h>
-#include <netinet/in.h>
+#include <netinet/in.h>
#include <arpa/inet.h>
@@ -277,11 +278,10 @@
#include <netinet/udp.h>
#ifdef IPSEC
-#include <net/route.h>
+#include <net/route.h>
#include <netinet6/ipsec.h>
#endif
-#define freehostent(hp)
#define DUMMY_PORT 10010
#define MAXPACKET 65535 /* max ip packet size */
@@ -302,6 +302,11 @@
#define Sprintf (void)sprintf
#define Printf (void)printf
+#ifndef HAVE_GETIPNODEBYNAME
+#define getipnodebyname(x, y, z, u) gethostbyname2((x), (y))
+#define freehostent(x)
+#endif
+
/*
* format of a (udp) probe packet.
*/
@@ -342,19 +347,19 @@
struct in6_pktinfo *rcvpktinfo;
struct sockaddr_in6 Src, Dst, Rcv;
-struct sockaddr_in6 *src = &Src, *rcv = &Rcv;
int datalen; /* How much data */
/* XXX: 2064 = 127(max hops in type 0 rthdr) * sizeof(ip6_hdr) + 16(margin) */
char rtbuf[2064];
#ifdef USE_RFC2292BIS
struct ip6_rthdr *rth;
-#endif
+#endif
struct cmsghdr *cmsg;
char *source = 0;
char *hostname;
int nprobes = 3;
+int first_hop = 1;
int max_hops = 30;
u_short ident;
u_short port = 32768+666; /* start udp dest port # for probe packets */
@@ -378,29 +383,63 @@
struct hostent *hp;
int error;
struct addrinfo hints, *res;
- extern char *optarg;
- extern int optind;
int ch, i, on, probe, seq, hops, rcvcmsglen;
static u_char *rcvcmsgbuf;
- char hbuf[NI_MAXHOST];
+ char hbuf[NI_MAXHOST], src0[NI_MAXHOST];
+
+ /*
+ * Receive ICMP
+ */
+ if ((rcvsock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
+ perror("socket(ICMPv6)");
+ exit(5);
+ }
+ /* set a minimum set of socket options */
on = 1;
+ /* specify to tell receiving interface */
+#ifdef IPV6_RECVPKTINFO
+ if (setsockopt(rcvsock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
+ sizeof(on)) < 0)
+ err(1, "setsockopt(IPV6_RECVPKTINFO)");
+#else /* old adv. API */
+ if (setsockopt(rcvsock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
+ sizeof(on)) < 0)
+ err(1, "setsockopt(IPV6_PKTINFO)");
+#endif
+
+ /* specify to tell value of hoplimit field of received IP6 hdr */
+#ifdef IPV6_RECVHOPLIMIT
+ if (setsockopt(rcvsock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
+ sizeof(on)) < 0)
+ err(1, "setsockopt(IPV6_RECVHOPLIMIT)");
+#else /* old adv. API */
+ if (setsockopt(rcvsock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
+ sizeof(on)) < 0)
+ err(1, "setsockopt(IPV6_HOPLIMIT)");
+#endif
+
+ /* revoke privs */
+ seteuid(getuid());
+ setuid(getuid());
+
seq = 0;
- while ((ch = getopt(argc, argv, "dlm:np:q:rs:w:vg:")) != EOF)
+ while ((ch = getopt(argc, argv, "df:g:lm:np:q:rs:w:v")) != EOF)
switch(ch) {
case 'd':
options |= SO_DEBUG;
break;
- case 'l':
- lflag++;
+ case 'f':
+ first_hop = atoi(optarg);
+ if (first_hop > max_hops) {
+ Fprintf(stderr,
+ "traceroute6: min hoplimit must be <= %d.\n", max_hops);
+ exit(1);
+ }
break;
case 'g':
-#if 0
hp = getipnodebyname(optarg, AF_INET6, 0, &h_errno);
-#else
- hp = gethostbyname2(optarg, AF_INET6);
-#endif
if (hp == NULL) {
Fprintf(stderr,
"traceroute6: unknown host %s\n", optarg);
@@ -435,11 +474,14 @@
#endif
freehostent(hp);
break;
+ case 'l':
+ lflag++;
+ break;
case 'm':
max_hops = atoi(optarg);
- if (max_hops <= 1) {
+ if (max_hops < first_hop) {
Fprintf(stderr,
- "traceroute6: max hoplimit must be >1.\n");
+ "traceroute6: max hoplimit must be >= %d.\n", first_hop);
exit(1);
}
break;
@@ -533,18 +575,11 @@
}
(void) bzero((char *)outpacket, datalen);
- /*
- * Receive ICMP
- */
- if ((rcvsock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
- perror("socket(ICMPv6)");
- exit(5);
- }
/* initialize msghdr for receiving packets */
rcviov[0].iov_base = (caddr_t)packet;
rcviov[0].iov_len = sizeof(packet);
- rcvmhdr.msg_name = (caddr_t)rcv;
- rcvmhdr.msg_namelen = sizeof(*rcv);
+ rcvmhdr.msg_name = (caddr_t)&Rcv;
Home |
Main Index |
Thread Index |
Old Index