Debande%smd.ucl.ac.be@cunyvm.cuny.edu (Benoit Debande) (03/14/91)
Hello, In a previous UNIX-DIGEST, rob@sswax1.dnet.loral.com made a (long) mail about using DNS and /etc/hosts with SUNOS 4.1 I followed his 2nd solution (based upond the sources of BIND) and applied his modification to allow host lookup first by DNS and then on /etc/hosts. This is the first patch enclosed : it replaces resolver.patch/gethostnamadr.c.patch included in the file "bidon41.shar" But, I'm not fully satisfied with the order of looking, and I prefer looking first in /etc/hosts and then by DNS. ie: that allows me to use local aliases for hosts. So, I made another modification to the sources, and it is the second patch enclosed. It also replace the original one from the file "bidon41.shar". I hope it will help .... =============================================================================== Dr. Benoit DEBANDE E-MAIL : debande@smd.ucl.ac.be School of Medicine debande@buclln11.bitnet Catholic University of Louvain FAX : 32-2-7645322 Av. Hippocrate 50 (50.20) PHONE : 32-2-7645268 B-1200 BRUXELLES (BELGIUM) =============================================================================== Theory : it doesn't work an you know why Practice : it works an you don't know why C programming : it doesn't work and you don't know why =============================================================================== FISRT ENCLOSURE : rob's modification patch *** gethostnamadr.c.orig Thu Jan 4 19:25:13 1990 --- gethostnamadr.c Wed Mar 13 18:57:33 1991 *************** *** 40,49 **** static char hostbuf[BUFSIZ+1]; static struct in_addr host_addr; static char HOSTDB[] = "/etc/hosts"; ! static FILE *hostf = NULL; static char hostaddr[MAXADDRS]; static char *host_addrs[2]; ! static int stayopen = 0; char *strpbrk(); #if PACKETSZ > 1024 --- 40,49 ---- static char hostbuf[BUFSIZ+1]; static struct in_addr host_addr; static char HOSTDB[] = "/etc/hosts"; ! static FILE *hostf; static char hostaddr[MAXADDRS]; static char *host_addrs[2]; ! static int stayopen; char *strpbrk(); #if PACKETSZ > 1024 *************** *** 261,270 **** if (_res.options & RES_DEBUG) printf("res_search failed\n"); #endif - if (errno == ECONNREFUSED) return (_gethtbyname(name)); - else - return ((struct hostent *) NULL); } return (getanswer(&buf, n, 0)); } --- 261,267 ---- *************** *** 293,301 **** if (_res.options & RES_DEBUG) printf("res_query failed\n"); #endif - if (errno == ECONNREFUSED) return (_gethtbyaddr(addr, len, type)); - return ((struct hostent *) NULL); } hp = getanswer(&buf, n, 1); if (hp == NULL) --- 290,296 ---- SECOND ENCLOSURE my modification patch *** gethostnamadr.c.orig Thu Jan 4 19:25:13 1990 --- gethostnamadr.c Wed Mar 13 18:47:49 1991 *************** *** 40,49 **** static char hostbuf[BUFSIZ+1]; static struct in_addr host_addr; static char HOSTDB[] = "/etc/hosts"; ! static FILE *hostf = NULL; static char hostaddr[MAXADDRS]; static char *host_addrs[2]; ! static int stayopen = 0; char *strpbrk(); #if PACKETSZ > 1024 --- 40,49 ---- static char hostbuf[BUFSIZ+1]; static struct in_addr host_addr; static char HOSTDB[] = "/etc/hosts"; ! static FILE *hostf; static char hostaddr[MAXADDRS]; static char *host_addrs[2]; ! static int stayopen; char *strpbrk(); #if PACKETSZ > 1024 *************** *** 217,222 **** --- 217,223 ---- register char *cp; int n; extern struct hostent *_gethtbyname(); + struct hostent *hp; /* * disallow names consisting only of digits/dots, unless *************** *** 254,272 **** } if (!isdigit(*cp) && *cp != '.') break; ! } ! if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) { #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search failed\n"); #endif ! if (errno == ECONNREFUSED) ! return (_gethtbyname(name)); ! else ! return ((struct hostent *) NULL); ! } ! return (getanswer(&buf, n, 0)); } struct hostent * --- 255,275 ---- } if (!isdigit(*cp) && *cp != '.') break; ! } ! if (( hp = _gethtbyname(name)) != NULL) ! return(hp); ! ! if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search failed\n"); #endif ! return ((struct hostent *) NULL); ! ! else ! ! return (getanswer(&buf, n, 0)); } struct hostent * *************** *** 287,292 **** --- 290,297 ---- ((unsigned)addr[2] & 0xff), ((unsigned)addr[1] & 0xff), ((unsigned)addr[0] & 0xff)); + if ((hp =_gethtbyaddr(addr, len, type)) != NULL) + return(hp); n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof(buf)); if (n < 0) { #ifdef DEBUG *************** *** 293,301 **** if (_res.options & RES_DEBUG) printf("res_query failed\n"); #endif ! if (errno == ECONNREFUSED) ! return (_gethtbyaddr(addr, len, type)); ! return ((struct hostent *) NULL); } hp = getanswer(&buf, n, 1); if (hp == NULL) --- 298,304 ---- if (_res.options & RES_DEBUG) printf("res_query failed\n"); #endif ! return ((struct hostent *) NULL); } hp = getanswer(&buf, n, 1); if (hp == NULL) --