Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin Add AS support for traceroute6. While here cleanup ...
details: https://anonhg.NetBSD.org/src/rev/f87ab7770633
branches: trunk
changeset: 764866:f87ab7770633
user: christos <christos%NetBSD.org@localhost>
date: Tue May 10 01:52:49 2011 +0000
description:
Add AS support for traceroute6. While here cleanup both traceroute programs
a bit.
XXX: Error printing on traceroute should be revisited.
diffstat:
usr.sbin/traceroute/Makefile | 4 +-
usr.sbin/traceroute/as.c | 86 ++++++--------
usr.sbin/traceroute/as.h | 6 +-
usr.sbin/traceroute/ifaddrlist.c | 10 +-
usr.sbin/traceroute/traceroute.c | 228 +++++++++++++++++++-------------------
usr.sbin/traceroute6/Makefile | 10 +-
6 files changed, 165 insertions(+), 179 deletions(-)
diffs (truncated from 707 to 300 lines):
diff -r 1d5a43827a91 -r f87ab7770633 usr.sbin/traceroute/Makefile
--- a/usr.sbin/traceroute/Makefile Tue May 10 00:34:26 2011 +0000
+++ b/usr.sbin/traceroute/Makefile Tue May 10 01:52:49 2011 +0000
@@ -1,6 +1,4 @@
-# $NetBSD: Makefile,v 1.17 2010/12/15 00:09:41 pooka Exp $
-
-WARNS?= 1 # XXX: out of date third-party program
+# $NetBSD: Makefile,v 1.18 2011/05/10 01:52:49 christos Exp $
USE_FORT?= yes # network client
diff -r 1d5a43827a91 -r f87ab7770633 usr.sbin/traceroute/as.c
--- a/usr.sbin/traceroute/as.c Tue May 10 00:34:26 2011 +0000
+++ b/usr.sbin/traceroute/as.c Tue May 10 01:52:49 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: as.c,v 1.3 2011/01/04 10:26:56 wiz Exp $ */
+/* $NetBSD: as.c,v 1.4 2011/05/10 01:52:49 christos Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -55,55 +55,44 @@
};
void *
-as_setup(server)
- char *server;
+as_setup(const char *server)
{
struct aslookup *asn;
- struct hostent *he = NULL;
- struct servent *se;
- struct sockaddr_in in;
+ struct addrinfo hints, *res0, *res;
FILE *f;
- int s;
+ int s, error;
+ s = -1;
+ if (server == NULL)
+ server = getenv("RA_SERVER");
if (server == NULL)
server = DEFAULT_AS_SERVER;
- (void)memset(&in, 0, sizeof(in));
- in.sin_family = AF_INET;
- in.sin_len = sizeof(in);
- if ((se = getservbyname("whois", "tcp")) == NULL) {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ error = getaddrinfo(server, "whois", &hints, &res0);
+ if (error == EAI_SERVICE) {
warnx("warning: whois/tcp service not found");
- in.sin_port = ntohs(43);
- } else
- in.sin_port = se->s_port;
+ error = getaddrinfo(server, "43", &hints, &res0);
+ }
- if (inet_aton(server, &in.sin_addr) == 0 &&
- ((he = gethostbyname(server)) == NULL ||
- he->h_addr == NULL)) {
- warnx("%s: %s", server, hstrerror(h_errno));
+ if (error != 0) {
+ warnx("%s: %s", server, gai_strerror(error));
return (NULL);
}
- if ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
- warn("socket");
- return (NULL);
+ for (res = res0; res; res = res->ai_next) {
+ s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (s < 0)
+ continue;
+ if (connect(s, res->ai_addr, res->ai_addrlen) >= 0)
+ break;
+ close(s);
+ s = -1;
}
-
- do {
- if (he != NULL) {
- memcpy(&in.sin_addr, he->h_addr, he->h_length);
- he->h_addr_list++;
- }
- if (connect(s, (struct sockaddr *)&in, sizeof(in)) == 0)
- break;
- if (he == NULL || he->h_addr == NULL) {
- close(s);
- s = -1;
- break;
- }
- } while (1);
-
- if (s == -1) {
+ freeaddrinfo(res0);
+ if (s < 0) {
warn("connect");
return (NULL);
}
@@ -131,23 +120,23 @@
return (asn);
}
-int
-as_lookup(_asn, addr)
- void *_asn;
- struct in_addr *addr;
+unsigned int
+as_lookup(void *_asn, char *addr, sa_family_t family)
{
struct aslookup *asn = _asn;
char buf[1024];
- int as, rc, dlen;
+ unsigned int as;
+ int rc, dlen, plen;
- as = rc = dlen = 0;
- (void)fprintf(asn->as_f, "!r%s/32,l\n", inet_ntoa(*addr));
+ as = 0;
+ rc = dlen = 0;
+ plen = (family == AF_INET6) ? 128 : 32;
+ (void)fprintf(asn->as_f, "!r%s/%d,l\n", addr, plen);
(void)fflush(asn->as_f);
#ifdef AS_DEBUG_FILE
if (asn->as_debug) {
- (void)fprintf(asn->as_debug, ">> !r%s/32,l\n",
- inet_ntoa(*addr));
+ (void)fprintf(asn->as_debug, ">> !r%s/%d,l\n", addr, plen);
(void)fflush(asn->as_debug);
}
#endif /* AS_DEBUG_FILE */
@@ -203,7 +192,7 @@
/* origin line is the interesting bit */
if (as == 0 && strncasecmp(buf, "origin:", 7) == 0) {
- sscanf(buf + 7, " AS%d", &as);
+ sscanf(buf + 7, " AS%u", &as);
#ifdef AS_DEBUG_FILE
if (asn->as_debug) {
(void)fprintf(asn->as_debug, "as: %d\n", as);
@@ -217,8 +206,7 @@
}
void
-as_shutdown(_asn)
- void *_asn;
+as_shutdown(void *_asn)
{
struct aslookup *asn = _asn;
diff -r 1d5a43827a91 -r f87ab7770633 usr.sbin/traceroute/as.h
--- a/usr.sbin/traceroute/as.h Tue May 10 00:34:26 2011 +0000
+++ b/usr.sbin/traceroute/as.h Tue May 10 01:52:49 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: as.h,v 1.3 2008/04/28 20:24:17 martin Exp $ */
+/* $NetBSD: as.h,v 1.4 2011/05/10 01:52:49 christos Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -29,6 +29,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-void *as_setup(char *);
-int as_lookup(void *, struct in_addr *);
+void *as_setup(const char *);
+unsigned int as_lookup(void *, char *, sa_family_t);
void as_shutdown(void *);
diff -r 1d5a43827a91 -r f87ab7770633 usr.sbin/traceroute/ifaddrlist.c
--- a/usr.sbin/traceroute/ifaddrlist.c Tue May 10 00:34:26 2011 +0000
+++ b/usr.sbin/traceroute/ifaddrlist.c Tue May 10 01:52:49 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ifaddrlist.c,v 1.7 2003/05/15 14:47:49 itojun Exp $ */
+/* $NetBSD: ifaddrlist.c,v 1.8 2011/05/10 01:52:49 christos Exp $ */
/*
* Copyright (c) 1997
@@ -39,7 +39,7 @@
static const char rcsid[] =
"@(#) Header: ifaddrlist.c,v 1.2 97/04/22 13:31:05 leres Exp (LBL)";
#else
-__RCSID("$NetBSD: ifaddrlist.c,v 1.7 2003/05/15 14:47:49 itojun Exp $");
+__RCSID("$NetBSD: ifaddrlist.c,v 1.8 2011/05/10 01:52:49 christos Exp $");
#endif
#endif
@@ -94,9 +94,9 @@
struct sockaddr_in *sin;
struct ifaddrs *ifap, *ifa;
struct ifaddrlist *al;
- static struct ifaddrlist ifaddrlist[MAX_IPADDR];
+ static struct ifaddrlist xifaddrlist[MAX_IPADDR];
- al = ifaddrlist;
+ al = xifaddrlist;
nipaddr = 0;
if (getifaddrs(&ifap) != 0) {
@@ -126,7 +126,7 @@
++al;
++nipaddr;
}
- *ipaddrp = ifaddrlist;
+ *ipaddrp = xifaddrlist;
freeifaddrs(ifap);
return (nipaddr);
}
diff -r 1d5a43827a91 -r f87ab7770633 usr.sbin/traceroute/traceroute.c
--- a/usr.sbin/traceroute/traceroute.c Tue May 10 00:34:26 2011 +0000
+++ b/usr.sbin/traceroute/traceroute.c Tue May 10 01:52:49 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: traceroute.c,v 1.76 2010/12/15 00:09:41 pooka Exp $ */
+/* $NetBSD: traceroute.c,v 1.77 2011/05/10 01:52:49 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997
@@ -29,7 +29,7 @@
#else
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997\
The Regents of the University of California. All rights reserved.");
-__RCSID("$NetBSD: traceroute.c,v 1.76 2010/12/15 00:09:41 pooka Exp $");
+__RCSID("$NetBSD: traceroute.c,v 1.77 2011/05/10 01:52:49 christos Exp $");
#endif
#endif
@@ -323,57 +323,57 @@
#endif
};
-u_char packet[512]; /* last inbound (icmp) packet */
+static u_char packet[512]; /* last inbound (icmp) packet */
-struct ip *outip; /* last output (udp) packet */
-struct udphdr *outudp; /* last output (udp) packet */
-void *outmark; /* packed location of struct outdata */
-struct outdata outsetup; /* setup and copy for alignment */
+static struct ip *outip; /* last output (udp) packet */
+static struct udphdr *outudp; /* last output (udp) packet */
+static void *outmark; /* packed location of struct outdata */
+static struct outdata outsetup; /* setup and copy for alignment */
-struct icmp *outicmp; /* last output (icmp) packet */
+static struct icmp *outicmp; /* last output (icmp) packet */
/* loose source route gateway list (including room for final destination) */
-u_int32_t gwlist[NGATEWAYS + 1];
+static u_int32_t gwlist[NGATEWAYS + 1];
-int s; /* receive (icmp) socket file descriptor */
-int sndsock; /* send (udp/icmp) socket file descriptor */
+static int s; /* receive (icmp) socket file descriptor */
+static int sndsock; /* send (udp/icmp) socket file descriptor */
-struct sockaddr whereto; /* Who to try to reach */
-struct sockaddr_in wherefrom; /* Who we are */
-int packlen; /* total length of packet */
-int minpacket; /* min ip packet size */
-int maxpacket = 32 * 1024; /* max ip packet size */
-int printed_ttl = 0;
+static struct sockaddr whereto; /* Who to try to reach */
+static struct sockaddr_in wherefrom; /* Who we are */
+static int packlen; /* total length of packet */
+static int minpacket; /* min ip packet size */
+static int maxpacket = 32 * 1024; /* max ip packet size */
+static int printed_ttl = 0;
-const char *prog;
-char *source;
-char *hostname;
-char *device;
+static const char *prog;
+static char *source;
+static char *hostname;
+static char *device;
-int nprobes = 3;
-int max_ttl = 30;
-int first_ttl = 1;
-u_int16_t ident;
-in_port_t port = 32768 + 666; /* start udp dest port # for probe packets */
+static int nprobes = 3;
+static int max_ttl = 30;
+static int first_ttl = 1;
+static u_int16_t ident;
+static in_port_t port = 32768 + 666; /* start udp dest port # for probe packets */
-int options; /* socket options */
-int verbose;
-int waittime = 5; /* time to wait for response (in seconds) */
-int nflag; /* print addresses numerically */
-int dump;
-int Mflag; /* show MPLS labels if any */
-int as_path; /* print as numbers for each hop */
-char *as_server = NULL;
-void *asn;
-int useicmp = 0; /* use icmp echo instead of udp packets */
+static int options; /* socket options */
Home |
Main Index |
Thread Index |
Old Index