- errno = 0;
- for (cp = name, n = 0; *cp; cp++)
- if (*cp == '.')
- n++;
- if ((n && *--cp == '.') || (_res.options & RES_DEFNAMES) == 0) {
- int defflag = _res.options & RES_DEFNAMES;
-
- _res.options &= ~RES_DEFNAMES; /* XXX */
- if (n && *cp == '.')
- *cp = '\0';
- hp = gethostdomain(name, (char *)NULL);
- if (n && *cp == '\0')
- *cp = '.';
- if (defflag)
- _res.options |= RES_DEFNAMES;
- return (hp);
- }
- if (n == 0 && (cp = hostalias(name)))
- return (gethostdomain(cp, (char *)NULL));
- 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,
- * or a wildcard MX entry could keep us from finding
- * host entries higher in the domain.
- */
- if (errno == ECONNREFUSED)
- return (_gethtbyname(name));
- if ((h_errno != HOST_NOT_FOUND &&
- h_errno != NO_ADDRESS) ||
- (_res.options & RES_DNSRCH) == 0)
- return (NULL);
- h_errno = 0;
- }
- return (gethostdomain(name, (char *)NULL));
-}