|
|
1.1 ! root 1: #include "parms.h" ! 2: #include "structs.h" ! 3: #include "net.h" ! 4: ! 5: #ifdef RCSIDENT ! 6: static char rcsid[] = "$Header: getnet.c,v 1.7 85/01/18 15:11:46 notes Rel $"; ! 7: #endif RCSIDENT ! 8: ! 9: /* ! 10: * getnet(sys, xmit, reply) ! 11: * char *sys, **xmit, **reply) ! 12: * ! 13: * This routine will scan the net.how file, looking for alternate ! 14: * routes to the system specified. The xmit and reply pointers are ! 15: * set appropriately. ! 16: * (null if no entry found). ! 17: * The routine returns -1 if the file is not there, otherwise ! 18: * it returns the count of lines matched (0,1,2) ! 19: * ! 20: * Original Coding: Ray Essick April 1982 ! 21: */ ! 22: ! 23: static char outgoing[CMDLEN]; ! 24: static char incoming[CMDLEN]; /* hold net command */ ! 25: ! 26: getnet (sys, xmit, reply, proto) ! 27: char *sys; ! 28: char **xmit; ! 29: char **reply; ! 30: int *proto; ! 31: { ! 32: ! 33: FILE * nethow; ! 34: char pathname[256]; /* probably ok */ ! 35: char oneline[512]; ! 36: char *p; ! 37: int i, ! 38: count; ! 39: char *tsys; /* room for slop */ ! 40: char *tdirect; ! 41: char *thow; ! 42: int tproto; ! 43: ! 44: count = 0; /* lines we have */ ! 45: if (xmit != (char **) NULL) ! 46: *xmit = NULL; ! 47: if (reply != (char **) NULL) ! 48: *reply = NULL; ! 49: if (proto != (int *) NULL) ! 50: *proto = 0; /* default protocol */ ! 51: sprintf (pathname, "%s/%s/%s", Mstdir, UTILITY, NETHOW); ! 52: ! 53: if ((nethow = fopen (pathname, "r")) == NULL) ! 54: return (-1); ! 55: ! 56: while (fgets (oneline, sizeof oneline, nethow) != NULL && count < 2) ! 57: { ! 58: i = strlen (oneline); /* get end */ ! 59: if (oneline[i - 1] == '\n') /* not entire line */ ! 60: { ! 61: oneline[i - 1] = '\0'; /* strip newline */ ! 62: } ! 63: else ! 64: { ! 65: fprintf (stderr, "%s: net.how line longer than %d characters", ! 66: Invokedas, pathname, sizeof oneline); ! 67: return (-2); /* line too long */ ! 68: } ! 69: if (oneline[0] == '#' || oneline[0] == '\0') ! 70: continue; /* comment or empty */ ! 71: ! 72: /* ! 73: * pick the system name ! 74: */ ! 75: tsys = p = oneline; /* pick fields */ ! 76: while (*p != ':' && *p) ! 77: p++; /* skip to colon */ ! 78: if (*p != ':') ! 79: continue; /* bad line */ ! 80: *p++ = '\0'; /* terminate */ ! 81: /* ! 82: * and the direction field ! 83: */ ! 84: tdirect = p; /* direction */ ! 85: while (*p != ':' && *p) ! 86: p++; /* skip rest of field */ ! 87: if (*p == '\0') ! 88: continue; /* bad line */ ! 89: *p++ = '\0'; /* terminate */ ! 90: /* ! 91: * now the protocol (possibly empty) ! 92: */ ! 93: if (sscanf (p, "%d", &tproto) != 1) /* get protocol */ ! 94: tproto = 0; /* default */ ! 95: while (*p != ':' && *p) ! 96: p++; /* skip rest */ ! 97: p++; /* skip */ ! 98: /* ! 99: * skip the empty 4th field to get to the "how to" field ! 100: */ ! 101: while (*p != ':' && *p) ! 102: p++; /* skip rest of field */ ! 103: p++; /* pointing at "how" */ ! 104: thow = p; /* assign */ ! 105: ! 106: /* ! 107: * now, let's see if it's the one we want. ! 108: */ ! 109: ! 110: if (strcmp (tsys, sys)) /* match? */ ! 111: continue; /* no */ ! 112: ! 113: ! 114: if (*tdirect == 'x') /* transmit */ ! 115: { ! 116: if (xmit != (char **) NULL) /* want it? */ ! 117: { ! 118: strcpy (outgoing, thow); /* copy */ ! 119: *xmit = outgoing; /* and point */ ! 120: } ! 121: if (proto != (int *) NULL) /* want it? */ ! 122: *proto = tproto; /* give it to him */ ! 123: } ! 124: else ! 125: { /* force reply */ ! 126: if (reply != (char **) NULL) ! 127: { ! 128: strcpy (incoming, thow); /* copy */ ! 129: *reply = incoming; /* and point */ ! 130: } ! 131: } ! 132: count++; /* bump the count */ ! 133: } ! 134: fclose (nethow); ! 135: return count; ! 136: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.