From: utzoo!decvax!duke!ucf-cs!tim Newsgroups: net.sources Title: Network Routing in one script Article-I.D.: ucf-cs.628 Posted: Mon Jun 21 04:42:35 1982 Received: Thu Jun 24 01:56:37 1982 : This shell script will setup nmail a Network Automatic Routing program echo Creating a directory nmail.srcs mkdir nmail.srcs echo Creating Readme file. cat >nmail.srcs/Readme <From my site typing nmail cbosgd!mark dave unc.smb@udel-relay will execute mail with the paths duke!chico!harpo!cbosg!cbosgd!mark dave duke!decvax!ucbvax!unc.smb@udel-relay Note: the first was a USENET path, the second was a local user, the third was an ARPANET (CSNET) address. This pro- gram is definitely inferior to the routing program just sub- mitted to the net by unc!smb but the advantages of this pro- gram are that it should install in under 5 minutes with no changes to existing system software. Also the total size of everything is under 500 lines of commented code verses the over 2500 lines of smb's. I would recommend installing smb's version but this will give you a quick and easy sub- stitute in the mean time. The path generated is definitely shortest but not necessarily the least cost since no calcu- lation of baud rates or polling frequencies is made. Tim Curry USENET: duke!ucf-cs!tim ARPANET: ucf-cs.tim@udel-relay E*O*F echo Creating makenet file cat >nmail.srcs/makenet <\$1 rm -f /tmp/site1 /tmp/site2 echo The network topology file is installed. E*O*F echo Creating nmail.c file cat >nmail.srcs/nmail.c < #include #include "nmail.h" main(argc,argv) int argc; char *argv[]; { /* * Variable Usage: * net - the input file descriptor name for the network topology file * site_name - a storage buffer to hold the name of a site * plen,psrc,pdest - pointer variables used to build the list of site * names. plen holds the length of the site name; psrc holds * the current character position in the source buffer; pdest * in the destination buffer * dest - holds the name of the site we are trying to reach * addr - holds both the name of the destination site and name of the * user to receive the message * i,k,j,l,m,n - integer counters * ppos - keeps track of the current character position in paths * ptr - index into the list of site links * used - an array to hold the sites already visited while finding * the shortest path * pstk - the stack onto which the breadth first search places values */ FILE *net,*fopen(); char site_name[SITENAMELEN]; char *plen,*psrc,*pdest; char paths[256],dest[14],addr[30]; int i,j,k,l,m,n,ppos; short int *ptr,used[MAXSITES],pstk[MAXSITES][2]; if (argc == 1) { fprintf(stderr,"nmail: no addresses given.\n"); nmailusage(); } if ((net = fopen(NETFILE,"r")) == NULL) { fprintf(stderr,"nmail: can't open network configuration file.\n"); exit(1); } /* the SITES buffer will consist of a byte with the length of the site name in it followed by the site name */ *SITES = '\0'; pdest = SITES; for (NUMSITES=1; ; NUMSITES++) { if ((pdest-SITES+SITENAMELEN) > SITEBUFSZ) { fprintf(stderr,"SITES buffer overflowed\n"); exit(1); } fscanf(net,"%s",site_name); if (isdigit(*site_name)) break; for (plen=pdest,psrc=site_name; *++pdest = *psrc++; (*plen)++); } /* LINKS will be an array of numbers indicating which sites are connected to which. LINDEX is used to index into the LINKS array. */ LINKS[1] = (short int) atoi(site_name); LINDEX[1] = &LINKS[1]; for (i=2,j=1; i<=NUMSITES+1 ; i++) { while (LINKS[j] != 0) { fscanf(net,"%d",&k); j++; LINKS[j] = (short int) k; } LINDEX[i] = &LINKS[j]; j--; } /* the last number was the value for the local site */ Local = LINKS[j]; /* initialize the buffer to mail */ paths[0] = '\0'; ppos = 0; for (i=1; inmail.srcs/nmail.h <20 links. Most have 1. Want to * keep the memory size declarations down so this * is an average. * SITEBUFSZ - The size of the buffer to hold the site names. * * NETFILE - Where the topology description is kept. * * LOCAL - The name of the originating (local) site. * * ARPA - The name of the site that will gateway mail to the ARPANET * */ #define SITENAMELEN 15 #define MAXSITES 500 #define AVGLINKS 4 #define SITEBUFSZ SITENAMELEN*MAXSITES #define NETFILE "/usr1/vlsi/tim/net/network" #define LOCAL ucf-cs #define ARPA "ucbvax!" short int NUMSITES,LINKS[MAXSITES*AVGLINKS],*LINDEX[MAXSITES],Local; char SITES[SITEBUFSZ]; E*O*F echo Creating runme file cat >nmail.srcs/runme </tmp/nmail.h mv /tmp/nmail.h nmail.h echo Header file changed reflecting sitename = \$sitename and echo the topology file = \$filename echo Creating the topology file. chmod +x ./makenet ./makenet \$filename cc -O -o nmail nmail.c echo The program can be found in the file "nmail". E*O*F echo Creating sites file cat >nmail.srcs/sites <