Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!uflorida!novavax!twwells!bill From: bill@twwells.com (T. William Wells) Newsgroups: comp.mail.uucp Subject: Re: pathalias ignores fast Internet connections Keywords: if else do Message-ID: <1989Jun20.112411.4177@twwells.com> Date: 20 Jun 89 11:24:11 GMT References: <1207@altos86.UUCP> <3288@epimass.EPI.COM> <742@crdgw1.crd.ge.com> <3307@epimass.EPI.COM> <11938@s.ms.uky.edu> Organization: None, Ft. Lauderdale, FL Lines: 185 In article <11938@s.ms.uky.edu> david@ms.uky.edu (David Herron -- One of the vertebrae) writes: : I'm not proposing that someone teach pathalias about domains. This could : be handled by a script of some sort, like : : run pathalias in the mode which generates costs as well as routes : save the output in "paths1" : look through paths1 doing : if it doesn't have a ".", continue : /* we know it's some domain name */ : look through the list of already known gateways and : if we find one whose name is a "superset" of : this one, then delete this route from paths1 : (superset means ".edu" is-superset-of ".podunk.edu") I run the following program on my system as a postprocessor on sorted pathalias output. If you have b.a and .a in the pathalias output, b.a goes away. Due to the particular connectivity for my site, I do not need to consider the cost of b.a vs. .a, but for a general system, one should. The program isn't wonderfully efficient, but the time it takes is negligible nonetheless. This program is freshly written and has not been cleaned up other than to remove lint. There are, as you can see, no comments. Caveat Usor! ------------------------------cut here---------------------------------------- #include #include /* Copyright 1989 by T. William Wells, bill@twwells.com. All Rights Reserved. You can do anything you want with this code, except alter or remove the copyright notice. */ extern char *malloc(); extern void free(); typedef struct GATE { struct GATE *g_next; char *g_site; char *g_path; } GATE; char Buffer[1024]; char *Path; int Sitelen; GATE *Gatelist; void addgate(); void printgate(); int main() { while (gets(Buffer)) { Path = strchr(Buffer, '\t'); Sitelen = Path - Buffer; *Path++ = 0; if (!hasgate()) { if (Buffer[0] != '.') { break; } addgate(); } } printgate(); if (feof(stdin)) { exit(0); } puts(Buffer); while (gets(Buffer)) { Path = strchr(Buffer, '\t'); Sitelen = Path - Buffer; *Path++ = 0; if (!hasgate()) { printf("%s\t%s\n", Buffer, Path); } } exit(0); /*NOTREACHED*/ } char * myalloc(size) int size; { char *ptr; if (!(ptr = malloc((unsigned)size))) { fprintf(stderr, "Out of memory.\n"); exit(1); } return (ptr); } char * stralloc(str) char *str; { char *ptr; ptr = myalloc(strlen(str) + 1); strcpy(ptr, str); return (ptr); } int hasgate() { register GATE *gp; register char *ptr; ptr = Buffer + Sitelen; while (1) { while (ptr > Buffer && *--ptr != '.') ; if (ptr == Buffer) { return (0); } for (gp = Gatelist; gp; gp = gp->g_next) { if (strcmp(ptr, gp->g_site) == 0) { return (1); } } } } void addgate() { register GATE *gp; register GATE *gp1; int n; gp1 = 0; for (gp = Gatelist; gp; ) { n = strlen(gp->g_site); if (n < Sitelen || strcmp(gp->g_site + n - Sitelen, Buffer) != 0) { gp1 = gp; gp = gp->g_next; continue; } if (gp1) { gp1->g_next = gp->g_next; } else { Gatelist = gp->g_next; } free(gp->g_site); free(gp->g_path); free((char *)gp); if (gp1) { gp = gp1->g_next; } else { gp = Gatelist; } } gp = (GATE *)myalloc(sizeof(GATE)); if (gp1) { gp1->g_next = gp; } else { Gatelist = gp; } gp->g_next = 0; gp->g_site = stralloc(Buffer); gp->g_path = stralloc(Path); } void printgate() { GATE *gp; for (gp = Gatelist; gp; gp = gp->g_next) { printf("%s\t%s\n", gp->g_site, gp->g_path); } } ------------------------------cut here---------------------------------------- Bill { uunet | novavax | ankh | sunvice } !twwells!bill bill@twwells.com