Update from 4.4-Lite.

This commit is contained in:
mycroft 1994-05-16 19:15:57 +00:00
parent 2d6f34fc15
commit 3d70e198e5
5 changed files with 71 additions and 44 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.1 (Berkeley) 5/11/90
# $Id: Makefile,v 1.2 1993/07/30 20:50:33 mycroft Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
# $Id: Makefile,v 1.3 1994/05/16 19:15:57 mycroft Exp $
PROG= traceroute
MAN8= traceroute.0

View File

@ -1,7 +1,7 @@
#!/bin/awk -f
#
# Copyright (c) 1990 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 1990, 1993
# The Regents of the University of California. All rights reserved.
#
# This code is derived from software contributed to Berkeley by
# Van Jacobson.
@ -34,7 +34,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#)mean.awk 5.2 (Berkeley) 4/28/90
# from: @(#)mean.awk 8.1 (Berkeley) 6/6/93
# $Id: mean.awk,v 1.2 1994/05/16 19:15:58 mycroft Exp $
#
/^ *[0-9]/ {
# print out the average time to each hop along a route.

View File

@ -1,7 +1,7 @@
#!/bin/awk -f
#
# Copyright (c) 1990 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 1990, 1993
# The Regents of the University of California. All rights reserved.
#
# This code is derived from software contributed to Berkeley by
# Van Jacobson.
@ -34,7 +34,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#)median.awk 5.2 (Berkeley) 4/28/90
# from: @(#)median.awk 8.1 (Berkeley) 6/6/93
# $Id: median.awk,v 1.2 1994/05/16 19:15:59 mycroft Exp $
#
/^ *[0-9]/ {
# print out the median time to each hop along a route.

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Van Jacobson.
@ -32,10 +32,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)traceroute.8 5.4 (Berkeley) 3/16/91
.\" $Id: traceroute.8,v 1.2 1993/08/01 07:23:17 mycroft Exp $
.\" @(#)traceroute.8 8.1 (Berkeley) 6/6/93
.\" $Id: traceroute.8,v 1.3 1994/05/16 19:16:00 mycroft Exp $
.\"
.Dd March 16, 1991
.Dd June 6, 1993
.Dt TRACEROUTE 8
.Os BSD 4.3
.Sh NAME

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Van Jacobson.
@ -35,14 +35,14 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)traceroute.c 5.4 (Berkeley) 5/15/90";*/
static char rcsid[] = "$Id: traceroute.c,v 1.2 1993/08/01 17:55:03 mycroft Exp $";
/*static char sccsid[] = "from: @(#)traceroute.c 8.1 (Berkeley) 6/6/93";*/
static char *rcsid = "$Id: traceroute.c,v 1.3 1994/05/16 19:16:01 mycroft Exp $";
#endif /* not lint */
/*
@ -227,11 +227,15 @@ static char rcsid[] = "$Id: traceroute.c,v 1.2 1993/08/01 17:55:03 mycroft Exp $
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAXPACKET 65535 /* max ip packet size */
#ifndef MAXHOSTNAMELEN
@ -250,10 +254,6 @@ static char rcsid[] = "$Id: traceroute.c,v 1.2 1993/08/01 17:55:03 mycroft Exp $
#define Fprintf (void)fprintf
#define Sprintf (void)sprintf
#define Printf (void)printf
extern int errno;
extern char *malloc();
extern char *inet_ntoa();
extern u_long inet_addr();
/*
* format of a (udp) probe packet.
@ -268,7 +268,15 @@ struct opacket {
u_char packet[512]; /* last inbound (icmp) packet */
struct opacket *outpacket; /* last output (udp) packet */
char *inetname();
int wait_for_reply __P((int, struct sockaddr_in *));
void send_probe __P((int, int));
double deltaT __P((struct timeval *, struct timeval *));
int packet_ok __P((u_char *, int, struct sockaddr_in *, int));
void print __P((u_char *, int, struct sockaddr_in *));
void tvsub __P((struct timeval *, struct timeval *));
char *inetname __P((struct in_addr));
void usage __P(());
int s; /* receive (icmp) socket file descriptor */
int sndsock; /* send (udp) socket file descriptor */
@ -289,7 +297,9 @@ int verbose;
int waittime = 5; /* time to wait for response (in seconds) */
int nflag; /* print addresses numerically */
int
main(argc, argv)
int argc;
char *argv[];
{
extern char *optarg;
@ -369,7 +379,7 @@ main(argc, argv)
argc -= optind;
argv += optind;
if (argc < 1)
if (argc < 1)
usage();
setlinebuf (stdout);
@ -377,7 +387,7 @@ main(argc, argv)
(void) bzero((char *)&whereto, sizeof(struct sockaddr));
to->sin_family = AF_INET;
to->sin_addr.s_addr = inet_addr(*argv);
if (to->sin_addr.s_addr != -1)
if (to->sin_addr.s_addr != -1)
hostname = *argv;
else {
hp = gethostbyname(*argv);
@ -391,7 +401,7 @@ main(argc, argv)
exit(1);
}
}
if (*++argv)
if (*++argv)
datalen = atoi(*argv);
if (datalen < 0 || datalen >= MAXPACKET - sizeof(struct opacket)) {
Fprintf(stderr,
@ -408,6 +418,8 @@ main(argc, argv)
(void) bzero((char *)outpacket, datalen);
outpacket->ip.ip_dst = to->sin_addr;
outpacket->ip.ip_tos = tos;
outpacket->ip.ip_v = IPVERSION;
outpacket->ip.ip_id = 0;
ident = (getpid() & 0xffff) | 0x8000;
@ -483,19 +495,20 @@ main(argc, argv)
Printf("%2d ", ttl);
for (probe = 0; probe < nprobes; ++probe) {
int cc;
struct timeval tv;
struct timeval t1, t2;
struct timezone tz;
struct ip *ip;
(void) gettimeofday(&tv, &tz);
(void) gettimeofday(&t1, &tz);
send_probe(++seq, ttl);
while (cc = wait_for_reply(s, &from)) {
(void) gettimeofday(&t2, &tz);
if ((i = packet_ok(packet, cc, &from, seq))) {
int dt = deltaT(&tv);
if (from.sin_addr.s_addr != lastaddr) {
print(packet, cc, &from);
lastaddr = from.sin_addr.s_addr;
}
Printf(" %d ms", dt);
Printf(" %g ms", deltaT(&t1, &t2));
switch(i - 1) {
case ICMP_UNREACH_PORT:
#ifndef ARCHAIC
@ -539,6 +552,7 @@ main(argc, argv)
}
}
int
wait_for_reply(sock, from)
int sock;
struct sockaddr_in *from;
@ -560,7 +574,9 @@ wait_for_reply(sock, from)
}
void
send_probe(seq, ttl)
int seq, ttl;
{
struct opacket *op = outpacket;
struct ip *ip = &op->ip;
@ -568,9 +584,12 @@ send_probe(seq, ttl)
int i;
ip->ip_off = 0;
ip->ip_hl = sizeof(*ip) >> 2;
ip->ip_p = IPPROTO_UDP;
ip->ip_len = datalen;
ip->ip_ttl = ttl;
ip->ip_v = IPVERSION;
ip->ip_id = htons(ident+seq);
up->uh_sport = htons(ident);
up->uh_dport = htons(port+seq);
@ -593,14 +612,15 @@ send_probe(seq, ttl)
}
deltaT(tp)
struct timeval *tp;
double
deltaT(t1p, t2p)
struct timeval *t1p, *t2p;
{
struct timeval tv;
register double dt;
(void) gettimeofday(&tv, &tz);
tvsub(&tv, tp);
return (tv.tv_sec*1000 + (tv.tv_usec + 500)/1000);
dt = (double)(t2p->tv_sec - t1p->tv_sec) * 1000.0 +
(double)(t2p->tv_usec - t1p->tv_usec) / 1000.0;
return (dt);
}
@ -626,6 +646,7 @@ pr_type(t)
}
int
packet_ok(buf, cc, from, seq)
u_char *buf;
int cc;
@ -682,6 +703,7 @@ packet_ok(buf, cc, from, seq)
}
void
print(buf, cc, from)
u_char *buf;
int cc;
@ -709,9 +731,10 @@ print(buf, cc, from)
/*
* Checksum routine for Internet Protocol family headers (C Version)
*/
u_short
in_cksum(addr, len)
u_short *addr;
int len;
u_short *addr;
int len;
{
register int nleft = len;
register u_short *w = addr;
@ -747,8 +770,9 @@ int len;
* Subtract 2 timeval structs: out = out - in.
* Out is assumed to be >= in.
*/
void
tvsub(out, in)
register struct timeval *out, *in;
register struct timeval *out, *in;
{
if ((out->tv_usec -= in->tv_usec) < 0) {
out->tv_sec--;
@ -760,7 +784,7 @@ register struct timeval *out, *in;
/*
* Construct an Internet address representation.
* If the nflag has been supplied, give
* If the nflag has been supplied, give
* numeric value, otherwise try for symbolic name.
*/
char *
@ -802,9 +826,10 @@ inetname(in)
return (line);
}
void
usage()
{
(void)fprintf(stderr,
(void)fprintf(stderr,
"usage: traceroute [-dnrv] [-m max_ttl] [-p port#] [-q nqueries]\n\t\
[-s src_addr] [-t tos] [-w wait] host [data size]\n");
exit(1);