3 * hosts.c -- find out the official name of a host
9 * In the SendMail world, we really don't know what the valid
10 * hosts are. We could poke around in the sendmail.cf file, but
11 * that still isn't a guarantee. As a result, we'll say that
12 * everything is a valid host, and let SendMail worry about it.
16 #include <zotnet/mts/mts.h>
29 static int init_hs(void);
33 OfficialName (char *name)
35 char *p, *q, site[BUFSIZ];
38 static char buffer[BUFSIZ];
42 for (p = name, q = site; *p && (q - site < sizeof(site) - 1); p++, q++)
43 *q = isupper (*p) ? tolower (*p) : *p;
47 if (!strcasecmp (LocalName(), site))
54 if ((hp = gethostbyname (q))) {
55 strncpy (buffer, hp->h_name, sizeof(buffer));
58 if (hosts.h_name || init_hs ()) {
59 for (h = hosts.h_next; h; h = h->h_next)
60 if (!strcasecmp (h->h_name, q))
63 for (r = h->h_aliases; *r; r++)
64 if (!strcasecmp (*r, q))
68 strncpy (buffer, site, sizeof(buffer));
73 * Use hostable as an exception file for those hosts that aren't
74 * on the Internet (listed in /etc/hosts). These are usually
75 * PhoneNet and UUCP sites.
83 char *cp, *dp, **q, **r;
84 char buffer[BUFSIZ], *aliases[NALIASES];
85 register struct host *h;
88 if ((fp = fopen (hostable, "r")) == NULL)
92 while (fgets (buffer, sizeof(buffer), fp) != NULL) {
93 if ((cp = strchr(buffer, '#')))
95 if ((cp = strchr(buffer, '\n')))
97 for (cp = buffer; *cp; cp++)
100 for (cp = buffer; isspace (*cp); cp++)
106 if ((cp = strchr(dp = cp, ' '))) {
108 for (cp++; *cp; cp++) {
109 while (isspace (*cp))
113 if ((cp = strchr(*q++ = cp, ' ')))
117 if (q >= aliases + NALIASES)
124 h->h_next = (struct host *) calloc (1, sizeof(*h));
126 h->h_name = getcpy (dp);
128 (char **) calloc ((size_t) (q - aliases + 1), sizeof(*q));
129 for (q = aliases; *q; q++)