[net.sources] An ARPA/UUCP path server

elvy@harvard.ARPA (Marc Elvy) (08/13/84)

#! /bin/sh
echo 'Extracting ReadMe'
sed -e s/X// > ReadMe << End-Of-ReadMe
X
XHello,
X
X	There are many people now working on making a standardized version
Xof Steve Bellovin's pathalias software available for everyone on UNIX systems.
XHowever, since that might take a little more time, I am sending out a program
Xcalled "pathto" which was written here and has proved somewhat useful.  The
Xprogram polls a host which has pathalias running (default harvard.arpa) and
Xprints out paths from that host to the sites specified on the command line.
XSo, if you do not have pathalias running yet, or if you cannot find a path
Xto some site, try running "pathto <site>+" to obtain the arpanet and uucp
Xpaths to that site.  Note that, unfortunately, the current version gives you
Xa path from the HOST (i.e. harvard) rather than from your local machine, but
Xyou can always send mail through harvard if you can find no other path.  Here
Xis the current harvard uucp hop count:
X
X		#sites	hops
X		   2 
X		 261	!
X		1456	!!
X		 940	!!!
X		 547	!!!!
X		 167	!!!!!
X		  36	!!!!!!
X		   8	!!!!!!!
X		   5	!!!!!!!!
X
XThe path you are given is ordered (somewhat) by speed, but it is not guaranteed
Xto be the fastest route.  However, it SHOULD be a reasonable and correct route.
XNote that this program makes a TCP connection to Harvard, so you will have to
X(1) be able to access harvard through a TCP connection and (2) add this line to
X/etc/services:
X
Xpath		541/tcp				# path routing
X
XIf you have any questions, feel free to write to me.  I also welcome any bug
Xreports, comments, and (especially) enhancements (e.g. the ability to return
Xa path from the local site rather than from the host).
X
XMarc Elvy (elvy@harvard.{arpa,uucp})
X
XP.S.  I have included the manual page to /etc/rpath as well as to pathto,
X	since that is the program which runs on the host and does the actual
X	dirty work, and since command line options to rpath are important.
End-Of-ReadMe
echo 'Extracting pathto.c'
sed -e s/X// > pathto.c << End-Of-pathto
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <stdio.h>
X#include <netdb.h>
X
X/*
X**	\$Header: pathto.c,v 1.3 84/08/10 16:58:56 source Exp \$
X**
X**	This is the frontend TCP program for Harvard's pathalias database.
X**	It makes a connection with a host machine (default harvard.arpa)
X**	and queries that host about the paths from the HOST to other network
X**	sites around the world.  The sites should be listed on the command
X**	line, and paths to them through various networks will be returned.
X**	At present the ARPANET and the UUCP network are known about.  Others
X**	may be integrated later.  Note that, unfortunately, the path given
X**	is from the host (usually harvard), so routing will be through it.
X**
X**	Questions or comments should be posted to elvy@harvard.{uucp,arpa}.
X**	I would appreciate being warned of any bugs and fixes.    Marc Elvy
X*/
X
X
X# define	PATHHOST	"harvard"
X
X
X
Xmain (argc, argv)
Xint argc;
Xchar **argv;
X{
X    register int c, s;
X    register FILE *sfi, *sfo;
X    char *host = PATHHOST, *NAME = *argv;
X    char buffer[512], *strcat();
X    struct sockaddr_in sin;
X    struct hostent *hp;
X    struct servent *sp;
X    extern int errno;
X
X    --argc, ++argv;
X
X    /*
X    **	If the "-h" option (which is, currently, the only option) is given,
X    **	we reset the host to a machine other than PATHHOST.  This should
X    **	be done if another database machine is closer than PATHHOST.  If
X    **	another machine is ALWAYS closer, then PATHHOST should be changed.
X    */
X
X    if ((argc > 2) && (strcmp (*argv, "-h") == 0))
X    {
X	++argv, argc -= 2;
X	host = *argv++;
X    }
X    if (argc < 1)
X    {
X	fprintf (stderr, "Usage:  %s [ -h host ] site(s)\n", NAME);
X	exit (1);
X    }
X    if ((hp = gethostbyname (host)) == (struct hostent *) NULL)
X    {
X	fprintf (stderr, "%s:  Unknown host (%s).\n", NAME, host);
X	exit (1);
X    }
X    host = hp->h_name;
X    if ((s = socket (hp->h_addrtype, SOCK_STREAM, 0)) < 0)
X    {
X	perror ("pathto (socket)");
X	exit (errno);
X    }
X    sin.sin_family = hp->h_addrtype;
X    if (bind (s, (struct sockaddr *) &sin, sizeof (sin)) < 0)
X    {
X	perror ("pathto (bind)");
X	exit (errno);
X    }
X    bcopy (hp->h_addr, &sin.sin_addr, hp->h_length);
X    if ((sp = getservbyname ("path", "tcp")) == NULL)
X    {
X	fprintf (stderr, "%s:  TCP/path is an unknown service.\n", NAME);
X	exit (4);
X    }
X    sin.sin_port = sp->s_port;
X    if (connect (s, (struct sockaddr *) &sin, sizeof (sin)) < 0)
X    {
X	perror ("pathto (connect)");
X	exit (errno);
X    }
X    if (((sfi = fdopen (s, "r")) == (FILE *) NULL) ||
X	((sfo = fdopen (s, "w")) == (FILE *) NULL))
X    {
X	perror ("fdopen");
X	(void) close (s);
X	exit (errno);
X    }
X    *buffer = (char) NULL;
X    while (*argv)
X    {
X	(void) strcat (buffer, *argv++);
X	(void) strcat (buffer, " ");
X    }
X    (void) strcat (buffer, "\n");
X    (void) fputs (buffer, sfo);
X    (void) fflush(sfo);
X    while ((c = getc (sfi)) != EOF)
X	putchar (c);
X    (void) fclose(sfo);
X    (void) fclose(sfi);
X}
End-Of-pathto
echo 'Extracting pathto.l'
sed -e s/X// > pathto.l << End-Of-pathto
X.TH PATHTO l  "23 July 1984"
X.UC 4
X.SH NAME
Xpathto \- find mail path(s) to various sites
X.SH SYNOPSIS
X.B Pathto
X[
X.B \-h
X] sitenames
X.SH DESCRIPTION
XGiven a list of destination sites,
X.I pathto
Xattempts to find a mail
Xrouting path
Xfrom the
X.I host
Xsite to the destination sites.  The
X.I \-h
Xoption indicates that the next argument is the host to contact for routing
Xinformation (the default is usually harvard.arpa).  All other command line
Xarguments are considered site names, unless they are arguments to /etc/rpath.
XIf the sites are found, then a path from the host site to the argument site
Xis printed, otherwise an error message is printed.
X.PP
XSites can be given in one of the following formats:
X.TP
X.B sitename
XLook for a relevant path to sitename.  If no (/etc/rpath) command line options
Xare supplied,
X.I pathto
Xdefaults to searching all the databases it knows about.  Otherwise,
Xit searches only the requested databases.
X.TP
X.B sitename.domain
XRegardless of any command-line options, look for a path to sitename
Xonly through the network
X.I domain
X(e.g.,
X.I pathto
Xucbvax.UUCP ignores any ARPA-net path from the local site
Xto ucbvax).
X.SH FILES
X/etc/hosts			for the Internet (for hosts)
X.br
X/usr/lib/dbmAlpath.pag	for UUCP and others (for hosts)
X.SH DIAGNOSTICS
XExit status is non-zero if problems are encountered.
X.SH COMMENTS
XLocally, paths through various other networks are crammed into the
XUUCP database; CSNET site information, for instance.
X.SH BUGS
X.I Pathto
Xcurrently only understands the ARPA and UUCP domains.  It should be
Xmade to understand CSNET, BITNET, and so on.  Also, the path printed
Xshould really be from the local site to the destination, not from the
Xhost to the destination.
End-Of-pathto
echo 'Extracting rpath.l'
sed -e s/X// > rpath.l << End-Of-rpath
X.TH RPATH l  "23 July 1984"
X.UC 4
X.SH NAME
Xrpath \- find mail path(s) to various sites
X.SH SYNOPSIS
X.B /etc/rpath
X[
X.B \-a
X] [
X.B \-u
X]
X.I sitenames
X.SH DESCRIPTION
XGiven a list of destination sites,
X.I rpath
Xattempts to find a mail
Xrouting path
Xfrom the local site to the destination sites.  These are the options:
X.TP
X.B \-a
XDefault to searching only for an ARPA-net path.
X.TP
X.B \-u
XDefault to searching only for a UUCP path.
X.PP
XSites can be given in one of the following formats:
X.TP
X.B sitename
XLook for a relevant path to sitename.  If no command-line options
Xare supplied,
X.I rpath
Xdefaults to searching all the databases it knows about.  Otherwise,
Xit searches only the requested databases.
X.TP
X.B sitename.domain
XRegardless of any command-line options, look for a path to sitename
Xonly through the network
X.I domain
X(e.g.,
X.I rpath
Xucbvax.UUCP ignores any ARPA-net path from the local site
Xto ucbvax).
X.SH FILES
X/etc/hosts			for the Internet
X.br
X/usr/lib/dbmAlpath.pag	for UUCP and others
X.SH DIAGNOSTICS
XExit status is non-zero if problems are encountered.
X.SH COMMENTS
XLocally, paths through various other networks are crammed into the
XUUCP database; CSNET site information, for instance.
X.SH BUGS
X.I Rpath
Xcurrently only understands the ARPA and UUCP domains.  It should be
Xmade to understand CSNET, BITNET, and so on.
End-Of-rpath

		      Marc A. Elvy  ( elvy@harvard.{arpa,uucp} )
			     Aiken Computation Laboratory
				  Harvard University