6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
12 static char *rcsid_fixhost_c = "$Header$";
15 #include <mit-copyright.h>
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/nameser.h>
20 #include <arpa/resolv.h>
26 extern char *malloc();
27 extern char *realloc();
28 extern char *strsave();
31 * Canonicalize hostname; if it is in the namespace, call the
32 * nameserver to expand it; otherwise uppercase it and append the
33 * default domain (using an, er, undocumented global of the
36 * Assumes that host was allocated using malloc(); it may be freed or
37 * realloc'ed, so the old pointer should not be considered valid.
41 canonicalize_hostname(host)
44 register struct hostent *hp;
50 if (index(host, '*') || index(host, '?'))
53 hp = gethostbyname(host);
56 n_len = strlen(hp->h_name) + 1;
57 host = realloc(host, (unsigned)n_len);
59 (void) strcpy(host, hp->h_name);
62 /* can't get name from nameserver; fix up the format a bit */
63 for (cp = host; *cp; cp++) {
64 register int c; /* pcc doesn't like register char */
65 if (islower(c = *cp)) *cp = toupper(c);
66 has_dot |= (c == '.');
69 (void) sprintf(tbuf, "%s.%s", host, _res.defdname);