6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.1 1987-09-03 03:12:45 wesommer
15 static char *rcsid_fixhost_c = "$Header$";
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/nameser.h>
22 #include <arpa/resolv.h>
28 extern char *malloc();
29 extern char *realloc();
30 extern char *strsave();
33 * Canonicalize hostname; if it is in the namespace, call the
34 * nameserver to expand it; otherwise uppercase it and append the
35 * default domain (using an, er, undocumented global of the
38 * Assumes that host was allocated using malloc(); it may be freed or
39 * realloc'ed, so the old pointer should not be considered valid.
43 canonicalize_hostname(host)
46 register struct hostent *hp;
52 hp = gethostbyname(host);
55 n_len = strlen(hp->h_name) + 1;
56 host = realloc(host, (unsigned)n_len);
58 (void) strcpy(host, hp->h_name);
61 /* can't get name from nameserver; fix up the format a bit */
62 for (cp = host; *cp; cp++) {
63 register int c; /* pcc doesn't like register char */
64 if (islower(c = *cp)) *cp = toupper(c);
65 has_dot |= (c == '.');
68 (void) sprintf(tbuf, "%s.%s", host, _res.defdname);