+ char qbuf[MAXDNAME];
+ extern struct hostent *_gethtbyaddr();
+
+ if (type != AF_INET)
+ return ((struct hostent *) NULL);
+ (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+ ((unsigned)addr[3] & 0xff),
+ ((unsigned)addr[2] & 0xff),
+ ((unsigned)addr[1] & 0xff),
+ ((unsigned)addr[0] & 0xff));
+ n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof(buf));
+ if (n < 0) {
+#ifdef DEBUG
+ 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)
+ return ((struct hostent *) NULL);
+ hp->h_addrtype = type;
+ hp->h_length = len;
+ h_addr_ptrs[0] = (char *)&host_addr;
+ h_addr_ptrs[1] = (char *)0;
+ host_addr = *(struct in_addr *)addr;
+#if BSD < 43 && !defined(h_addr) /* new-style hostent structure */
+ hp->h_addr = h_addr_ptrs[0];
+#endif
+ return(hp);
+}
+
+void
+_sethtent(f)
+ int f;
+{
+ if (hostf == NULL)
+ hostf = fopen(_PATH_HOSTS, "r" );
+ else
+ rewind(hostf);
+ stayopen |= f;
+}
+
+void
+_endhtent()
+{
+ if (hostf && !stayopen) {
+ (void) fclose(hostf);
+ hostf = NULL;
+ }
+}
+
+struct hostent *
+_gethtent()
+{
+ char *p;
+ register char *cp, **q;
+
+ if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL)
+ return (NULL);
+again:
+ if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ /* THIS STUFF IS INTERNET SPECIFIC */
+#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
+ host.h_addr_list = host_addrs;
+#endif
+ host.h_addr = hostaddr;
+ *((u_int32_t *)host.h_addr) = inet_addr(p);
+ host.h_length = sizeof (u_int32_t);
+ host.h_addrtype = AF_INET;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ host.h_name = cp;
+ q = host.h_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;