summaryrefslogtreecommitdiffstats
path: root/contrib/traceroute/traceroute.c
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2008-02-20 23:29:53 +0000
committerrpaulo <rpaulo@FreeBSD.org>2008-02-20 23:29:53 +0000
commit63199bf7b7c89cd5951e13c17b014c06b2ef7739 (patch)
tree320768ace56ea7c61548fe94e747002ed891ac06 /contrib/traceroute/traceroute.c
parent23dbe457bf5f99f80a46e3a2035970149d6cb024 (diff)
downloadFreeBSD-src-63199bf7b7c89cd5951e13c17b014c06b2ef7739.zip
FreeBSD-src-63199bf7b7c89cd5951e13c17b014c06b2ef7739.tar.gz
Add AS lookup functionality. On each hop we query a whois server to
find the corresponding AS for that IP (-a switch). We can also choose a different whois server with the -A switch. The default is whois.radb.net. Obtained from: NetBSD Reviewed by: bms, njl (mentor) Approved by: njl (mentor)
Diffstat (limited to 'contrib/traceroute/traceroute.c')
-rw-r--r--contrib/traceroute/traceroute.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/contrib/traceroute/traceroute.c b/contrib/traceroute/traceroute.c
index 5a9e8d2..a4bce61 100644
--- a/contrib/traceroute/traceroute.c
+++ b/contrib/traceroute/traceroute.c
@@ -263,6 +263,7 @@ static const char rcsid[] =
#include "findsaddr.h"
#include "ifaddrlist.h"
+#include "as.h"
#include "traceroute.h"
/* Maximum number of gateways (include room for one noop) */
@@ -350,6 +351,9 @@ int options; /* socket options */
int verbose;
int waittime = 5; /* time to wait for response (in seconds) */
int nflag; /* print addresses numerically */
+int as_path; /* print as numbers for each hop */
+char *as_server = NULL;
+void *asn;
#ifdef CANT_HACK_IPCKSUM
int doipcksum = 0; /* don't calculate ip checksums by default */
#else
@@ -535,9 +539,17 @@ main(int argc, char **argv)
prog = argv[0];
opterr = 0;
- while ((op = getopt(argc, argv, "edDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF)
+ while ((op = getopt(argc, argv, "aA:edDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF)
switch (op) {
-
+ case 'a':
+ as_path = 1;
+ break;
+
+ case 'A':
+ as_path = 1;
+ as_server = optarg;
+ break;
+
case 'd':
options |= SO_DEBUG;
break;
@@ -913,6 +925,16 @@ main(int argc, char **argv)
exit (1);
}
+ if (as_path) {
+ asn = as_setup(as_server);
+ if (asn == NULL) {
+ Fprintf(stderr, "%s: as_setup failed, AS# lookups"
+ " disabled\n", prog);
+ (void)fflush(stderr);
+ as_path = 0;
+ }
+ }
+
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
if (setpolicy(sndsock, "in bypass") < 0)
errx(1, "%s", ipsec_strerror());
@@ -1118,6 +1140,8 @@ main(int argc, char **argv)
(unreachable > 0 && unreachable >= nprobes - 1))
break;
}
+ if (as_path)
+ as_shutdown(asn);
exit(0);
}
@@ -1458,6 +1482,9 @@ print(register u_char *buf, register int cc, register struct sockaddr_in *from)
hlen = ip->ip_hl << 2;
cc -= hlen;
+ if (as_path)
+ Printf(" [AS%d]", as_lookup(asn, &from->sin_addr));
+
if (nflag)
Printf(" %s", inet_ntoa(from->sin_addr));
else
@@ -1764,8 +1791,8 @@ usage(void)
Fprintf(stderr, "Version %s\n", version);
Fprintf(stderr,
- "Usage: %s [-dDeFInrSvx] [-f first_ttl] [-g gateway] [-i iface]\n"
+ "Usage: %s [-adDeFInrSvx] [-f first_ttl] [-g gateway] [-i iface]\n"
"\t[-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr]\n"
- "\t[-t tos] [-w waittime] [-z pausemsecs] host [packetlen]\n", prog);
+ "\t[-t tos] [-w waittime] [-A as_server] [-z pausemsecs] host [packetlen]\n", prog);
exit(1);
}
OpenPOWER on IntegriCloud