- n = res_mkquery(QUERY, name, C_ANY, T_A, (char *)NULL, 0, NULL,
- (char *)&buf, sizeof(buf));
- if (n < 0) {
+ /*
+ * 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;
+ }
+
+ if ((n = res_search(name, C_IN, T_A, buf.buf, sizeof(buf))) < 0) {