From: utzoo!decvax!harpo!duke!ucf-cs!tim Newsgroups: net.sources Title: nmail.c C source pgm for Network Mail Router Article-I.D.: ucf-cs.618 Posted: Fri Jun 18 06:08:59 1982 Received: Tue Jun 29 20:06:18 1982 /* * * TITLE : nmail * * PURPOSE : To pre-process network addresses finding the shortest * path through the network * * PROGRAMMER : Timothy W. Curry at University of Central Florida * * DATE : April 7, 1982 * * ENTRY PTS. : main * * PARAMETERS : addresses of the form: name or site!name or name@arpa_site * */ /* include the headers to work with standard I/O; isdigit; nmailer defines */ #include#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 */ strcpy(paths,"mail "); ppos = 5; for (i=1; i