3 * hosts.c -- find out the official name of a host
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 * In the SendMail world, we really don't know what the valid
14 * hosts are. We could poke around in the sendmail.cf file, but
15 * that still isn't a guarantee. As a result, we'll say that
16 * everything is a valid host, and let SendMail worry about it.
33 static int init_hs(void);
37 OfficialName (char *name)
40 char *q, site[BUFSIZ];
43 static char buffer[BUFSIZ];
47 for (p = name, q = site; *p && (q - site < sizeof(site) - 1); p++, q++)
48 *q = isupper (*p) ? tolower (*p) : *p;
52 if (!mh_strcasecmp (LocalName(), site))
55 #ifdef HAVE_SETHOSTENT
59 if ((hp = gethostbyname (q))) {
60 strncpy (buffer, hp->h_name, sizeof(buffer));
63 if (hosts.h_name || init_hs ()) {
64 for (h = hosts.h_next; h; h = h->h_next)
65 if (!mh_strcasecmp (h->h_name, q)) {
68 for (r = h->h_aliases; *r; r++)
69 if (!mh_strcasecmp (*r, q))
74 strncpy (buffer, site, sizeof(buffer));
79 * Use hostable as an exception file for those hosts that aren't
80 * on the Internet (listed in /etc/hosts). These are usually
81 * PhoneNet and UUCP sites.
91 char buffer[BUFSIZ], *aliases[NALIASES];
92 register struct host *h;
95 if ((fp = fopen (hostable, "r")) == NULL)
99 while (fgets (buffer, sizeof(buffer), fp) != NULL) {
100 if ((cp = strchr(buffer, '#')))
102 if ((cp = strchr(buffer, '\n')))
104 for (cp = buffer; *cp; cp++)
107 for (cp = buffer; isspace (*cp); cp++)
113 if ((cp = strchr(dp = cp, ' '))) {
115 for (cp++; *cp; cp++) {
116 while (isspace (*cp))
120 if ((cp = strchr(*q++ = cp, ' ')))
124 if (q >= aliases + NALIASES)
131 h->h_next = (struct host *) calloc (1, sizeof(*h));
133 h->h_name = getcpy (dp);
135 (char **) calloc ((size_t) (q - aliases + 1), sizeof(*q));
136 for (q = aliases; *q; q++)