- if (!(_res.options & RES_INIT) && res_init() == -1)
- return (NULL);
- if (isdigit(name[0])) {
- h_errno = HOST_NOT_FOUND;
- return (NULL);
-
- }
- 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));
-}
-
-static struct hostent *
-gethostdomain(name, domain)
- char *name, *domain;
-{
- querybuf buf;
- char nbuf[2*MAXDNAME+2];
- int n;
+ /*
+ * disallow names consisting only of digits/dots, unless
+ * they end in a dot.
+ */
+ if (isdigit(name[0]))
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-numeric, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup. What if someone types
+ * 255.255.255.255? The test below will
+ * succeed spuriously... ???
+ */
+ if ((host_addr.s_addr = inet_addr(name)) == -1) {
+ h_errno = HOST_NOT_FOUND;
+ return((struct hostent *) NULL);
+ }
+ host.h_name = name;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ host.h_addrtype = AF_INET;
+ host.h_length = sizeof(u_long);
+ h_addr_ptrs[0] = (char *)&host_addr;
+ h_addr_ptrs[1] = (char *)0;
+#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
+ host.h_addr_list = h_addr_ptrs;
+#else
+ host.h_addr = h_addr_ptrs[0];
+#endif
+ return (&host);
+ }
+ if (!isdigit(*cp) && *cp != '.')
+ break;
+ }