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)
39 char *p, *q, site[BUFSIZ];
42 static char buffer[BUFSIZ];
46 for (p = name, q = site; *p && (q - site < sizeof(site) - 1); p++, q++)
47 *q = isupper (*p) ? tolower (*p) : *p;
51 if (!strcasecmp (LocalName(), site))
54 #ifdef HAVE_SETHOSTENT
58 if ((hp = gethostbyname (q))) {
59 strncpy (buffer, hp->h_name, sizeof(buffer));
62 if (hosts.h_name || init_hs ()) {
63 for (h = hosts.h_next; h; h = h->h_next)
64 if (!strcasecmp (h->h_name, q)) {
67 for (r = h->h_aliases; *r; r++)
68 if (!strcasecmp (*r, q))
73 strncpy (buffer, site, sizeof(buffer));
78 * Use hostable as an exception file for those hosts that aren't
79 * on the Internet (listed in /etc/hosts). These are usually
80 * PhoneNet and UUCP sites.
88 char *cp, *dp, **q, **r;
89 char buffer[BUFSIZ], *aliases[NALIASES];
90 register struct host *h;
93 if ((fp = fopen (hostable, "r")) == NULL)
97 while (fgets (buffer, sizeof(buffer), fp) != NULL) {
98 if ((cp = strchr(buffer, '#')))
100 if ((cp = strchr(buffer, '\n')))
102 for (cp = buffer; *cp; cp++)
105 for (cp = buffer; isspace (*cp); cp++)
111 if ((cp = strchr(dp = cp, ' '))) {
113 for (cp++; *cp; cp++) {
114 while (isspace (*cp))
118 if ((cp = strchr(*q++ = cp, ' ')))
122 if (q >= aliases + NALIASES)
129 h->h_next = (struct host *) calloc (1, sizeof(*h));
131 h->h_name = getcpy (dp);
133 (char **) calloc ((size_t) (q - aliases + 1), sizeof(*q));
134 for (q = aliases; *q; q++)