|
|
1.1 ! root 1: #include <sys/inet/in.h> ! 2: #include <stdio.h> ! 3: #include <ctype.h> ! 4: #include "config.h" ! 5: ! 6: static char *files[] = { ! 7: HOSTS, ! 8: NETWORKS, ! 9: }; ! 10: #define NFILES (sizeof(files) / sizeof(files[0])) ! 11: ! 12: extern char *in_getw(); ! 13: ! 14: /* translate a host name into an address */ ! 15: in_addr ! 16: in_address(host) ! 17: char *host; ! 18: { ! 19: FILE *fp; ! 20: char buf[512], b[512], *p; ! 21: int addr, i; ! 22: ! 23: if(isdigit(host[0])) ! 24: return(in_aton(host)); ! 25: for(i = 0; i < NFILES; i++){ ! 26: if((fp = fopen(files[i], "r")) == 0){ ! 27: perror(files[i]); ! 28: continue; ! 29: } ! 30: while(fgets(buf, sizeof(buf), fp)){ ! 31: if(buf[0] == '\n' || buf[0] == '#') ! 32: continue; ! 33: if((p = in_getw(buf, b)) == 0) ! 34: continue; ! 35: addr = in_aton(b); ! 36: while(p = in_getw(p, b)){ ! 37: if(strcmp(b, host) == 0){ ! 38: fclose(fp); ! 39: return(addr); ! 40: } ! 41: } ! 42: } ! 43: fclose(fp); ! 44: } ! 45: return(0); ! 46: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.