Import LBL's traceroute-1.4a5

This commit is contained in:
christos 1997-10-03 22:25:12 +00:00
parent 0382099526
commit 313a9cff6b
8 changed files with 463 additions and 115 deletions

View File

@ -0,0 +1,87 @@
$NetBSD: CHANGES,v 1.1.1.1 1997/10/03 22:25:19 christos Exp $
@(#) Header: CHANGES,v 1.17 97/06/13 02:27:02 leres Exp (LBL)
v1.4 Fri Jun 13 02:23:51 PDT 1997
- Add an option to use icmp echo instead of udp datagrams.
- Add HPUX and Linux support.
- Handle hex argument values as suggested by John Hawkinson
(jhawk@mit.edu)
- Added flags to set the first ttl and to set the don't fragment bit.
- Removed dependence on strdup().
- Add a local autoconf macro to check for routines in libraries; the
autoconf version is broken (it only puts the library name in the
cache variable name). Thanks to John Hawkinson.
- Add a local autoconf macro to check for types; the autoconf version
is broken (it uses grep instead of actually compiling a code fragment).
v1.3.2 Thu Sep 26 18:06:16 PDT 1996
- Rewrite source routing code to eliminate a number of problems on
systems using raw ip options. Also pad options with a noop so gateway
addresses are aligned.
- Don't call inet_ntoa() twice in the same printf(). Thanks to NetBSD
via Bill Fenner (fenner@parc.xerox.com)
- Decode "administratively prohibited filter" icmp code and print
numeric value for unknown codes. Thanks to Bill Fenner.
v1.3.1 Wed Sep 18 21:08:16 PDT 1996
- Some systems (e.g. AIX) need sys/select.h. Thanks to Brett Hogden
(hogden@rge.com)
- Byte swap ip header length under Solaris. (This has no effect on the
sparc but is required on the i386.)
- Made optional packet length control total size of packet.
v1.3 Mon Sep 16 14:55:44 PDT 1996
- Overrun buffer security fixes. Thanks to Bill Fenner
(fenner@parc.xerox.com)
- Wait for response packet relative to start of probe. Thanks to Bill
Fenner.
- Fix bug that prevented changing the packet size. Thanks to Gregory
Decker (gdecker@nate.dcrt.nih.gov)
- Add support for RAW_OPTIONS (e.g. 4.4 BSD systems such as BSD/OS and
FreeBSD) thanks to Jeffrey C Honig (jch@bsdi.com)
- Remove ip header byte swap fix from v1.2; most kernels swap the ip
header length in the kernel (and it causes OSF3 to crash).
- Fix to not exit when the number of probes is set to 1 (i.e. "-q 1")
- Improve autoconf configuration.
v1.2 Tue Oct 17 23:50:05 PDT 1995
- Convert to autoconf and ansify.
- Byte swap ip header length for little endian machines. Fix thanks to
Y Badri (yb@greybox.demon.co.uk).
v1.1 Thu Jun 15 02:32:55 PDT 1995
- Check for too many arguments.
- Recode to make timing of packet's round trip more obvious and to
tighten up code.
- Ifdef IP_OPTIONS code.
- Display time in microseconds.
v1.0 Tue Feb 28 23:50:05 PDT 1989
- Initial public release.

View File

@ -1,126 +1,30 @@
Tue Dec 27 06:24:24 PST 1988
$NetBSD: README,v 1.1.1.4 1997/10/03 22:25:20 christos Exp $
@(#) Header: README,v 1.8 97/01/05 04:15:36 leres Exp (LBL)
TRACEROUTE 1.4
Lawrence Berkeley National Laboratory
Network Research Group
traceroute@ee.lbl.gov
ftp://ftp.ee.lbl.gov/traceroute.tar.Z
Traceroute is a system administrators utility to trace the route
ip packets from the current system take in getting to some
destination system. See the comments at the front of the
program for a description of its use.
This program
a) can only be run by root (it uses raw ip sockets).
b) REQUIRES A KERNEL MOD to the raw ip output code to run.
If you want to hack on your kernel, my modified version of the
routine rip_output (in file /sys/netinet/raw_ip.c) is attached.
This code may or may not resemble the code in your kernel.
It may offer you a place to start but I make no promises.
If you do hack your kernel, remember to test everything that uses
raw ip sockets (e.g., ping and egpup/gated) & make sure they still
work. I wish you the best of luck and you're on your own.
If your system has the ttl bug mentioned in the source, you
might want to fix it while you're in the kernel. (This bug
appears in all releases of BSD up to but not including 4.3tahoe.
If your version of netinet/ip_icmp.c is any earlier than 7.3
(April, '87), it has the bug.) The fix is just to add the line
ip->ip_ttl = MAXTTL;
after the line
ip->ip_src = t;
(or anywhere before the call to icmp_send) in routine icmp_reflect.
If you're running this on a pre-4.3bsd system (e.g., Sun 3.x,
Ultrix) that strips ip headers from icmp messages, add -DARCHAIC
to CFLAGS in the Makefile. Also note that rip_output contains
a conditional for a 4.2/4.3 change in the location of a raw
socket's protocol number. I've checked this under 4.3 & Sun OS
3.5 but you should double-check your system to make sure the
appropriate branch of the #if is taken (check the line that
assigned to ip->ip_p in your system's original rip_output).
This program uses raw ip sockets and must be run as root (or installed
setuid to root).
A couple of awk programs to massage the traceroute output are
included. "mean.awk" and "median.awk" compute the mean and median
time to each hop, respectively. I've found that something like
included. "mean.awk" and "median.awk" compute the mean and median time
to each hop, respectively. I've found that something like
traceroute -q 7 foo.somewhere >t
awk -f median.awk t | graph
traceroute -q 7 foo.somewhere >t
awk -f median.awk t | xgraph
can give you a quick picture of the bad spots on a long
path (median is usually a better noise filter than mean).
can give you a quick picture of the bad spots on a long path (median is
usually a better noise filter than mean).
Enjoy.
- Van Jacobson (van@helios.ee.lbl.gov)
-------------------- rip_output from /sys/netinet/raw_ip.c
rip_output(m, so)
register struct mbuf *m;
struct socket *so;
{
register struct ip *ip;
int error;
struct rawcb *rp = sotorawcb(so);
struct sockaddr_in *sin;
#if BSD>=43
short proto = rp->rcb_proto.sp_protocol;
#else
short proto = so->so_proto->pr_protocol;
#endif
/*
* if the protocol is IPPROTO_RAW, the user handed us a
* complete IP packet. Otherwise, allocate an mbuf for a
* header and fill it in as needed.
*/
if (proto != IPPROTO_RAW) {
/*
* Calculate data length and get an mbuf
* for IP header.
*/
int len = 0;
struct mbuf *m0;
for (m0 = m; m; m = m->m_next)
len += m->m_len;
m = m_get(M_DONTWAIT, MT_HEADER);
if (m == 0) {
m = m0;
error = ENOBUFS;
goto bad;
}
m->m_off = MMAXOFF - sizeof(struct ip);
m->m_len = sizeof(struct ip);
m->m_next = m0;
ip = mtod(m, struct ip *);
ip->ip_tos = 0;
ip->ip_off = 0;
ip->ip_p = proto;
ip->ip_len = sizeof(struct ip) + len;
ip->ip_ttl = MAXTTL;
} else
ip = mtod(m, struct ip *);
if (rp->rcb_flags & RAW_LADDR) {
sin = (struct sockaddr_in *)&rp->rcb_laddr;
if (sin->sin_family != AF_INET) {
error = EAFNOSUPPORT;
goto bad;
}
ip->ip_src.s_addr = sin->sin_addr.s_addr;
} else
ip->ip_src.s_addr = 0;
ip->ip_dst = ((struct sockaddr_in *)&rp->rcb_faddr)->sin_addr;
#if BSD>=43
return (ip_output(m, rp->rcb_options, &rp->rcb_route,
(so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST));
#else
return (ip_output(m, (struct mbuf *)0, &rp->rcb_route,
(so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST));
#endif
bad:
m_freem(m);
return (error);
}
Problems, bugs, questions, desirable enhancements, source code
contributions, etc., should be sent to the email address
"traceroute@ee.lbl.gov".

View File

@ -0,0 +1,45 @@
/* $NetBSD: gnuc.h,v 1.1.1.1 1997/10/03 22:25:19 christos Exp $ */
/* @(#) Header: gnuc.h,v 1.3 95/10/09 02:47:01 leres Exp (LBL) */
/* Define __P() macro, if necessary */
#ifndef __P
#if __STDC__
#define __P(protos) protos
#else
#define __P(protos) ()
#endif
#endif
/* inline foo */
#ifdef __GNUC__
#define inline __inline
#else
#define inline
#endif
/*
* Handle new and old "dead" routine prototypes
*
* For example:
*
* __dead void foo(void) __attribute__((volatile));
*
*/
#ifdef __GNUC__
#ifndef __dead
#define __dead volatile
#endif
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
#ifndef __attribute__
#define __attribute__(args)
#endif
#endif
#else
#ifndef __dead
#define __dead
#endif
#ifndef __attribute__
#define __attribute__(args)
#endif
#endif

View File

@ -0,0 +1,179 @@
/* $NetBSD: ifaddrlist.c,v 1.1.1.1 1997/10/03 22:25:12 christos Exp $ */
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
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.1.1.1 1997/10/03 22:25:12 christos Exp $");
#endif
#endif
#include <sys/param.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#include <sys/time.h> /* concession to AIX */
#if __STDC__
struct mbuf;
struct rtentry;
#endif
#include <net/if.h>
#include <netinet/in.h>
#include <ctype.h>
#include <errno.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "gnuc.h"
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
#include "ifaddrlist.h"
#include "savestr.h"
/* Not all systems have IFF_LOOPBACK */
#ifdef IFF_LOOPBACK
#define ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
#else
#define ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
#endif
#define MAX_IPADDR 32
/*
* Return the interface list
*/
int
ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
{
register int fd, nipaddr;
#ifdef HAVE_SOCKADDR_SA_LEN
register int n;
#endif
register struct ifreq *ifrp, *ifend, *ifnext, *mp;
register struct sockaddr_in *sin;
register struct ifaddrlist *al;
struct ifconf ifc;
struct ifreq ibuf[MAX_IPADDR], ifr;
char device[sizeof(ifr.ifr_name) + 1];
static struct ifaddrlist ifaddrlist[MAX_IPADDR];
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
(void)sprintf(errbuf, "socket: %s", strerror(errno));
return (-1);
}
ifc.ifc_len = sizeof(ibuf);
ifc.ifc_buf = (caddr_t)ibuf;
if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 ||
ifc.ifc_len < sizeof(struct ifreq)) {
(void)sprintf(errbuf, "SIOCGIFCONF: %s", strerror(errno));
(void)close(fd);
return (-1);
}
ifrp = ibuf;
ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len);
al = ifaddrlist;
mp = NULL;
nipaddr = 0;
for (; ifrp < ifend; ifrp = ifnext) {
#ifdef HAVE_SOCKADDR_SA_LEN
n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
if (n < sizeof(*ifrp))
ifnext = ifrp + 1;
else
ifnext = (struct ifreq *)((char *)ifrp + n);
if (ifrp->ifr_addr.sa_family != AF_INET)
continue;
#else
ifnext = ifrp + 1;
#endif
/*
* Need a template to preserve address info that is
* used below to locate the next entry. (Otherwise,
* SIOCGIFFLAGS stomps over it because the requests
* are returned in a union.)
*/
strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
if (errno == ENXIO)
continue;
(void)sprintf(errbuf, "SIOCGIFFLAGS: %.*s: %s",
(int)sizeof(ifr.ifr_name), ifr.ifr_name,
strerror(errno));
(void)close(fd);
return (-1);
}
/* Must be up and not the loopback */
if ((ifr.ifr_flags & IFF_UP) == 0 || ISLOOPBACK(&ifr))
continue;
(void)strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name));
device[sizeof(device) - 1] = '\0';
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
(void)sprintf(errbuf, "SIOCGIFADDR: %s: %s",
device, strerror(errno));
(void)close(fd);
return (-1);
}
sin = (struct sockaddr_in *)&ifr.ifr_addr;
al->addr = sin->sin_addr.s_addr;
al->device = savestr(device);
++al;
++nipaddr;
}
(void)close(fd);
*ipaddrp = ifaddrlist;
return (nipaddr);
}

View File

@ -0,0 +1,31 @@
/* $NetBSD: ifaddrlist.h,v 1.1.1.1 1997/10/03 22:25:19 christos Exp $ */
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) Header: traceroute.h,v 1.1 97/01/04 19:33:33 leres Locked (LBL)
*/
struct ifaddrlist {
u_int32_t addr;
char *device;
};
int ifaddrlist(struct ifaddrlist **, char *);

View File

@ -0,0 +1,74 @@
/* $NetBSD: savestr.c,v 1.1.1.1 1997/10/03 22:25:13 christos Exp $ */
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char rcsid[] =
"@(#) Header: savestr.c,v 1.2 97/05/09 14:52:31 leres Exp (LBL)";
#else
__RCSID("$NetBSD: savestr.c,v 1.1.1.1 1997/10/03 22:25:13 christos Exp $");
#endif
#endif
#include <sys/types.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "gnuc.h"
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
#include "savestr.h"
/* A replacement for strdup() that cuts down on malloc() overhead */
char *
savestr(register const char *str)
{
register u_int size;
register char *p;
static char *strptr = NULL;
static u_int strsize = 0;
size = strlen(str) + 1;
if (size > strsize) {
strsize = 1024;
if (strsize < size)
strsize = size;
strptr = (char *)malloc(strsize);
if (strptr == NULL) {
fprintf(stderr, "savestr: malloc\n");
exit(1);
}
}
(void)strcpy(strptr, str);
p = strptr;
strptr += size;
strsize -= size;
return (p);
}

View File

@ -0,0 +1,26 @@
/* $NetBSD: savestr.h,v 1.1.1.1 1997/10/03 22:25:19 christos Exp $ */
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) Header: savestr.h,v 1.1 97/04/22 13:30:21 leres Exp (LBL)
*/
extern char *savestr(const char *);

View File

@ -0,0 +1,2 @@
/* $NetBSD: version.c,v 1.1.1.1 1997/10/03 22:25:33 christos Exp $ */
char version[] = "1.4a5";