- errno = 0;
- for (cp = name, n = 0; *cp; cp++)
- if (*cp == '.')
- n++;
- if (n == 0 && (cp = hostalias(name)))
- return (gethostdomain(cp, (char *)NULL));
- if ((n == 0 || *--cp != '.') && (_res.options & RES_DEFNAMES))
- for (domain = _res.dnsrch; *domain; domain++) {
- hp = gethostdomain(name, *domain);
- if (hp)
- return (hp);
- /*
- * If no server present, use host table.
- * If host isn't found in this domain,
- * keep trying higher domains in the search list
- * (if that's enabled).
- * On a NO_ADDRESS error, keep trying, otherwise
- * a wildcard MX entry could keep us from finding
- * host entries higher in the domain.
- * If we get some other error (non-authoritative negative
- * answer or server failure), then stop searching up,
- * but try the input name below in case it's fully-qualified.
- */
- if (errno == ECONNREFUSED)
- return (_gethtbyname(name));
- if ((h_errno != HOST_NOT_FOUND && h_errno != NO_ADDRESS) ||
- (_res.options & RES_DNSRCH) == 0)
- break;
- h_errno = 0;
- }
- /*
- * If the search/default failed, try the name as fully-qualified,
- * but only if it contained at least one dot (even trailing).
- */
- if (n)
- return (gethostdomain(name, (char *)NULL));
- return ((struct hostent *) NULL);
-}
-
-static struct hostent *
-gethostdomain(name, domain)
- char *name, *domain;
-{
- querybuf buf;
- char nbuf[2*MAXDNAME+2];
- char *longname = nbuf;
- int n;