6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.2 1988-08-02 21:12:18 mar
10 * don't change hostname if it contains wildcards
12 * Revision 1.1 87/09/03 03:12:45 wesommer
18 static char *rcsid_fixhost_c = "$Header$";
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/nameser.h>
25 #include <arpa/resolv.h>
31 extern char *malloc();
32 extern char *realloc();
33 extern char *strsave();
36 * Canonicalize hostname; if it is in the namespace, call the
37 * nameserver to expand it; otherwise uppercase it and append the
38 * default domain (using an, er, undocumented global of the
41 * Assumes that host was allocated using malloc(); it may be freed or
42 * realloc'ed, so the old pointer should not be considered valid.
46 canonicalize_hostname(host)
49 register struct hostent *hp;
55 if (index(host, '*') || index(host, '?'))
58 hp = gethostbyname(host);
61 n_len = strlen(hp->h_name) + 1;
62 host = realloc(host, (unsigned)n_len);
64 (void) strcpy(host, hp->h_name);
67 /* can't get name from nameserver; fix up the format a bit */
68 for (cp = host; *cp; cp++) {
69 register int c; /* pcc doesn't like register char */
70 if (islower(c = *cp)) *cp = toupper(c);
71 has_dot |= (c == '.');
74 (void) sprintf(tbuf, "%s.%s", host, _res.defdname);